Analysing Companies Leverage with Python

In this article, we are going to learn how to analyse companies leverage with Python. First, we will start with a short introduction on what is leverage and how to interpret it. Then, we will move to Python to learn how to calculate the degree of financial leverage. As we will see, it is super easy to code.

Photo by Karolina Grabowska on

Measuring Companies Leverage

All companies face two level of risk affecting stock prices. On one side, companies suffer from business risk which includes sales and operating risks. On the other side, they may also experience financial risk which is related to the company capital structure and the amount of financial debt.

There is a clear distinction between business risk and financial risk. Business risk includes factors such as industry structure, where we are in the economic cycle and the company cost structure (variable costs versus fixed costs). Financial risk has more to do with the capital structure of the company and the amount of debt.

Now that we know a bit more about the two type of risk levels. We can link them to the total company leverage. On one hand, we have operating leverage which measures the usage of fixed vs variable costs in a company cost structure and therefore it is associated to business risk.

On the other hand, we have financial risk that we can link to the company financial leverage.

Therefore, total leverage of a company can be calculated as shown below:

Total Leverage = Operating Leverage * Financial Leverage

A high degree of leverage will increase the volatility of company earnings and therefore will also increase the cost of capital.

Operating Leverage

Operating leverage is dependent on the industry that the company is operating in. For example, airlines tend to have a high level of fixed costs. The reason for it is that they have to invest huge amounts of money in airplanes. In order for airlines to make money, they need to fleet planes to almost 100% of capacity since variables costs, that is cost per passenger, are very low.

Operating leverage is not something that the management of a company can easily influence since it is industry inherent. For example, it is not possible for management to control the cycle of the economy that we are in. Or in the case of an airline, to reduce the level of fixed costs when planes are required to operate.

The Degree of Operating Leverage (DOL) can be calculated as per below. We need to first know the contribution margin of the company in oder to calculate the company DOL. And to calculate the contribution margin, we need to know the variable and fixed costs of the company. Unfortunately, this information is not available in the external financial reports from the company and therefore, we cannot calculate them in this post using Python.

Contribution Margin = Sales — Variable Costs

DOL = Contribution Margin / Operating Profit

Financial Leverage

On the contrary, financial leverage is fully under management control and influence. If the degree of financial leverage is high, a company management can always decide (except in extreme circumstances) to reduce levels of debt.

The degree of financial leverage can be calculated dividing a company operating profit by earnings before taxes.

In the next section, we are going to see how to calculate the degree of financial leverage with Python

DFL (Degree of Financial Leverage) = Operating Profit / Earnings Before Taxes

Calculating the Degree of Financial Leverage with Python

It is super easy to calculate a company financial leverage with Python. We will be using financialmodelingprep. It offers 250 free API calls per month by signing up. If 250 calls per month are not enough, you can sign up for a bit more than 100$ a year to have unlimited access. Readers of my posts can get a 25% discount by using the following link.

Lets start with making a request to the API in order to get income statement data. In our example, we are going to calculate Apple financial leverage:

import requests
import pandas as pd

apikey = 'your api key'

stock = 'AAPL'
IS = requests.get(f"{stock}?period=quarter&apikey={apikey}").json()


[{'acceptedDate': '2020-07-30 19:29:09',
'costAndExpenses': 33133000000,
'costOfRevenue': 37005000000,
'date': '2020-06-27',
'depreciationAndAmortization': 2752000000,
'ebitda': 1

Note that you need to include your api key from financialmodelingprep in the apikey variable. Otherwise, the code will not work.

The API returns a list of multiple year quarterly income statements. We need to parse the first element in the list since it contains the most recent quarter. Then, from the returning dictionary, we can extract operating profits and earnings before tax. Remember that we calculate the degree of financial leverage by dividing these two items:

operating_Profit = IS[0]['operatingIncome'] - IS[0]['operatingExpenses']
EBT = IS[0]['incomeBeforeTax']

financialLeverage = operating_Profit/ EBT

By running the code above and based on the latest available income statement for Apple, we get a degree of financial leverage of 0.26. That means, that if Apple increase operating profits by 10%, the increase in net income would be 2.6% (10 * 0.26).

Wrapping Up

We have seen how to calculate the degree of financial leverage using Python. As mentioned above, company managers have influence over the degree of financial leverage in a company but not on the operating leverage.

It is also interesting to learn how financial leverage affects other company metrics. For instance, in my previous posts on analysing ROE with Python, we saw how financial leverage increases return on equity. Therefore, as long as economy conditions are favourable, taking on debt may help improve the return on equity.

Leverage can act as a magnifier of earnings but it can also have the same role in adverse economic situations. Therefore, before investing in highly leverage companies, it is always good to understand in which cycle of the economy are we in. If we are starting an expansionary cycle, highly leveraged companies may be seen as a good option.

Originally published at on August 21, 2020.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store