FMP
Sep 11, 2023 4:59 PM - Rajnish Katharotiya
In this post we are going to learn how to analyse cash flow statements with Python. We will build a Common-Size Cash Flow Statement to analyse how companies are generating and using cash.
During the first part of the post, we will focus on understanding what a cash flow statement is. Then, in the second part ,we will build our Python for Finance script to analyse the cash flow Statement of Apple.
Photo by Pixabay on Pexels.com
Cash flow statements can tell us a lot on how firms generate and spend cash. A cash flow statement can let us know how much cash receipts and payments a company made during a period of time. It help investors to understand if a firm will be in need of additional financing. In general, it provides very useful information to analyse firms solvency and liquidity.
Firms classify cash receipts and payments into three different categories using the cash flow statement:
Cash from Operating Activities. Cash payments and receipts generated from transactions affecting net income.
Cash from Investing Activities. Cash payments and receipts generated from acquisition or sales of long-term assets.
Cash from Financing Activities. Cash payments and receipts generated from transactions affecting the capital structure of firms.
Non cash transactions are not included in the Cash Flow Statement since that do not represent cash outflows or inflows.
When a firm is growing, it is very likely that it will have a negative cash flow from operations. That is because a growing firm will probably have big outflow of cash in order to build up inventory. At the same time, a growing company will accumulate receivables over time as the business grow.
To finance a firm's negative operating cash flow, a firm will need to get a loan or issue equity leading to a positive cash from financing activities. However, over the years companies need to turn negative operating cash flow into positive since it is not sustainable to always relay on external sources of finance.
Another thing to take into account is how the firm is generating positive operating cash flow. Is the firm having a positive operating cash flow because the firm suddenly sold a lot of inventory bringing it inventory levels close to 0? If that is the case, we need to watch out since the positive operating cash flow may not be related to the firm main core activities.
Another element of importance is capital expenditures. Growing firms are normally increasing capital expenditures since they invest in long term assets to support future sales.
Ideally, a firm would generate enough operating cash flow to cover its capital expenditures. Free Cash Flow (FCF) is a valuation measure often used by analysts to understand how much cash a company has generated after covering its capital expenditures:
FCF = Operating Cash Flow − Capital Expenditures
On the contrary, firms may sale PP&E and obtain cash out of it. This should not be seen as a good source of cash since long-term assets are required to generate cash from earning-related activities.
One of the best ways to analyse firms cash flow is using Common-Size Cash Flow Statements. That is, we take a firm cash flow and express each cash flow line item as a percentage of revenue.
A Common-Size Cash Flow statement will help us to identify how firm cash sources are changing over time. It helps us to see the cash flow as a trend analysis.
We are going to build a Python script in order to express the cash flow statement of firms as percentage of revenues. We can easily do that with financialmodellingprep API. And our analysis will focus on the cash flow from the last three years.
First thing we need to do is to make an api call to the API end point to retrieve the cash flow Statement of the firm that we are interested in. For instance, Apple.
As you can see below, we pass within the url the ticker from Apple, AAPL, in order to retrieve the cash flow statement from the API. We retrieve the income statement as well since we will need the company revenue to express the cash flow statement as a percentage of revenue. Then, we also create an empty dictionary CF_3Y where we will store the last three years cash flow statements:
import requests
import pandas as pd
api_key = 'demo'
CF = requests.get(f'https://financialmodelingprep.com/api/v3/cash-flow-statement/AAPL?apikey={api_key}').json()
count = 0
#Create an empty dictionary
CF_3Y = {}
IS = requests.get(f'https://financialmodelingprep.com/api/v3/income-statement/AAPL?apikey={api_key}').json()
print(CF)
The outcome is a list of dictionaries. Each dictionary contains a different period. Therefore, we loop through the three first elements of the list since they will give us the last three year cash flow statements. In addition, we also obtain the last three years of revenue and include them in the CF3Y dictionary:
for item in CF:
if count < 3:
date = item['date']
CF_3Y[date] = item
#we add revenue as well to the dictionary since we need it to calculate the common-size cash flow
CF_3Y[date]['Revenue'] = IS[count]['revenue']
count += 1
print(CF_3Y)
# outcome
{
'date': '2021-09-25',
'symbol': 'AAPL',
'reportedCurrency': 'USD',
'cik': '0000320193',
'netIncome': 94680000000,
'depreciationAndAmortization': 11284000000,
'deferredIncomeTax': -4774000000,
'stockBasedCompensation': 7906000000,
'changeInWorkingCapital': -4911000000,
...
},
Building a Pandas DataFrameNow, we can transform the dictionary into a Pandas DataFrame:
CF_Common_Size = pd.DataFrame.from_dict(CF_3Y, orient='index')
CF_Common_Size = CF_Common_Size.T
print(CF_Common_Size)
Revenue can be extracted from the last row of the Pandas DataFrame. So we can easily extract it to the variable Revenue:
Revenue = CF_Common_Size.iloc[-1]
Now we have the last three years cash flow statements from Apple. We need to clean up the first four rows since the Cash Flow Statement should start with Net Income. In addition, we get rid of the last three rows of the DataFrame.
CF_Common_Size = CF_Common_Size.iloc[5:-3,:]
Finally, to express the Cash Flow Statement as a percentage of revenue, we only need to divide each row by the revenues:
CF_Common_Size = (CF_Common_Size/Revenue) * 100
#show as percentage:
pd.options.display.float_format = '{:.2f}%'.format
print(CF_Common_Size)
And just with that few lines of code, we have built a common-size income statement with Python. You can apply it to any company you are interested in by simple changing the company ticker in the url.
Sep 11, 2023 - Rajnish Katharotiya
Price to Earnings is one of the key metrics use to value companies using multiples. The P/E ratio and other multiples are relative valuation metrics and they cannot be looked at in isolation. One of the problems with the P/E metric is the fact that if we are in the peak of a business cycle, earni...
Sep 11, 2023 - Rajnish Katharotiya
Price-to-Earnings ratio is a relative valuation tool. It is used by investors to find great companies at low prices. In this post, we will build a Python script to calculate Price Earnings Ratio for comparable companies. Photo by Skitterphoto on Pexels Price Earnings Ratio and Comparable Compa...
Oct 17, 2023 - Davit Kirakosyan
Shares of VMware (NYSE:VMW) witnessed a sharp drop of 12% intra-day today due to rising concerns about China's review of the company's significant sale deal to Broadcom. Consequently, Broadcom's shares also saw a dip of around 4%. Even though there aren’t any apparent problems with the proposed solu...