Chapter 10 Laboratory — Module 10: The Control Room¶

Mathematical Foundations of Modern Finance · Part III · Week 10

Four panels: the Bellman recursion, the HJB verification panel, the spending surface, and the optimal-execution frontier. A candidate policy's performance bleeds at its HJB deficit and flatlines exactly at the optimum.

Seeds: 20261001–20261004.

In [1]:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({"figure.figsize": (7, 4.2), "axes.grid": True,
                     "grid.alpha": 0.3, "font.size": 11})
BRASS, INK = "#B4884A", "#0F1E3D"
import mfmf_engine_ch10 as eng

E1 — The Bellman recursion (supports LOS 10.2)¶

Solve a three-date, two-action consumption toy by backward induction. Value propagates backward and the argmax policy paints itself state by state.

In [2]:
r1 = eng.E1_bellman()
print(f"V0 at wealth 100 : {r1['V0_at_100']:.4f}")
print(f"Policy at t=0    : {r1['policy_t0']}")
print(f"Value monotone in wealth: {r1['recursion_monotone']}")
V0 at wealth 100 : 13.9551
Policy at t=0    : {'50.0': 0.6, '100.0': 0.6, '150.0': 0.6, '200.0': 0.6}
Value monotone in wealth: True

E2 — Verification and the HJB deficit (supports LOS 10.3–10.4)¶

Enter a candidate policy and watch its performance-process mean bleed at its HJB deficit. The optimum is the unique flat line.

In [3]:
r2 = eng.E2_verification()
print(f"Optimal weight w*   : {r2['w_opt']:.4f}")
print(f"Optimal spending nu*: {r2['nu_opt']:.4f}")
print("Bleed rates by policy:")
for name, b in r2['bleed_rates'].items():
    print(f"   {name:16s}: {b:+.5f}")
print(f"Optimal is flat: {r2['optimal_is_flat']}")
Optimal weight w*   : 0.5224
Optimal spending nu*: 0.0392
Bleed rates by policy:
   pi=120%,c=8%    : -0.03532
   pi=60%,c=4.5%   : -0.00062
   optimal         : -0.00000
Optimal is flat: True

E3 — The spending surface (supports LOS 10.5)¶

Locate Meridian on the $(\gamma, \rho) \mapsto \nu^\*$ surface: the optimal spend rate at $(\gamma, \rho) = (2, 5\%)$, and the impatience $\rho$ a 4.5% rule implies.

In [4]:
r3 = eng.E3_spending_surface()
print(f"nu* at (gamma, rho) = (2, 5%) : {r3['nu_star_at_2_5pct']:.4f}")
print(f"Implied rho of the 4.5% rule  : {r3['implied_rho_of_4.5pct_rule']:.4f}")
nu* at (gamma, rho) = (2, 5%) : 0.0392
Implied rho of the 4.5% rule  : 0.0616

E4 — Optimal execution (supports LOS 10.6)¶

The transition-desk simulator trades a $600M position over the day. Higher risk aversion $\kappa$ front-loads the schedule, trading expected cost against variance.

In [5]:
r4 = eng.E4_execution()
print(f"Transition size: ${r4['X0']:.0f}M")
for k, d in r4['frontier'].items():
    print(f"   kappa = {k}: expected cost {d['exp_cost']:.2f}, risk {d['risk']:.2f}")
Transition size: $600M
   kappa = 0.05: expected cost 3600.00, risk 2.22
   kappa = 0.2: expected cost 3600.01, risk 8.88
   kappa = 0.4: expected cost 3600.02, risk 17.74

Validation checks¶

Every laboratory report must reproduce these; a report whose checks do not pass is returned ungraded.

In [6]:
checks = eng.validation_checks()
for k, v in checks.items():
    if k.startswith("_"): continue
    print(f"[{'PASS' if v else 'FAIL'}] {k}")
assert checks["ALL_PASS"], "Validation failed — do not submit."
print("\nAll Module validation checks pass.")
[PASS] V1_bellman_monotone
[PASS] V2_optimal_is_flat
[PASS] V3_suboptimal_bleeds
[PASS] V4_spending_positive
[PASS] ALL_PASS

All Module validation checks pass.