Discounted Cash Flow Analysis
A discounted cash flow (DCF) valuation estimates intrinsic value as the present value of future free cash flows. This chapter pulls a firm's statements, computes free cash flow, projects it forward at a historical growth rate, and discounts it back. Use the R | Python toggle to switch.
library(tidyverse)
library(tidyfinance)
library(scales)
library(fmpapi)
import pandas as pd
import numpy as np
from plotnine import *
from mizani.formatters import percent_format, comma_format
from fmpapi import fmp_get
Free cash flow from the statements
Free cash flow combines items across the income statement and balance sheet, so we download both for one firm (here Amazon). From the income statement we keep revenue, operating income, taxes, and depreciation & amortization — the building blocks of free cash flow.
symbol <- "AMZN"
income_statement <- fmp_get(
resource = "income-statement", symbol = symbol,
params = list(period = "annual", limit = 5)
) |>
select(
symbol, calendar_year, revenue, operating_income,
income_tax_expense, income_before_tax, depreciation_and_amortization
)
balance_sheet <- fmp_get(
resource = "balance-sheet-statement", symbol = symbol,
params = list(period = "annual", limit = 5)
)
symbol = "AMZN"
income_statement = fmp_get(
resource="income-statement", symbol=symbol,
params={"period": "annual", "limit": 5},
to_pandas=True
).get([
"symbol", "calendar_year", "revenue", "operating_income",
"income_tax_expense", "income_before_tax", "depreciation_and_amortization"
])
balance_sheet = fmp_get(
resource="balance-sheet-statement", symbol=symbol,
params={"period": "annual", "limit": 5},
to_pandas=True
)
Forecasting future cash flows
To project cash flows we need a growth rate. A simple, transparent choice is the compound annual growth rate (CAGR) over the observed history — the geometric average growth between the first and last year. Applying it to the latest free cash flow gives the forecast path.
cagr <- function(x) {
(x[length(x)] / x[1])^(1 / (length(x) - 1)) - 1
}
def cagr(x):
return (x.iloc[-1] / x.iloc[0])**(1 / (len(x) - 1)) - 1
Discounting
The discount rate is the weighted average cost of capital (WACC). Here it is set as a fixed input for the valuation; in practice it blends the cost of equity (e.g. from a CAPM estimate) and the after-tax cost of debt by their capital-structure weights. Discounting each projected free cash flow by (1 + wacc) raised to its horizon, and summing, gives the present value — the DCF estimate of intrinsic value. Because the answer is sensitive to both the growth rate and the WACC, it is best read as a range.
wacc <- 0.10
wacc = 0.10
Study notes following the Tidy Finance curriculum by Scheuch, Voigt, Weiss, and Frey. Prose is my own; the R/Python code is reproduced from the book's open-source source, licensed CC BY-NC-SA 4.0.