FMPFMP
Datensätze
Insights/Data in Action/Model Builds/Calculating Cost of Equity with Python

Calculating Cost of Equity with Python

·

Updated Mar 17, 2026

·2 min read
Data in Action

In this post, we are going to use the Dividend Discount Model model to calculate the cost of equity with Python.

Photo by Lorenzo from Pexels.com

What is Cost of Equity?

Cost of equity is an essential element in finance. It is used in a lot of valuation methods and therefore, it is important to know how it can be calculated and what it represents.

Cost of equity is the required (expected) rate of return on equity. A firm cost of equity is the compensation required for the market in exchange of owning the assets and risk of the company. It represents the return that a firm theoretically pays to its investors.

Estimation of Cost of Equity

To estimate the cost of equity we can follow below four steps:

  • Retrieve the current share price.

  • Determine the current dividend per share.

  • Estimate the expected growth rate of the dividend payments.

  • Solve above equation to estimate the cost of equity.

And just like that, using the latest dividend of a company, the latest share price and an estimation of the expected growth, we can calculate the cost of equity for any company. Note that for estimating expected growth, we will use as a proxy the growth of past year dividends.

Calculating Cost of Equity using Python

Time to start coding. In our example, we will calculate Apple cost of equity with Python.

  • First, we retrieve the latest dividend per share and add it to the variable Dtoday.

  • Then, we retrieve the dividend from the last 3 years and compute the dividend growth during this period. We store it in a variable call dividend_growth.

  • Finally, we also retrieve the most recent price of the stock and calculate the cost of equity.

And here is the code. Please note that it uses special endpoints and you might be reqired to upgrade your plan.

import pandas as pd

import requests

demo = 'demo' # your API key

def cost_of_equity(stock):

IS = requests.get(f'https://financialmodelingprep.com/api/v3/historical-price-full/stock_dividend/{stock}?apikey={demo}')

IS = IS.json()

Dtoday = float(IS['historical'][0]['dividend'])

# get dividend growht from previous 3 year dividends

Div_2y = float(IS['historical'][1]['dividend'])

Div_3y = float(IS['historical'][2]['dividend'])

Div_4y = float(IS['historical'][3]['dividend'])

dividend_growth = ( Div_2y - Div_4y)/Div_4y

#price of the stock

ccompany_info = requests.get(f'https://financialmodelingprep.com/api/v3/historical-price-full/{stock}?apikey={demo}')

ccompany_info = ccompany_info.json()

price = float(ccompany_info[0]['price'])

#calculate cost of equity

ke = (Dtoday*(1+dividend_growth)/price) + dividend_growth

print(ke)

cost_of_equity('MSFT')

Then we can use the output in our analysis.

Is the Dividend Discount Model a Good Approach to Calculate Cost of Equity?

Compared to the CAPM method that we saw in my previous article, the Gordon Growth model (or Dividend Discount model) is quite easy to use. The data is easily accessible.

However, it is rather a very simplistic method and it only works for companies which pay dividends. For example, we could not use this method to get Amazon cost of equity since it does not pay dividends.

Also, we assume that the expected growth rate can be extrapolated based on the latest dividends. This may be true for mature companies. However, dividend payouts in growth companies may change year to year.

As a potential workaround, we could use more complicated models based on the dividend discount model. For instance, we could use multiple various growth rates instead of only one. But we will probably cover that in a future post.

Tags:

About the Author

Rajnish Katharotiya
Rajnish Katharotiya

Financial data, valuation, and FMP API workflows

Rajnish Katharotiya writes about financial data, valuation, and the practical use of the FMP API. His work focuses on connecting structured market data to real analysis and repeatable workflows for developers and investors.

Related

Financial data for every need

Real-time quotes and 30+ years of historical data, including prices, fundamentals, and insider transactions — all accessible via API.