#939

[BUG] DCF valuation reuses old cash flows after set_assumptions changes the model

OpenBichengWangopened 6d ago

Affected Notebook/File

skills/custom_skills/creating-financial-models/dcf_model.py

Bug Description

After the first calculate_enterprise_value() call, changing assumptions with set_assumptions() leaves the old cash-flow projections cached. The next valuation uses those projections even though assumptions contains the new inputs, producing a different result from a fresh model with identical inputs.

For example, increasing the EBITDA margin from 20% to 40% leaves enterprise value at 1454.31005883673; a fresh model at 40% returns 3393.3901372857035. The reused model still projects EBITDA of 200 each year instead of 400. This requires no sensitivity or scenario analysis.

Steps to Reproduce

From the repository root at a162e0184e71b60290808a43961a6cbc8060123c, run:

import sys
sys.path.insert(0, "skills/custom_skills/creating-financial-models")
from dcf_model import DCFModel


def configure(model, margin):
    model.set_assumptions(
        projection_years=5,
        revenue_growth=[0.0] * 5,
        ebitda_margin=[margin] * 5,
        capex_percent=[0.05] * 5,
        nwc_percent=[0.10] * 5,
        terminal_growth=0.03,
    )
    model.calculate_wacc(
        risk_free_rate=0.04, beta=1.0, market_premium=0.06,
        cost_of_debt=0.05, debt_to_equity=0.0,
    )


reused = DCFModel()
configure(reused, 0.20)
reused.calculate_enterprise_value()
configure(reused, 0.40)
actual = reused.calculate_enterprise_value()["enterprise_value"]

fresh = DCFModel()
configure(fresh, 0.40)
expected = fresh.calculate_enterprise_value()["enterprise_value"]
print(actual, expected)
print(reused.projections["ebitda"], fresh.projections["ebitda"])
assert actual == expected

Error Message

The assertion fails:

1454.31005883673 3393.3901372857035
[200.0, 200.0, 200.0, 200.0, 200.0] [400.0, 400.0, 400.0, 400.0, 400.0]
AssertionError

Environment

macOS 27.0.1 arm64; Python 3.11.17; NumPy 2.4.6; pandas 3.0.6. Reproduced offline; no API calls are involved.

Calling reused.project_cash_flows() explicitly before the next valuation works around the stale projections and returns 3393.3901372857035. The setters should invalidate dependent cached calculations, or valuation should refresh projections when their inputs change.

Would you be willing to submit a PR to fix this?

No, I'm just reporting.

Activity

0

No activity yet.