Analysing Cash Flow Statements with Python

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

Analysing Cash Flow Statements with Python

Sep 11, 2023 4:59 PM - Rajnish Katharotiya

blog post cover photo

Image credit: Lukas Blazek

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

Understanding Cash Flow

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.

How to interpret the different Cash Flows categories

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.

Investing Activities and Free Cash Flow

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.

Common-Size Cash Flow - Analysing CF Statements with Python

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.

Starting the Cash Flow Python code

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'{api_key}').json()

count = 0

#Create an empty dictionary

CF_3Y = {}

IS = requests.get(f'{api_key}').json()


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


# 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


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


Wrapping Up

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.

Other Blogs

Sep 11, 2023 - Rajnish Katharotiya

P/E Ratios Using Normalized Earnings

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...

blog post title

Sep 11, 2023 - Rajnish Katharotiya

What is Price To Earnings Ratio and How to Calculate it using Python

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...

blog post title

Oct 17, 2023 - Davit Kirakosyan

VMware Stock Drops 12% as China May Hold Up the Broadcom Acquisition

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...

blog post title


Financial Modeling Prep API provides real time stock price, company financial statements, major index prices, stock historical data, forex real time rate and cryptocurrencies. Financial Modeling Prep stock price API is in real time, the company reports can be found in quarter or annual format, and goes back 30 years in history.
2017-2023 © Financial Modeling Prep