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):
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)

53
main.py
View File

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

View File

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