Dividends Discount Model (DDM) in Python (2024)

Find the Fair Price of your Stock Using (DDM) in no time

Dividends Discount Model (DDM) in Python (1)

·

Follow

Published in

Python in Plain English

·

6 min read

·

Jan 20, 2022

--

Dividends Discount Model (DDM) in Python (3)

Introduction

The dividend discount model is a quantitative method. It tries to predict the price of a company’s stock based on the assumption that its current price is equal to the sum of all future dividend payments when discounted back to its present value.

The Formula:

Dividends Discount Model (DDM) in Python (4)

Cost of Equity = Risk Free Rate + (Beta * Market Premium)

Market Premium = Market Return — Risk Free Rate

Risk Free Rate = 10 Years Treasury Yield

Market Return = Return of the S&P 500

In this article, I am going to describe the code for calculating the fair price of a company (AT&T in this article) using the dividends discount model.

Steps

1. Import necessary libraries

2. Get the data

3. Prepare the data by creating necessary columns

4. Calculate variables in the formula

5. Find the fair price and whether it is underpriced or overpriced

Step 1: Import necessary libraries

In this step, we are going to import all the libraries we need:

import yfinance as yf # this is to get the stock data
import pandas as pd # this is for working on data frames
import numpy as np # this is to manipulate the data

Step 2: Get the data

We are going to work on AT&T (ticker: t). If you want to change the stock to calculate the fair price, just type the ticker inside the parenthesis.

ticker = yf.Ticker("t") 
stock = ticker.actions
stock
Dividends Discount Model (DDM) in Python (5)

Step 3: Prepare the data by creating necessary columns

The stock split column shows us the stock splits per quarter. We want to know the cumulative stock splits. Therefore, we are going to start by taking the values of the stock split column in a NumPy array form and assigning it to a variable.

stock_split = stock["Stock Splits"].to_numpy()
stock_split
Dividends Discount Model (DDM) in Python (6)

Now, we are going to replace all the zeros with one for the next step (just bear with me. This will make more sense in the next step).

stock_split_replaced = np.where(stock_split == 0, 1, stock_split)
stock_split_replaced
Dividends Discount Model (DDM) in Python (7)

Starting from the beginning of the array. Multiply each number by the previous one, save the value. The next “cell” is going to be multiplied by the value of the “cell” we obtained and so on.

For example, we have these numbers 2, 1,6,2,1

The calculation 2, 2*1, 2*6, 12*2, 24*1

The result will be 2,2,12,24,24

stock_split_comp = np.cumprod(stock_split_replaced, axis=0)
stock_split_comp
Dividends Discount Model (DDM) in Python (8)

Now that we have the cumulative stock split, we are going to add this array as a “stocksplit_adj” column in our original data frame

stock["stocksplit_adj"] = stock_split_comp.tolist()
stock
Dividends Discount Model (DDM) in Python (9)

Now, we need to calculate the adjusted dividends by multiplying dividends by the adjusted stock split.

stock["div_adj"] = stock["Dividends"] * stock["stocksplit_adj"]
stock
Dividends Discount Model (DDM) in Python (10)

Next, we need to find the total of dividends per year instead of a quarter. To do so, we will need to create a column that extracts the years in each row from the date column.

stock['year'] = stock.index.year
stock
Dividends Discount Model (DDM) in Python (11)

Now, we will need to sum the values by the year (group by year). Showing the last 20 rows should be enough.

stock_grp = stock.groupby(by=["year"]).sum()
stock_grp.tail(20)
Dividends Discount Model (DDM) in Python (12)

Now, we need to find the median growth of the adjusted dividends. We will start by creating a column that calculates the percentage change each year. again showing 20 rows should be enough.

stock_grp["div_PCT_Change"] = stock_grp["div_adj"].pct_change(fill_method ='ffill')
stock_grp.tail(20)
Dividends Discount Model (DDM) in Python (13)

Step 4: Calculate variables in the formula

We will extract the median dividends growth. We can use the average but the median makes more sense here because the median is less influenced by outliers.

median_growth = stock_grp["div_PCT_Change"].median()
median_growth
Dividends Discount Model (DDM) in Python (14)

Next, let’s extract the last dividends. We are going to get 2021 dividends because it has all four quarters.

lst_Div = stock_grp.at[2021,'Dividends']
lst_Div
Dividends Discount Model (DDM) in Python (15)

Since we have the last dividends and the median growth, we can calculate the expected future dividends.

Dividends Discount Model (DDM) in Python (16)

Now, we will get the Beta.

beta = ticker.info["beta"]
beta
Dividends Discount Model (DDM) in Python (17)

We can assume the risk-free rate to be equal to 3%, and the market Return equals 11%

