fund-indicators/main.py

120 lines
3.8 KiB
Python
Raw Normal View History

2018-12-15 17:56:29 -08:00
# main.py
# Andrew Dinh
# Python 3.6.1
2019-01-16 08:54:06 -08:00
# Description:
2018-12-16 17:58:25 -08:00
'''
Asks users for mutual funds/stocks to compare
Asks to be compared (expense ratio, turnover, market capitalization, or persistence)
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
2018-12-31 16:37:51 -08:00
NOTES: Later can worry about getting close values to make a graph or something
2018-12-16 17:58:25 -08:00
Gives correlation value using equation at the end (from 0 to 1)
2018-12-16 14:46:56 -08:00
2018-12-16 17:58:25 -08:00
FIRST TESTING WITH EXPENSE RATIO
'''
2018-12-16 14:46:56 -08:00
2019-01-16 08:54:06 -08:00
from StockData import StockData
2019-01-30 08:18:34 -08:00
from StockReturn import Return
2018-12-19 21:32:14 -08:00
2019-01-30 08:18:34 -08:00
listOfStocksData = []
listOfStocksReturn = []
#numberOfStocks = int(input("How many stocks or mutual funds would you like to analyze? ")) # CHANGE BACK LATER
numberOfStocks = 1
2018-12-21 09:59:40 -08:00
for i in range(0, numberOfStocks, 1):
2018-12-31 16:37:51 -08:00
print("Stock", i+1, ": ", end='')
stockName = str(input())
2019-01-30 08:18:34 -08:00
listOfStocksData.append(i)
listOfStocksData[i] = StockData()
listOfStocksData[i].setName(stockName)
# print(listOfStocksData[i].name)
#listOfStocksReturn.append(i)
#listOfStocksReturn[i] = StockReturn()
# Decide on a benchmark
benchmarkTicker = ''
while benchmarkTicker == '':
listOfBenchmarks = ['S&P500', 'DJIA', 'Russell 3000', 'MSCI EAFE']
listOfBenchmarksTicker = ['SPY', 'DJIA', 'VTHR', 'EFT']
print('\nList of benchmarks:', listOfBenchmarks)
#benchmark = str(input('Benchmark to compare to: '))
benchmark = 'S&P500'
for i in range(0,len(listOfBenchmarks), 1):
if benchmark == listOfBenchmarks[i]:
benchmarkTicker = listOfBenchmarksTicker[i]
i = len(listOfBenchmarks)
if benchmarkTicker == '':
print('Benchmark not found. Please type in a benchmark from the list')
print('\n', benchmark, ' (', benchmarkTicker, ')', sep='')
benchmarkName = str(benchmark)
benchmark = StockData()
benchmark.setName(benchmarkName)
StockData.main(benchmark)
benchmarkReturn = Return()
Return.mainBenchmark(benchmarkReturn, benchmark)
timeFrame = Return.returnTimeFrame(benchmarkReturn)
print('Time Frame [years, months]:', timeFrame)
2018-12-19 21:32:14 -08:00
2018-12-31 16:37:51 -08:00
sumOfListLengths = 0
2018-12-21 09:59:40 -08:00
for i in range(0, numberOfStocks, 1):
2019-01-30 08:18:34 -08:00
print('\n', listOfStocksData[i].name, sep='')
StockData.main(listOfStocksData[i])
2018-12-31 16:37:51 -08:00
# Count how many stocks are available
2019-01-30 08:18:34 -08:00
sumOfListLengths = sumOfListLengths + len(StockData.returnAllLists(listOfStocksData[i]))
2018-12-31 16:37:51 -08:00
if sumOfListLengths == 0:
2019-01-16 08:54:06 -08:00
print("No sources have data for given stocks")
exit()
2018-12-31 16:37:51 -08:00
2019-01-16 08:54:06 -08:00
# Find return over time using either Jensen's Alpha, Sharpe Ratio, Sortino Ratio, or Treynor Ratio
2019-01-30 08:18:34 -08:00
for i in range(0, numberOfStocks, 1):
print('\n', listOfStocksData[i].name, sep='')
#StockReturn.main(listOfStocksReturn[i])
2018-12-31 16:37:51 -08:00
2019-01-16 08:54:06 -08:00
# Runs correlation or regression study
2019-01-30 08:18:34 -08:00
# print(listOfStocksData[0].name, listOfStocksData[0].absFirstLastDates, listOfStocksData[0].finalDatesAndClose)
2019-01-16 08:54:06 -08:00
indicatorFound = False
while indicatorFound == False:
2019-01-30 08:18:34 -08:00
print("1. Expense Ratio\n2. Asset Size\n3. Turnover\n4. Persistence\nWhich indicator would you like to look at? ", end='')
#indicator = str(input()) # CHANGE BACK TO THIS LATER
indicator = 'Expense Ratio'
print(indicator, end='')
2019-01-16 08:54:06 -08:00
indicatorFound = True
2019-01-30 08:18:34 -08:00
print('\n', end='')
2018-12-31 16:37:51 -08:00
2019-01-16 08:54:06 -08:00
if indicator == 'Expense Ratio' or indicator == '1' or indicator == 'expense ratio':
#from ExpenseRatio import ExpenseRatio
print('\nExpense Ratio')
2018-12-31 16:37:51 -08:00
2019-01-16 08:54:06 -08:00
elif indicator == 'Asset Size' or indicator == '2' or indicator == 'asset size':
print('\nAsset Size')
2018-12-31 16:37:51 -08:00
2019-01-16 08:54:06 -08:00
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
2019-01-30 08:18:34 -08:00
print('Invalid input, please enter indicator again')
2018-12-21 09:59:40 -08:00
'''
2018-12-19 21:32:14 -08:00
stockName = 'IWV'
stock1 = Stock(stockName)
print("Finding available dates and close values for", stock1.name)
2019-01-16 08:54:06 -08:00
StockData.main(stock1)
'''