Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created October 27, 2021 22:49
Show Gist options
  • Select an option

  • Save marcosan93/1a17d241540fc01bf178617c85f431d3 to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/1a17d241540fc01bf178617c85f431d3 to your computer and use it in GitHub Desktop.
def getFundamentals(ticker):
"""
Returns the fundamental data from the financial data API. Combines the quarterly balance
sheet, cash flow, income statement, and earnings for a specific stock ticker.
"""
# Getting data
fund_data = client.get_fundamental_equity(ticker)
# Financials
bal = pd.DataFrame(fund_data['Financials']['Balance_Sheet']['quarterly']).T
cf = pd.DataFrame(fund_data['Financials']['Cash_Flow']['quarterly']).T
inc = pd.DataFrame(fund_data['Financials']['Income_Statement']['quarterly']).T
# Earnings
earn = pd.DataFrame(fund_data['Earnings']['History']).T
# Merging them together
df = reduce(
lambda left,right: pd.merge(
left,
right,
left_index=True,
right_index=True,
how='outer',
suffixes=('', '_drop')
),
[bal, cf, inc, earn]
)
# Dropping redundant date and duplicate columns
dup_cols = [i for i in df.columns if "date" in i or "Date" in i or "_drop" in i]
df = df.drop(dup_cols, axis=1)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment