Started Expense Ratio

This commit is contained in:
Andrew Dinh 2018-12-31 16:37:51 -08:00
parent d2b58de37a
commit d3c1bf0155
4 changed files with 67 additions and 17 deletions

20
ExpenseRatio.py Normal file
View File

@ -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()

View File

@ -60,6 +60,9 @@ class Stock:
def setName(self, newName): def setName(self, newName):
self.name = newName self.name = newName
def getAllLists(self):
return self.allLists
def getIEX(self): def getIEX(self):
url = ''.join(('https://api.iextrading.com/1.0/stock/', self.name, '/chart/5y')) url = ''.join(('https://api.iextrading.com/1.0/stock/', self.name, '/chart/5y'))
#link = "https://api.iextrading.com/1.0/stock/spy/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)) socket.create_connection(("www.andrewkdinh.com", 80))
return True return True
except OSError: except OSError:
pass #pass
print("\nNo internet connection!")
return False return False
def main(self): def main(self):
@ -449,7 +453,6 @@ class Stock:
# Test internet connection # Test internet connection
internetConnection = Stock.is_connected() internetConnection = Stock.is_connected()
if internetConnection == False: if internetConnection == False:
print("\nNo internet connection!")
return return
listOfFirstLastDates = [] listOfFirstLastDates = []
@ -498,7 +501,6 @@ class Stock:
finalClose = self.finalDatesAndClose[1] finalClose = self.finalDatesAndClose[1]
print(len(finalDates), "unique dates:", finalDates[len(finalDates)-1], "...", finalDates[0]) print(len(finalDates), "unique dates:", finalDates[len(finalDates)-1], "...", finalDates[0])
print(len(finalClose), "close values:", finalClose[len(finalClose)-1], "...", finalClose[0]) print(len(finalClose), "close values:", finalClose[len(finalClose)-1], "...", finalClose[0])
#print("Uncomment above line in code to see output")
else: else:
print("No sources have data for", self.name) print("No sources have data for", self.name)

33
main.py
View File

@ -27,14 +27,41 @@ for i in range(0, numberOfStocks, 1):
listOfStocks[i].setName(stockName) listOfStocks[i].setName(stockName)
#print(listOfStocks[i].name) #print(listOfStocks[i].name)
sumOfListLengths = 0
for i in range(0, numberOfStocks, 1): for i in range(0, numberOfStocks, 1):
print("\n")
print(listOfStocks[i].name) print(listOfStocks[i].name)
Stock.main(listOfStocks[i]) 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) #print(listOfStocks[0].name, listOfStocks[0].absFirstLastDates, listOfStocks[0].finalDatesAndClose)
print("\nWhich indicator would you like to look at? \n1. Expense Ratio") indicatorFound = False
indicator = str(input) 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')
''' '''
stockName = 'IWV' stockName = 'IWV'
stock1 = Stock(stockName) stock1 = Stock(stockName)

View File

@ -1 +1,2 @@
requests==2.21.0 requests==2.21.0
numpy==1.15.4