The SEC requires publicly traded companies to file annual and quarterly reports on an ongoing basis. These reports detail the financial results of operations, the financial position, and the cash flow of the organization. If you're interested, you can learn more about how to read financial statements. From these financial statements, we can calculate various metrics and ratios that can provide insight into the nature of the company or how it's performing. Thankfully, you don't have to import the financial statements and calculate these for yourself -- Intrinio has already done that for us.
Financial Calculations & Metrics
Intrinio provides us with the needed calculations and metrics. For this post, let's add the classic price-to-book ratio (P/B) ratio. We'll start by exploring the API through the REPL.
Exploring the Intrinio Fundamentals API
Start by activating the environment we created in part one, importing what we need, and grabbing both the CompanyApi and FundamentalsApi.
Now let's loop through the api_response to get the P/B using the tag pricetobook.
pricetobook = None
for calc in api_response.standardized_financials_dict:
if calc['data_tag']['tag'] == 'pricetobook':
pricetobook = calc['value']
Congratulations! You just grabbed your first fundamental value!
Adding Fundamentals to Data Feed
While there are many ways you can store the data, I prefer to add fundamental and alternative data directly to the data feed I'm working with. If you remember from part one, we created a CSV file with the OHLCV fields. We'll append pricetobook to the end of these values. We'll need to loop through each page and add that to our prices dictionary.
As you progress on your journey, you'll want to be able to slice and dice data to observe relationships and build various trading indicators. For this, you'll need Pandas.
pip install pandas
Pandas was developed at hedge fund AQR by Wes McKinney to enable quick analysis of financial data. Pandas is an extension of NumPy that supports vectorized operations, enabling fast manipulation of financial information. While out of scope for these posts, I would consider Pandas required learning for systematic and algorithmic trading. You can learn more by reading How to Manipulate Data with Pandas and Python.
With that out of the way, let's append our price to book to our OHLC values. First, we'll import pandas and read in our list of dictionaries to a pandas dataframe.