Financial Calculations & Valuation Intermediate

Automated 5-Year Discounted Cash Flow (DCF) Valuation Script in Python

Calculate intrinsic value per share of any stock using a 2-stage Discounted Cash Flow (DCF) model in Python. Includes WACC discounting and Terminal Value.

#numpy#pandas

Problem Statement

Building DCF spreadsheets manually for dozens of stocks is tedious. This script projects 5-year Free Cash Flows, computes Gordon Growth Terminal Value, and outputs Intrinsic Share Price.

Formula / Core Logic

Projected FCF_t = FCF_0 x (1 + g)^t Terminal Value = [FCF_5 x (1 + g_term)] / (WACC - g_term)

Installation

pip install numpy pandas
discounted-cash-flow-dcf-valuation-model-python.py
import numpy as np

def dcf_valuation(fcf0, g5, wacc, g_term, debt, cash, shares):
    years = np.arange(1, 6)
    fcf = [fcf0 * ((1 + g5) ** t) for t in years]
    pv_fcf = sum(fcf[i] / ((1 + wacc) ** (i + 1)) for i in range(5))
    tv = (fcf[-1] * (1 + g_term)) / (wacc - g_term)
    pv_tv = tv / ((1 + wacc) ** 5)
    equity_val = pv_fcf + pv_tv - debt + cash
    return {'Enterprise_Value': round(pv_fcf + pv_tv, 2), 'Equity_Value': round(equity_val, 2), 'Intrinsic_Share_Price': round(equity_val / shares, 2)}

Get the Complete 100+ Python Quant & Automation Bundle

Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).

Buy Full Bundle on Gumroad ($19) →

Frequently Asked Questions

Q: What should the terminal growth rate be?

Terminal growth rate should never exceed long-term GDP growth (typically 2% to 4%).