-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfundamental_data.py
33 lines (24 loc) · 1011 Bytes
/
fundamental_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import pandas as pd
# get fundamental data for
def get_fin_data(tickerlist, report_type):
df = pd.DataFrame()
for ticker in tickerlist:
try:
url = 'https://api.polygon.io/v2/reference/financials/' + ticker + '?type=' + report_type + '&apiKey=AKD9NA6TPAY71JOD3TQJ'
# gets results in dataframe
data = requests.get(url).json()
df1 = pd.DataFrame(data['results'])
# shares column has # of outstanding shares
df = df.append(df1)
print(ticker + " (" + str(tickerlist.index(ticker) + 1) + "/" + str(len(tickerlist)) + "): SUCCESS")
except:
print(ticker + " (" + str(tickerlist.index(ticker) + 1) + "/" + str(len(tickerlist)) + "): FAILURE")
return df
# returns unadjusted quarterly fin data
tickerlist = ['AAPL', 'GOOGL']
# report_type: Q = quarterly, A = Annual, QA = quarterly annualized
df = get_fin_data(tickerlist, 'Q')
# stores data in csv
df.to_csv('fundamental-data.csv')
df