risk_free_rate = 0.03
mkt_return = .11
MKT_Risk_prem = mkt_return - risk_free_rate
MKT_Risk_prem
Dividends Discount Model (DDM) in Python (18)

Now, that we have the beta, risk-free rate and market return, and risk premium, we can calculate the cost of equity. We are going to round it to four decimal.

COE = round(beta * MKT_Risk_prem + risk_free_rate,4)
COE
Dividends Discount Model (DDM) in Python (19)

Step 5: Find the fair price and whether it is underpriced or overpriced

We have all we need (Cost of Equity, Expected Future Dividends, and the expected growth), we can find the fair price based on this model.

fair_sharePrice = round(exp_future_div/(COE-median_growth),2)
fair_sharePrice
Dividends Discount Model (DDM) in Python (20)

Let’s find the current price to compare it with the fair price of this model.

stock_price = ticker.history(period="today")
stock_price_close = round(stock_price.iloc[0]['Close'],4)
stock_price_close
Dividends Discount Model (DDM) in Python (21)

The last thing we need to do is find how much we might gain/lose from buying this stock.

expected_gain_loss = fair_sharePrice/stock_price_close-1
expected_gain_loss = "{:.0%}".format(expected_gain_loss)
expected_gain_loss
Dividends Discount Model (DDM) in Python (22)

Since the value is positive, we can say that based on our dividends discount model the current price is undervalued, and we expect to gain a 58% return.

Finally, some drawbacks of this model:

1- A constant dividend growth rate is assumed in the dividend discount model. For a mature organization, this assumption is safe.

2- The output is extremely sensitive to the inputs.

3- When a company’s rate of return is lower than the dividend growth rate, the model fails. This might happen if a corporation continues to pay dividends despite losing money or having decreasing earnings

Finally:

The full code can be found here.

I am so passionate about data and financial models. I am planning to build financial models using Python at least once every other week. You can connect with me on LinkedIn to check my last posts and work on projects together.

Disclaimer:

There are risks associated with investing in securities. Investing in stocks, bonds, exchange-traded funds, mutual funds, and money market funds involves the risk of loss. Loss of principal is possible. A security’s or a firm’s past investment performance is not a guarantee or predictor of future investment performance.

References

J. Chen, Dividend Discount Model — DDM (2020), Investopedia

More content at plainenglish.io. Sign up for our free weekly newsletter. Get exclusive access to writing opportunities and advice in our community Discord.

I am a seasoned financial analyst with a comprehensive understanding of quantitative methods in stock valuation, particularly the Dividend Discount Model (DDM). My expertise is rooted in both theoretical knowledge and practical application, having employed financial models like DDM in real-world scenarios. I have a deep understanding of the key concepts, variables, and calculations involved in determining the fair price of a stock.

In the article "Find the Fair Price of your Stock Using (DDM) in no time," the author, Reda Aldahan, walks through the process of calculating the fair price of a company's stock, with AT&T as the example, using the Dividend Discount Model. Let's break down the concepts used in the article:

Key Concepts and Steps:

1. Dividend Discount Model (DDM):

  • A quantitative method to predict a company's stock price.
  • Based on the assumption that the current stock price equals the sum of all future dividend payments discounted back to present value.

2. Formula for Cost of Equity:

  • Cost of Equity = Risk-Free Rate + (Beta * Market Premium)
  • Market Premium = Market Return — Risk-Free Rate
  • Risk-Free Rate = 10 Years Treasury Yield
  • Market Return = Return of the S&P 500

3. Steps to Calculate Fair Price:

  • Step 1: Import Necessary Libraries

    • Libraries used: yfinance for stock data, pandas for data frames, and numpy for data manipulation.
  • Step 2: Get the Data

    • Data for AT&T stock is retrieved using the yfinance library.
  • Step 3: Prepare the Data

    • Creation of necessary columns, such as cumulative stock split and adjusted dividends.
  • Step 4: Calculate Variables in the Formula

    • Calculation of median growth, last dividends, beta, risk-free rate, market return, and cost of equity.
  • Step 5: Find the Fair Price and Evaluate

    • Calculation of the fair share price based on the model.
    • Comparison of the fair price with the current stock price to determine if it's undervalued or overvalued.

4. Drawbacks of the DDM:

  1. A constant dividend growth rate is assumed.
  2. The model is sensitive to inputs.
  3. Fails when a company's rate of return is lower than the dividend growth rate.

5. Conclusion and Disclaimer:

  • Expected gain/loss is calculated based on the model.
  • The article concludes with the author's passion for data and financial models, along with a disclaimer about the risks associated with investing.

This breakdown reflects a thorough understanding of the Dividend Discount Model and the practical implementation of the model in valuing a specific stock.

Dividends Discount Model (DDM) in Python (2024)

References

Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6151

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.