FMP

Calculating Cost of Equity with Python

Calculating Cost of Equity with Python

Sep 11, 2023 5:18 PM - Rajnish Katharotiya

Image credit: Austin Distel

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.

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

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

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

FMP

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