DCF Valuation with Valuein SDK
Build a discounted cash flow model using SEC EDGAR fundamentals. Fetch FCF, WACC, and growth assumptions from the API, then compute intrinsic value per share.
Overview
A Discounted Cash Flow (DCF) model estimates a company's intrinsic value by projecting future free cash flows and discounting them back to present value. Valuein provides the WACC, FCF base, and growth rate assumptions via the get_valuation_metrics MCP tool, or directly via the Python SDK.
Install and Authenticate
Install the Valuein SDK and set your API token.
pip install valuein-sdk
from valuein_sdk import ValueinClient
client = ValueinClient()Fetch Valuation Inputs
Use the valuation table to get pipeline-computed WACC, FCF base, and growth rate assumptions.
from valuein_sdk import ValueinClient, ValueinError
try:
with ValueinClient() as client:
df = client.query("""
SELECT
entity_id, period_end, knowledge_at,
wacc, fcf_base, stage1_growth_rate, terminal_growth_rate,
stage1_years, shares_outstanding
FROM valuation
WHERE entity_id = '0000320193' -- AAPL CIK
ORDER BY period_end DESC
LIMIT 1
""")
row = df.iloc[0]
except ValueinError as e:
print(f"Error: {e}")Compute Intrinsic Value
Implement the two-stage DCF: high-growth phase followed by terminal value.
def dcf_two_stage(fcf, growth, wacc, terminal_growth, years, shares):
# Stage 1: explicit growth period
pv_fcfs = 0
for t in range(1, years + 1):
fcf_t = fcf * (1 + growth) ** t
pv_fcfs += fcf_t / (1 + wacc) ** t
# Stage 2: terminal value (Gordon Growth)
terminal_fcf = fcf * (1 + growth) ** years * (1 + terminal_growth)
terminal_value = terminal_fcf / (wacc - terminal_growth)
pv_terminal = terminal_value / (1 + wacc) ** years
total_equity = pv_fcfs + pv_terminal
return total_equity / shares
fcf, wacc, growth, terminal, years, shares = (
row[4], row[3], row[5], row[6], row[7], row[8]
)
intrinsic_value = dcf_two_stage(fcf, growth, wacc, terminal, years, shares)
print(f"Intrinsic value per share: ${intrinsic_value:.2f}")Point-in-Time Backtest
To avoid look-ahead bias, filter by knowledge_at when using DCF for historical analysis.
# Only use fundamentals known before 2023-01-01
from valuein_sdk import ValueinClient, ValueinError
try:
with ValueinClient() as client:
df = client.query("""
SELECT wacc, fcf_base, stage1_growth_rate, terminal_growth_rate,
stage1_years, shares_outstanding
FROM valuation
WHERE entity_id = '0000320193'
AND knowledge_at <= TIMESTAMP '2023-01-01'
ORDER BY knowledge_at DESC
LIMIT 1
""")
row = df.iloc[0]
except ValueinError as e:
print(f"Error: {e}")Up next
Factor-Based Stock Screening
Build a multi-factor stock screen using cross-sectional percentile ranks. Filter by ROE, Piotroski F-score, FCF yield, and momentum signals.