A 5-year DCF model to estimate the intrinsic value of publicly traded companies. Built in Python with automated financial data retrieval, WACC calculation via CAPM, sensitivity analysis, and visualization. Pls try it ;)
| Feature | Description |
|---|---|
| 5-Year FCF Projections | Revenue, EBIT, EBIAT, D&A, CapEx, and NWC projected using weighted historical margins and analyst consensus estimates |
| WACC via CAPM | Automated calculation of Cost of Equity (CAPM), Cost of Debt, and capital structure weights |
| Terminal Value | Perpetual Growth (Gordon Growth) and EV/EBITDA Exit Multiple methods, with sector-aware default multiples |
| Monte Carlo Simulation | 10,000-run probabilistic valuation randomizing growth, margins, WACC, and TGR — outputs a price distribution with percentiles |
| Scenario Analysis | Bull / Base / Bear cases with different growth and margin assumptions |
| Sensitivity Analysis | Matrix of implied prices across WACC and Terminal Growth Rate scenarios |
| Comparable Company Analysis | Auto-fetches P/E, EV/EBITDA, EV/Revenue, and P/S for peer companies |
| Implied Growth Rate | Bisection algorithm to reverse-engineer the growth rate priced into the current stock price |
| Multi-Stock Comparison | Run the model across multiple tickers and compare valuations side by side |
| Visualization | 6-chart report: FCF bars, sensitivity heatmap, valuation bridge, Monte Carlo histogram, scenario analysis, and key metrics |
| JSON Export | Export model outputs for integration with other tools |
# Clone the repo
git clone https://github.com/EmanueleSturzo/DCF-Valuation-Model.git
(download zip file and extract)
for Mac:
cd ~/Downloads/DCF-Valuation-Model-main
for windows:
cd C:\Users\UserName\Downloads\DCF-Valuation-Model-main
# Install dependencies
pip install -r requirements.txt
# Run the model
python dcf\_model.py --ticker AAPLpython dcf\_model.py --ticker AAPLOutput:
============================================================
DCF VALUATION SUMMARY — Apple Inc. (AAPL)
============================================================
Sector: Technology
Industry: Consumer Electronics
Current Price: $217.90
Shares Outstanding: 15.115B
============================================================
KEY ASSUMPTIONS
────────────────────────────────────────
Revenue Growth (Yr1): 7.32%
EBIT Margin: 31.52%
Effective Tax Rate: 16.02%
...
VALUATION OUTPUT
────────────────────────────────────────
Implied Share Price: $243.18
Current Market Price: $217.90
Margin of Safety: 11.60% (UNDERVALUED ↑)
Implied Growth Rate: 5.14%
python dcf\_model.py --ticker NVDA --tgr 0.04 --riskfree ^FVX --market VT| Argument | Description | Default |
|---|---|---|
--ticker |
Stock ticker symbol (required) | — |
--tgr |
Terminal Growth Rate | 0.03 |
--riskfree |
Risk-free rate proxy ticker | ^TNX (US 10Y) |
--market |
Market return proxy ticker | VTI |
--json |
Export results to JSON file | None |
python compare.py --tickers AAPL MSFT GOOGL META AMZNOutputs a side-by-side comparison table with implied prices, margins of safety, and buy/hold/sell signals.
python visualize.py --ticker AAPL --saveProduces a full-page report with 4 charts saved to output/AAPL\_dcf\_report.png.
from dcf\_model import DCFModel
model = DCFModel("MSFT")
# Core valuation
print(f"Implied Price: ${model.implied\_share\_price:.2f}")
print(f"WACC: {model.wacc:.2%}")
print(f"Margin of Safety: {model.margin\_of\_safety:.2%}")
# Monte Carlo simulation
mc = model.monte\_carlo()
print(f"Monte Carlo Median: ${mc\['median']:.2f}")
print(f"P10–P90 Range: ${mc\['p10']:.0f}–${mc\['p90']:.0f}")
print(f"Probability Undervalued: {mc\['prob\_undervalued']:.1f}%")
# Scenario analysis
print(model.scenario\_analysis())
# Exit multiple valuation
em = model.exit\_multiple\_valuation()
print(f"Exit Multiple Price: ${em\['implied\_price']:.2f} ({em\['multiple']:.0f}x EV/EBITDA)")
# Sensitivity table
print(model.sensitivity\_analysis())
# Comparable company analysis (requires internet)
print(model.comparable\_analysis(\["GOOGL", "META", "AMZN"]))
# Export
model.to\_json("output/msft\_valuation.json")# Auto-detect peers by sector
python dcf\_model.py --ticker AAPL --comps
# Specify custom peers
python dcf\_model.py --ticker AAPL --comps MSFT GOOGL AMZN META---
Free Cash Flow represents the cash available to all capital providers after operating expenses and reinvestment:
Where:
- EBIT = Earnings Before Interest and Taxes
- D & A = Depreciation & Amortization (non-cash add-back)
- CapEx = Capital Expenditures (reinvestment in fixed assets)
- ΔNWC = Change in Net Working Capital
Each component is projected as a weighted-average margin of revenue, with more recent years weighted more heavily (40/30/20/10).
WACC is the blended cost of financing used as the discount rate:
Cost of Equity is derived from the Capital Asset Pricing Model (CAPM):
| Variable | Meaning | Source |
|---|---|---|
| Risk-Free Rate | US 10-Year Treasury Yield (^TNX) |
|
| Systematic risk relative to market | Yahoo Finance | |
| Expected Market Return | VTI 3-year average return | |
| Cost of Debt = Interest Expense / Total Debt | Income Statement | |
| Debt and Equity weights in capital structure | Balance Sheet + Market Cap |
Assumes the company generates free cash flow at a constant growth rate in perpetuity after the projection period:
Where
Uses mid-year convention (
Reverse-engineers the revenue growth rate the market is currently pricing in by finding
Solved iteratively using the bisection algorithm with convergence tolerance of $0.01.
Generates a matrix of implied share prices across a range of WACC and Terminal Growth Rate assumptions, enabling the analyst to assess how sensitive the valuation is to key inputs.
Randomizes key model inputs across distributions to produce a probability distribution of implied prices:
| Input | Distribution |
|---|---|
| Revenue Growth | Normal (μ = base estimate, σ = 3%) |
| EBIT Margin | Normal (μ = historical avg, σ = 2%) |
| WACC | Normal (μ = calculated, σ = 1.5%) |
| Terminal Growth Rate | Uniform (1.5% – 4.0%) |
10,000 simulations produce percentiles (P10, P25, P50, P75, P90) and the probability that the stock is undervalued.
Three cases with distinct assumptions:
| Scenario | Growth Adj | Margin Adj |
|---|---|---|
| Bull | Base + 2% | Base + 1% |
| Base | Model default | Model default |
| Bear | Base − 3% | Base − 2% |
An alternative to the Gordon Growth method:
The model auto-selects a sector-appropriate multiple (e.g., 20x for Technology, 6x for Energy) or accepts a custom input.
Automatically retrieves valuation multiples (P/E, EV/EBITDA, EV/Revenue, P/S) for peer companies and displays a comparison table. Peers are either specified manually or auto-selected by sector.
---
DCF-Valuation-Model/
├── dcf\_model.py # Core DCF model (CLI + importable class)
├── compare.py # Multi-stock comparison tool
├── visualize.py # Chart generation and visual reports
├── requirements.txt # Python dependencies
├── LICENSE # MIT License
├── .gitignore
├── output/ # Generated reports (gitignored)
└── README.md
| Data | Source |
|---|---|
| Financial Statements | Yahoo Finance via yfinance |
| Analyst Revenue Estimates | Yahoo Finance consensus |
| Risk-Free Rate | US Treasury Yields (^TNX, ^FVX) |
| Market Return | Vanguard Total Stock Market ETF (VTI) |
| Beta | Yahoo Finance |
- Analyst estimates: Revenue projections rely on Yahoo Finance consensus; these may be stale or unavailable for smaller companies. The model falls back to historical CAGR when estimates are not available.
- Margin stability: The model assumes historical margins (EBIT, D&A, CapEx) are representative of the future. This may not hold for companies undergoing transformation.
- Terminal Value dominance: In most DCFs, the Terminal Value accounts for 60–80% of the Enterprise Value. Small changes in WACC or TGR can dramatically change the output — hence the sensitivity table.
- Single-scenario: This is a deterministic model. A Monte Carlo extension would provide a probability distribution of outcomes.
- Revenue build-up by business segment (e.g., iPhone, Services, Mac)
- Regression-based beta calculation from historical returns
- ROIC and reinvestment rate consistency check
- Streamlit web dashboard for interactive analysis
- Historical DCF accuracy backtesting
- LBO model add-on
- Damodaran, A. — NYU Stern Valuation Resources
- Investopedia — DCF Analysis
- Wall Street Oasis — Terminal Value
- Financial data: Yahoo Finance