From d3c1bf0155a4745f04a09664c426d183841abee8 Mon Sep 17 00:00:00 2001 From: Andrew Dinh Date: Mon, 31 Dec 2018 16:37:51 -0800 Subject: [PATCH] Started Expense Ratio --- ExpenseRatio.py | 20 ++++++++++++++++++ StockData.py | 8 +++++--- main.py | 53 ++++++++++++++++++++++++++++++++++++------------ requirements.txt | 3 ++- 4 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 ExpenseRatio.py diff --git a/ExpenseRatio.py b/ExpenseRatio.py new file mode 100644 index 0000000..7dcd0e0 --- /dev/null +++ b/ExpenseRatio.py @@ -0,0 +1,20 @@ +# ExpenseRatio.py +# Andrew Dinh +# Python 3.6.1 +# Description: +''' +Asks user for expense ratio of stock (I don't think there's an API for expense ratios) +Runs corrrelation study (I'm not sure if I want another class for this or not) +''' + +import numpy + +def main(): # For testing purposes + a = [1,4,6] + b = [1,2,3] + c = numpy.corrcoef(a, b)[0, 1] + print(c) + + +if __name__ == "__main__": + main() diff --git a/StockData.py b/StockData.py index a562b00..0d6cff7 100644 --- a/StockData.py +++ b/StockData.py @@ -60,6 +60,9 @@ class Stock: def setName(self, newName): self.name = newName + def getAllLists(self): + return self.allLists + def getIEX(self): url = ''.join(('https://api.iextrading.com/1.0/stock/', self.name, '/chart/5y')) #link = "https://api.iextrading.com/1.0/stock/spy/chart/5y" @@ -434,7 +437,8 @@ class Stock: socket.create_connection(("www.andrewkdinh.com", 80)) return True except OSError: - pass + #pass + print("\nNo internet connection!") return False def main(self): @@ -449,7 +453,6 @@ class Stock: # Test internet connection internetConnection = Stock.is_connected() if internetConnection == False: - print("\nNo internet connection!") return listOfFirstLastDates = [] @@ -498,7 +501,6 @@ class Stock: finalClose = self.finalDatesAndClose[1] print(len(finalDates), "unique dates:", finalDates[len(finalDates)-1], "...", finalDates[0]) print(len(finalClose), "close values:", finalClose[len(finalClose)-1], "...", finalClose[0]) - #print("Uncomment above line in code to see output") else: print("No sources have data for", self.name) diff --git a/main.py b/main.py index 436088b..dc8fe5e 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ Asks for time period (Possibly: 1 year, 5 years, 10 years) Makes the mutual funds as class Stock Gets data from each API Compare and contrast dates and end changeOverTime for set time period - NOTES: Later can worry about getting close values to make a graph or something + NOTES: Later can worry about getting close values to make a graph or something Gives correlation value using equation at the end (from 0 to 1) FIRST TESTING WITH EXPENSE RATIO @@ -20,21 +20,48 @@ from StockData import Stock listOfStocks = [] numberOfStocks = int(input("How many stocks or mutual funds would you like to analyze? ")) for i in range(0, numberOfStocks, 1): - print("Stock", i+1, ": ", end='') - stockName = str(input()) - listOfStocks.append(i) - listOfStocks[i] = Stock() - listOfStocks[i].setName(stockName) - #print(listOfStocks[i].name) + print("Stock", i+1, ": ", end='') + stockName = str(input()) + listOfStocks.append(i) + listOfStocks[i] = Stock() + listOfStocks[i].setName(stockName) + #print(listOfStocks[i].name) +sumOfListLengths = 0 for i in range(0, numberOfStocks, 1): - print("\n") - print(listOfStocks[i].name) - Stock.main(listOfStocks[i]) + print(listOfStocks[i].name) + Stock.main(listOfStocks[i]) + # Count how many stocks are available + temp = Stock.getAllLists(listOfStocks[i]) + sumOfListLengths = sumOfListLengths + len(temp) + +if sumOfListLengths == 0: + print("No sources have stock data for given stocks") + +else: + #print(listOfStocks[0].name, listOfStocks[0].absFirstLastDates, listOfStocks[0].finalDatesAndClose) + indicatorFound = False + while indicatorFound == False: + print("\n1. Expense Ratio\n2. Asset Size\n3. Turnover\n4. Persistence\nWhich indicator would you like to look at? ", end='') + indicator = str(input()) + indicatorFound = True + + if indicator == 'Expense Ratio' or indicator == '1' or indicator == 'expense ratio': + print('\nExpense Ratio') + + elif indicator == 'Asset Size' or indicator == '2' or indicator == 'asset size': + print('\nAsset Size') + + elif indicator == 'Turnover' or indicator == '3' or indicator == 'turnover': + print('\nTurnover') + + elif indicator == 'Persistence' or indicator == '4' or indicator == 'persistence': + print('\nPersistence') + + else: + indicatorFound = False + print('\nInvalid input, please enter indicator again') -#print(listOfStocks[0].name, listOfStocks[0].absFirstLastDates, listOfStocks[0].finalDatesAndClose) -print("\nWhich indicator would you like to look at? \n1. Expense Ratio") -indicator = str(input) ''' stockName = 'IWV' stock1 = Stock(stockName) diff --git a/requirements.txt b/requirements.txt index 8024749..2bd7352 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -requests==2.21.0 \ No newline at end of file +requests==2.21.0 +numpy==1.15.4 \ No newline at end of file