04 — Rates & counterparty risk
P&L attribution that has to add up, and a CVA that tests its own assumption
I bootstrap a discount curve from FRED Treasury constant-maturity par yields and mark a ten-swap, $255M book from 2 to 30 years. Every par instrument reprices to under 1e-9. Daily P&L splits into carry, roll-down and level, slope and curvature moves through key-rate durations, with convexity booked as an explicit residual so the parts reconcile to a full revaluation.
I then extended it to counterparty exposure, block-bootstrapping 8,478 joint daily observations of the curve and Moody's credit spreads (1986–2026) into 20,000 thirty-year paths. Peak EPE $2.35M, peak PFE $13.5M. Wrong-way risk was priced by experiment: resampling rates and credit from the same days keeps their −0.38 correlation, resampling them from different days destroys it. The coupling is worth $89,553, 16.9% of CVA, and both runs share their curve paths bit-for-bit, so the difference cannot be Monte Carlo noise.
Scope: a Treasury curve, not SOFR fixings (ICE swap rates are licensed); one curve; a historical CVA rather than a risk-neutral desk reserve; no CSA. On a quiet day the residual is 0.9% of P&L. On April 16, 1980, when the curve fell 51–76bp, it is 9% — the honest limit of a first-order attribution.
github.com/6ixE11even/sofr-swap-pnl-attribution ↗