Implementation:AI4Finance Foundation FinRobot calculate dcf
| Knowledge Sources | |
|---|---|
| Domains | Finance, Valuation, Deterministic_Compute |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete deterministic engine for running a full DCF valuation (base case + sensitivity grid) from structured inputs, provided by the FinRobot compute layer.
Description
The calculate_dcf function is the flagship compute operator in FinRobot's deterministic compute engine. It takes a fully-seeded DCFInputs object (produced by seed_dcf_inputs) and performs reproducible, auditable arithmetic: it projects revenue/EBITDA/FCF year-by-year, discounts each cash flow at the correct time period, computes a Gordon-Growth terminal value, and derives equity value from enterprise value minus net debt. Every number is reproducible from the typed inputs; the LLM only selects the assumptions.
The companion calculate_sensitivity function projects FCFs once (they are WACC/TG-independent), then discounts at each (WACC, TG) combination to produce a two-dimensional sensitivity table.
Usage
- DCF_Valuation workflow: Called after seed_dcf_inputs produces a DCFInputs to compute the base-case implied price and the WACC × terminal-growth sensitivity grid.
- Equity_Research workflow (Step 4): Called as part of financial modeling; the DCF result feeds the valuation synthesis and technical analysis.
- IC_Memo workflow (Step 2): Called alongside calculate_lbo to produce both DCF and LBO returns for the investment committee memo.
- Import this when you need deterministic DCF arithmetic from a pre-seeded inputs object. The function raises ValueError for inapplicable cases (tg ≥ WACC, sub-floor Gordon spread, non-positive terminal FCF, negative equity) so the pipeline can fall back to relative valuation.
Code Reference
Source Location
- Repository: FinRobot
- File: finrobot_desktop/finrobot/engine/compute/operators/dcf.py
Signature
def calculate_dcf(
inputs: DCFInputs,
wacc_override: float | None = None,
tg_override: float | None = None,
mid_year: bool = False,
) -> DCFResult:
"""Run a full DCF valuation from structured inputs.
Args:
inputs: DCFInputs with all financial fields seeded by seed_dcf_inputs.
wacc_override: If not None, use this WACC instead of computing from
CAPM inputs (risk_free_rate, beta, ERP, cost_of_debt, tax_rate,
debt_ratio). Cost of equity is set to None in this case.
tg_override: If not None, use this terminal growth rate instead of
inputs.terminal_growth_rate.
mid_year: If True, discount cash flows at (t - 0.5) instead of t,
reflecting mid-year convention. Typically increases valuation
by 3-6%.
Returns:
DCFResult with all intermediate and final valuation numbers.
Raises:
ValueError: If terminal_growth_rate >= WACC (Gordon Growth undefined),
if WACC - tg < MIN_GORDON_SPREAD, if terminal FCF <= 0, or if
equity value <= 0 (net debt exceeds enterprise value).
"""
def calculate_sensitivity(
inputs: DCFInputs,
wacc_range: list[float],
tg_range: list[float],
mid_year: bool = False,
) -> dict[str, Any]:
"""Generate sensitivity table: implied price for each (WACC, tg) pair.
Returns None for cells where tg >= wacc or Gordon spread is below floor.
"""
Import
from finrobot.engine.compute.operators.dcf import calculate_dcf, calculate_sensitivity
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| inputs | DCFInputs | Yes | Fully seeded DCF inputs (revenue_base, margins, growth, WACC components, net_debt, shares) |
| wacc_override | float | No | Override computed WACC with a specific discount rate |
| tg_override | float | No | Override terminal growth rate from inputs |
| mid_year | bool | No | Use mid-year discounting convention (default False) |
| wacc_range | list[float] | Yes (sensitivity) | WACC values for the sensitivity grid |
| tg_range | list[float] | Yes (sensitivity) | Terminal growth values for the sensitivity grid |
Outputs
| Name | Type | Description |
|---|---|---|
| DCFResult | DCFResult | cost_of_equity, wacc, projection_years, projected_revenue/ebitda/fcf, terminal_value, pv_terminal, terminal_fcf, pv_fcf_total, enterprise_value, equity_value, implied_price, currency, inputs |
| sensitivity | dict | wacc_values, tg_values, implied_prices (2D grid with None for undefined cells) |
Usage Examples
Basic DCF Valuation
from finrobot.engine.compute.operators.dcf import calculate_dcf, calculate_sensitivity
from finrobot.engine.compute.operators.dcf_seed import seed_dcf_inputs
# 1. Seed DCF inputs from real financials + historical metrics
dcf_inputs = seed_dcf_inputs(
financials=financial_data,
historical=historical_metrics,
forward_growth=analyst_consensus_growth, # e.g. [0.12, 0.10, 0.08]
cyclical=False,
)
# 2. Run the base-case DCF
dcf_result = calculate_dcf(dcf_inputs, mid_year=True)
print(f"Implied price: ${dcf_result.implied_price:.2f}")
print(f"WACC: {dcf_result.wacc:.2%}")
print(f"Enterprise Value: ${dcf_result.enterprise_value:,.0f}")
# 3. Generate sensitivity table
sensitivity = calculate_sensitivity(
dcf_inputs,
wacc_range=[0.07, 0.08, 0.09, 0.10, 0.11],
tg_range=[0.02, 0.025, 0.03, 0.035],
mid_year=True,
)
# sensitivity["implied_prices"] is a 5x4 grid of implied prices (None for undefined)
With WACC Override
# Override WACC when you have a specific discount rate (e.g. from a separate
# WACC build) instead of using the CAPM components in DCFInputs.
result = calculate_dcf(dcf_inputs, wacc_override=0.095, tg_override=0.025)