diff --git a/web/src/padelnomics/planner/calculator.py b/web/src/padelnomics/planner/calculator.py index 96e75c2..3608268 100644 --- a/web/src/padelnomics/planner/calculator.py +++ b/web/src/padelnomics/planner/calculator.py @@ -85,6 +85,9 @@ DEFAULTS = { "holdYears": 5, "exitMultiple": 6, "annualRevGrowth": 2, + "annualOpexGrowth": 2, + "hurdleRate": 12, + "interestOnlyMonths": 0, "budgetTarget": 0, "country": "DE", "permitsCompliance": 12000, @@ -336,6 +339,9 @@ def calc(s: dict, lang: str = "en") -> dict: d["netCFMonth"] = d["ebitdaMonth"] - d["monthlyPayment"] # -- 60-month cash flow projection -- + # Fix 1: annualRevGrowth applied to all revenue streams. + # Fix 8: annualOpexGrowth applied to all operating costs (utilities, staff, insurance inflate). + # Fix 10: interest-only period — first N months pay only interest, not P+I. months: list[dict] = [] for m in range(1, 61): cm = (m - 1) % 12 @@ -345,19 +351,32 @@ def calc(s: dict, lang: str = "en") -> dict: eff_util = (s["utilTarget"] / 100) * ramp * seas avail = s["hoursPerDay"] * dpm * total_courts if seas > 0 else 0 booked = avail * eff_util - court_rev = booked * w_rate + + # Revenue growth compounds from Year 2 onwards (Year 1 = base) + rev_growth = math.pow(1 + s["annualRevGrowth"] / 100, max(0, yr - 1)) + court_rev = booked * w_rate * rev_growth fees = -court_rev * (s["bookingFee"] / 100) ancillary = booked * ( (s["racketRentalRate"] / 100) * s["racketQty"] * s["racketPrice"] + (s["ballRate"] / 100) * (s["ballPrice"] - s["ballCost"]) - ) - membership = total_courts * s["membershipRevPerCourt"] * (ramp if seas > 0 else 0) - fb = total_courts * s["fbRevPerCourt"] * (ramp if seas > 0 else 0) - coaching = total_courts * s["coachingRevPerCourt"] * (ramp if seas > 0 else 0) - retail = total_courts * s["retailRevPerCourt"] * (ramp if seas > 0 else 0) + ) * rev_growth + membership = total_courts * s["membershipRevPerCourt"] * (ramp if seas > 0 else 0) * rev_growth + fb = total_courts * s["fbRevPerCourt"] * (ramp if seas > 0 else 0) * rev_growth + coaching = total_courts * s["coachingRevPerCourt"] * (ramp if seas > 0 else 0) * rev_growth + retail = total_courts * s["retailRevPerCourt"] * (ramp if seas > 0 else 0) * rev_growth total_rev = court_rev + fees + ancillary + membership + fb + coaching + retail - opex_val = -d["opex"] - loan = -d["monthlyPayment"] + + # OPEX inflates from Year 2 onwards (utilities, staff, insurance) + opex_growth = math.pow(1 + s["annualOpexGrowth"] / 100, max(0, yr - 1)) + opex_val = -(d["opex"] * opex_growth) + + # Fix 10: interest-only period — lower debt service during construction/ramp + if m <= s["interestOnlyMonths"] and d["loanAmount"] > 0: + # Interest-only payment: loan balance × monthly rate + loan = -(d["loanAmount"] * s["interestRate"] / 100 / 12) + else: + loan = -d["monthlyPayment"] + ebitda = total_rev + opex_val ncf = ebitda + loan prev = months[-1] if months else None @@ -387,29 +406,95 @@ def calc(s: dict, lang: str = "en") -> dict: d["annuals"] = annuals # -- Returns & exit -- - y3_ebitda = annuals[2]["ebitda"] if len(annuals) >= 3 else 0 - d["stabEbitda"] = y3_ebitda - d["exitValue"] = y3_ebitda * s["exitMultiple"] - d["remainingLoan"] = d["loanAmount"] * max(0, 1 - s["holdYears"] / (max(s["loanTerm"], 1) * 1.5)) + # Fix 5: use terminal year EBITDA (exit year), not hardcoded Year 3 + exit_yr_idx = min(s["holdYears"] - 1, len(annuals) - 1) + d["stabEbitda"] = annuals[exit_yr_idx]["ebitda"] + d["exitValue"] = d["stabEbitda"] * s["exitMultiple"] + + # Fix 4: remaining loan via amortization math (PV of remaining payments), + # replacing the heuristic loanAmount * max(0, 1 - holdYears / (loanTerm * 1.5)) + k = s["holdYears"] * 12 # number of P+I payments made (after interest-only period) + n = max(s["loanTerm"], 1) * 12 + r_monthly_loan = s["interestRate"] / 100 / 12 + if r_monthly_loan > 0 and d["loanAmount"] > 0 and n > k: + d["remainingLoan"] = _round( + d["monthlyPayment"] * (1 - math.pow(1 + r_monthly_loan, -(n - k))) / r_monthly_loan + ) + elif d["loanAmount"] > 0 and n > k: + # Zero-interest loan: straight-line amortization + d["remainingLoan"] = _round(d["loanAmount"] * (n - k) / n) + else: + d["remainingLoan"] = 0 + d["netExit"] = d["exitValue"] - d["remainingLoan"] - irr_cfs = [-d["capex"]] + # Fix 2: equity IRR — use equity invested as initial outflow (not full capex). + # NCFs are already post-debt-service (levered), so the denominator must match. + # Using capex here would produce a hybrid metric that's neither equity IRR + # nor project IRR — it systematically understates returns for leveraged deals. + irr_cfs = [-d["equity"]] for y in range(s["holdYears"]): ycf = annuals[y]["ncf"] if y < len(annuals) else (annuals[-1]["ncf"] if annuals else 0) if y == s["holdYears"] - 1: irr_cfs.append(ycf + d["netExit"]) else: irr_cfs.append(ycf) - d["irr"] = calc_irr(irr_cfs) + + # Project IRR (unlevered): uses full capex as outflow and EBITDA as cash flows. + # Useful for lender analysis and comparing across capital structures. + unlevered_cfs = [-d["capex"]] + for y in range(s["holdYears"]): + ya = annuals[y] if y < len(annuals) else annuals[-1] + if y == s["holdYears"] - 1: + unlevered_cfs.append(ya["ebitda"] + d["netExit"]) + else: + unlevered_cfs.append(ya["ebitda"]) + d["projectIrr"] = calc_irr(unlevered_cfs) + + # Fix 3: NPV at hurdle rate (discounts equity NCFs + exit at hurdleRate) + r_hurdle_monthly = math.pow(1 + s["hurdleRate"] / 100, 1 / 12) - 1 + pv_ncf = sum(m["ncf"] / math.pow(1 + r_hurdle_monthly, m["m"]) for m in months) + pv_exit = d["netExit"] / math.pow(1 + s["hurdleRate"] / 100, s["holdYears"]) + d["npv"] = _round(-d["equity"] + pv_ncf + pv_exit) + d["npvPositive"] = d["npv"] >= 0 + d["totalReturned"] = sum(irr_cfs[1:]) - d["moic"] = d["totalReturned"] / d["capex"] if d["capex"] > 0 else 0 + + # Fix 6: leveraged MOIC (equity cash flows / equity invested — what the investor earns). + # Also keep project MOIC (total returns / capex) for reference. + equity_cfs = irr_cfs[1:] + d["moic"] = sum(equity_cfs) / d["equity"] if d["equity"] > 0 else 0 + d["projectMoic"] = d["totalReturned"] / d["capex"] if d["capex"] > 0 else 0 + + # Fix 7: return decomposition / value bridge (PE-style attribution). + # Shows what drove equity returns: operational improvement vs. financial leverage. + entry_ebitda = annuals[0]["ebitda"] if annuals else 0 + ebitda_growth_value = (d["stabEbitda"] - entry_ebitda) * s["exitMultiple"] + deleverage_value = d["loanAmount"] - d["remainingLoan"] + d["valueDrivers"] = { + "ebitda_growth": _round(ebitda_growth_value), + "deleverage": _round(deleverage_value), + "entry_equity": d["equity"], + "exit_equity": _round(d["netExit"]), + } d["dscr"] = [ {"year": a["year"], "dscr": a["ebitda"] / a["ds"] if a["ds"] > 0 else 999} for a in annuals ] + # Fix 9: LTV and DSCR warnings for lender compliance thresholds + d["ltvWarning"] = d["ltv"] > 0.75 # above typical commercial RE lending limit + d["dscrWarning"] = any(row["dscr"] < 1.25 for row in d["dscr"] if row["dscr"] < 999) + d["dscrMinYear"] = None + if d["dscrWarning"]: + d["dscrMinYear"] = min( + (row["year"] for row in d["dscr"] if row["dscr"] < 999), + key=lambda yr: next(r["dscr"] for r in d["dscr"] if r["year"] == yr), + default=None, + ) + payback_idx = -1 for i, m in enumerate(months): if m["cum"] >= 0: diff --git a/web/src/padelnomics/planner/templates/partials/tab_metrics.html b/web/src/padelnomics/planner/templates/partials/tab_metrics.html index ef3749e..6d7f995 100644 --- a/web/src/padelnomics/planner/templates/partials/tab_metrics.html +++ b/web/src/padelnomics/planner/templates/partials/tab_metrics.html @@ -61,11 +61,17 @@