-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinancial_statements.py
31 lines (23 loc) · 1.29 KB
/
financial_statements.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
import pandas as pd
from financialModelingPrep import api
import requests
import os
def load_statement(fmp:api, symbol:str, statement_type:str, period:str) -> pd.DataFrame:
try:
statement = pd.read_csv(f"{symbol}_{statement_type}_{period}.csv")
print("loaded cached csv")
except:
statement = fmp.getStatement(symbol, statement_type, period)
print("Requested new data from API")
#Clean unwanted rows
if statement_type == "income-statement":
statement = statement.drop(["symbol", "reportedCurrency", "cik", "fillingDate", "acceptedDate", "calendarYear","period","link","finalLink"])
elif statement_type == "balance-sheet-statement":
statement = statement.drop(["symbol", "reportedCurrency", "cik", "fillingDate", "acceptedDate", "calendarYear","period","link","finalLink"])
elif statement_type == "cash-flow-statement":
pass
statement.to_csv(f"{symbol}_{statement_type}_{period}.csv")
return statement
fmp = api(os.environ.get("financialModelingPrep_API_Key"))
statement = load_statement(fmp, input("Symbol to get: ").upper(), input("Statement type to get (cash-flow-statement, income-statement, balance-sheet-statement): "), input("Period (type \"annual\"): "))
print(statement.head(5))