Python Tutorial
Financial Modelling with Python
Build DCF models, financial projections, and valuation tools in Python instead of Excel.
DCF Model
import numpy as np
# Discounted Cash Flow valuation
free_cash_flows = [50, 55, 60, 66, 72] # Projected FCF (millions)
discount_rate = 0.10 # 10% WACC
terminal_growth = 0.03 # 3% perpetual growth
# Discount each cash flow
pv_fcfs = [fcf / (1 + discount_rate)**i for i, fcf in enumerate(free_cash_flows, 1)]
# Terminal value
terminal_value = free_cash_flows[-1] * (1 + terminal_growth) / (discount_rate - terminal_growth)
pv_terminal = terminal_value / (1 + discount_rate)**len(free_cash_flows)
enterprise_value = sum(pv_fcfs) + pv_terminal
print(f"PV of Cash Flows: £{sum(pv_fcfs):.1f}M")
print(f"PV of Terminal Value: £{pv_terminal:.1f}M")
print(f"Enterprise Value: £{enterprise_value:.1f}M")Sensitivity Table
# Sensitivity analysis — how valuation changes with assumptions
wacc_range = np.arange(0.08, 0.14, 0.01)
growth_range = np.arange(0.01, 0.05, 0.01)
print(f"{'WACC →':>12}", end="")
for w in wacc_range:
print(f"{w:>8.0%}", end="")
print()
for g in growth_range:
print(f"Growth {g:.0%} ", end="")
for w in wacc_range:
tv = free_cash_flows[-1] * (1 + g) / (w - g)
pv_tv = tv / (1 + w)**5
ev = sum(fcf / (1 + w)**i for i, fcf in enumerate(free_cash_flows, 1)) + pv_tv
print(f"{ev:>8.0f}", end="")
print()