Skip to content

fix: correct DCF engine — FCFF/WACC consistency, smooth growth fade, mid-year convention - #3

Closed
blackswan127 wants to merge 0 commit into
masterfrom
claude/stocklens-ui-alphavintage-fallback-7tswp4
Closed

blackswan127 wants to merge 0 commit into
masterfrom
claude/stocklens-ui-alphavintage-fallback-7tswp4

Conversation

@blackswan127

Copy link
Copy Markdown
Owner

Summary

Six correctness fixes to the DCF valuation engine, covering financial accuracy, numerical stability, and code quality.

Changes

1. FCFF / WACC consistency

  • dcfService.ts: computes historicalFCFF server-side by adding back after-tax interest expense to reported (levered) FCF
  • Client DCF model now uses unlevered FCFF-derived margins, consistent with the WACC denominator that includes both equity and debt capital
  • Quarterly TTM rows correctly carry zero interest add-back when no interest data is present

2. SEC EDGAR confidence period fix

  • dcfService.ts: captures latestAnnualFCF / latestAnnualRev before TTM is appended
  • dataConfidence block now compares annual-vs-annual data, eliminating false-medium signals caused by the TTM period mismatch

3. Smooth 2-stage growth fade for any projection length

  • dcfCalculator.ts: replaces the hard-coded 5-year stage-1 cliff with adaptive split — stage1Years = min(5, ceil(N/2))
  • For a 6-year projection: stage-1 = 3 years, smooth linear fade over years 4–6 (no cliff)
  • For a 10-year projection: stage-1 = 5 years, fade over years 6–10

4. Monte Carlo initial-margin standard deviation

  • monteCarlo.ts: separates fcfMarginStdDev (initial-year dispersion) from targetFcfMarginStdDev (long-run target dispersion)
  • Fixes silent conflation that was underestimating initial margin uncertainty

5. Deduplicated projection core

  • dcfCalculator.ts: extracts runProjection(inputs, wacc, currentPrice) as a single shared function
  • computeDCF and computeDCFWithFixedWACC both delegate to it, eliminating ~80 lines of duplicated logic

6. Mid-year discounting convention

  • dcfCalculator.ts: adds optional midYearConvention?: boolean flag
  • When enabled: year-i FCF discounted at period i − 0.5; terminal value at period N − 0.5
  • Off by default to preserve all existing test values
  • UI: checkbox in the WACC card; wired into all four input objects and Monte Carlo

Tests

  • 4 new tests added: 6-year smooth fade, mid-year discounting accuracy, shared-core consistency (computeDCFWithFixedWACC matches computeDCF at the same WACC), FCFF series assertions on the DCF route
  • All 49 tests pass (vitest run)
  • npx tsc --noEmit exits 0
  • Production build succeeds (vite build)

Generated by Claude Code

@blackswan127
blackswan127 force-pushed the claude/stocklens-ui-alphavintage-fallback-7tswp4 branch from d4ff513 to 304ad05 Compare July 9, 2026 12:58

This branch was previously deployed

2 inactive deployments
courteous-happiness / production 304ad055 Deployed Jul 9, 2026 by railway-app[bot]
considerate-fascination / production 304ad055 Deployed Jul 9, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant