mirror of
https://github.com/andrewkdinh/fund-indicators.git
synced 2024-11-21 17:24:20 -08:00
Added support for datetime
This commit is contained in:
parent
7f675e25ae
commit
d1888d2779
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ __pycache__/
|
|||||||
quickstart.py
|
quickstart.py
|
||||||
creds.json
|
creds.json
|
||||||
test/
|
test/
|
||||||
|
.vscode/
|
||||||
|
listGoogle.py
|
@ -4,6 +4,8 @@ A project to determine indicators of overperforming mutual funds.
|
|||||||
This project is written in Python and will examine market capitalization, persistence, turnover, and expense ratios.
|
This project is written in Python and will examine market capitalization, persistence, turnover, and expense ratios.
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
`$ pip install -r requirements.txt`
|
||||||
|
or
|
||||||
`$ pip install requests`
|
`$ pip install requests`
|
||||||
|
|
||||||
Created by Andrew Dinh from Dr. TJ Owens Gilroy Early College Academy
|
Created by Andrew Dinh from Dr. TJ Owens Gilroy Early College Academy
|
||||||
|
24
StockData.py
24
StockData.py
@ -141,9 +141,17 @@ class StockData:
|
|||||||
|
|
||||||
def getAV(self):
|
def getAV(self):
|
||||||
listAV = []
|
listAV = []
|
||||||
url = ''.join(('https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=', self.name, '&apikey=', apiAV))
|
#url = ''.join(('https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=', self.name, '&apikey=', apiAV))
|
||||||
# https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=MSFT&apikey=demo
|
# https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=MSFT&apikey=demo
|
||||||
|
|
||||||
|
#url = ''.join(('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=', self.name, '&outputsize=full&apikey=', apiAV))
|
||||||
|
# https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&outputsize=full&apikey=demo
|
||||||
|
|
||||||
|
url = ''.join(('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=', self.name, '&outputsize=full&apikey=', apiAV))
|
||||||
|
# https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=demo
|
||||||
|
|
||||||
print("\nSending request to:", url)
|
print("\nSending request to:", url)
|
||||||
|
print("(This will take a while)")
|
||||||
f = requests.get(url)
|
f = requests.get(url)
|
||||||
json_data = f.text
|
json_data = f.text
|
||||||
loaded_json = json.loads(json_data)
|
loaded_json = json.loads(json_data)
|
||||||
@ -156,9 +164,9 @@ class StockData:
|
|||||||
return 'Not available'
|
return 'Not available'
|
||||||
|
|
||||||
#print(loaded_json['Monthly Time Series'])
|
#print(loaded_json['Monthly Time Series'])
|
||||||
monthlyTimeSeries = loaded_json['Monthly Time Series']
|
dailyTimeSeries = loaded_json['Time Series (Daily)']
|
||||||
#print(monthlyTimeSeries)
|
#print(monthlyTimeSeries)
|
||||||
listOfDates = list(monthlyTimeSeries)
|
listOfDates = list(dailyTimeSeries)
|
||||||
#print(listOfDates)
|
#print(listOfDates)
|
||||||
|
|
||||||
firstDate = listOfDates[-1]
|
firstDate = listOfDates[-1]
|
||||||
@ -179,8 +187,9 @@ class StockData:
|
|||||||
values = []
|
values = []
|
||||||
for i in range(0, len(listOfDates), 1):
|
for i in range(0, len(listOfDates), 1):
|
||||||
temp = listOfDates[i]
|
temp = listOfDates[i]
|
||||||
loaded_json2 = monthlyTimeSeries[temp]
|
loaded_json2 = dailyTimeSeries[temp]
|
||||||
value = loaded_json2['4. close']
|
#value = loaded_json2['4. close']
|
||||||
|
value = loaded_json2['5. adjusted close']
|
||||||
values.append(value)
|
values.append(value)
|
||||||
listAV.append(values)
|
listAV.append(values)
|
||||||
#print(listOfDates[0])
|
#print(listOfDates[0])
|
||||||
@ -485,6 +494,8 @@ class StockData:
|
|||||||
listOfFirstLastDates = []
|
listOfFirstLastDates = []
|
||||||
self.allLists = []
|
self.allLists = []
|
||||||
|
|
||||||
|
print('\nNOTE: Only IEX and Alpha Vantage support adjusted returns')
|
||||||
|
|
||||||
# IEX
|
# IEX
|
||||||
print("\nIEX")
|
print("\nIEX")
|
||||||
listIEX = StockData.getIEX(self)
|
listIEX = StockData.getIEX(self)
|
||||||
@ -504,6 +515,7 @@ class StockData:
|
|||||||
# COMMENTED OUT FOR NOW B/C LIMITED
|
# COMMENTED OUT FOR NOW B/C LIMITED
|
||||||
'''
|
'''
|
||||||
print("\nTiingo")
|
print("\nTiingo")
|
||||||
|
print("NOTE: Tiingo does not return adjusted returns!!")
|
||||||
listTiingo = StockData.getTiingo(self)
|
listTiingo = StockData.getTiingo(self)
|
||||||
#print(listTiingo)
|
#print(listTiingo)
|
||||||
if listTiingo != 'Not available':
|
if listTiingo != 'Not available':
|
||||||
@ -515,7 +527,7 @@ class StockData:
|
|||||||
#print(listOfFirstLastDates)
|
#print(listOfFirstLastDates)
|
||||||
if (len(self.allLists) > 0):
|
if (len(self.allLists) > 0):
|
||||||
print("\n")
|
print("\n")
|
||||||
print(len(self.allLists), "available sources for", self.name)
|
print(len(self.allLists), "available source(s) for", self.name)
|
||||||
self.absFirstLastDates = StockData.getFirstLastDate(self, listOfFirstLastDates)
|
self.absFirstLastDates = StockData.getFirstLastDate(self, listOfFirstLastDates)
|
||||||
print("\nThe absolute first date with close values is:", self.absFirstLastDates[0])
|
print("\nThe absolute first date with close values is:", self.absFirstLastDates[0])
|
||||||
print("The absolute last date with close values is:", self.absFirstLastDates[1])
|
print("The absolute last date with close values is:", self.absFirstLastDates[1])
|
||||||
|
@ -107,11 +107,12 @@ class Return:
|
|||||||
print("\nPlease enter a time frame in years: ", end='')
|
print("\nPlease enter a time frame in years: ", end='')
|
||||||
#timeFrameYear = int(input())
|
#timeFrameYear = int(input())
|
||||||
timeFrameYear = 5
|
timeFrameYear = 5
|
||||||
|
print(timeFrameYear)
|
||||||
self.timeFrame.append(timeFrameYear)
|
self.timeFrame.append(timeFrameYear)
|
||||||
print("Please enter a time frame in months (30 days): ", end='')
|
print("Please enter a time frame in months (30 days): ", end='')
|
||||||
#timeFrameMonth = int(input())
|
#timeFrameMonth = int(input())
|
||||||
timeFrameMonth = 0
|
timeFrameMonth = 0
|
||||||
print('')
|
print(timeFrameMonth)
|
||||||
self.timeFrame.append(timeFrameMonth)
|
self.timeFrame.append(timeFrameMonth)
|
||||||
#print(self.timeFrame)
|
#print(self.timeFrame)
|
||||||
self.firstLastDates = Return.getFirstLastDates(self, stock)
|
self.firstLastDates = Return.getFirstLastDates(self, stock)
|
||||||
@ -124,7 +125,8 @@ class Return:
|
|||||||
print('\nGetting unadjusted return')
|
print('\nGetting unadjusted return')
|
||||||
unadjustedReturn = Return.getUnadjustedReturn(self, stock)
|
unadjustedReturn = Return.getUnadjustedReturn(self, stock)
|
||||||
self.listOfReturn.append(unadjustedReturn)
|
self.listOfReturn.append(unadjustedReturn)
|
||||||
print(self.listOfReturn[0], '%')
|
print(self.listOfReturn[0])
|
||||||
|
print(self.listOfReturn[0]/timeFrameYear, '%')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
stockName = 'spy'
|
stockName = 'spy'
|
||||||
|
Loading…
Reference in New Issue
Block a user