Module repack_sim
Expand description
The repack gap by Monte Carlo: crises, the valuation trigger and its lag.
The closed forms of repack_gap stop where
a diffusion stops. A valuation trigger catches an issuer that deteriorates
slowly, so with a diffusive intensity alone the gap is priced close to zero.
The exposure is a crisis: a spread jump that gaps the collateral through
the trigger, or straight into default. This module simulates it, in f64
only. Risk is a central difference on common random numbers, never AD.
- Factors. The Hull-White factor
x, the intensity factoryand both their time integrals are stepped exactly from their joint Gaussian law over each step, under the piecewise volatility term. - Default. Weighted by survival rather than drawn: each path carries
exp(−∫ψ − ∫y),ψmatching the issuer’s risky discount factors in closed form including the covariance and the compound-Poisson jump termΛ_J. - Crises. A path’s first crisis is drawn exactly. At it, the share
pof the weight defaults at once; the rest continues with the intensity raised by an exponential jump of meanm. Later crises enter through the exact factorexp(−Λ_J(θ, t)), which keeps the default mass unbiased (the process is independent of the diffusion and memoryless). Withrepeat_crisesevery crisis is simulated instead. - Trigger. On each monitoring date, and right after a crisis, the
collateral is priced in closed form on the path’s state. Below
level·Nthe note terminates and the collateral is soldliquidation_lag_dayslater.
Structs§
- Claim 🔒
- A default claim: its note-currency flows, affine in
x, and its collateral-currency flows, affine inx_fand worthSeach. - Crisis
Draw 🔒 - Cross
Step 🔒 - One step of a cross-currency note: the Cholesky factor of the innovation
covariance of
(x, y, ∫x, ∫y, x_f, ∫x_f, σ_S·W), the collateral factor’s carries, and the quanto drift’s means. - GapLegs
- The simulated charge split by what ended the note.
- GapProfile
Row - One default date’s profile.
- Model 🔒
- Everything deterministic a simulation reads, resolved from one view.
- Monitor 🔒
- A monitoring date and the sale its breach would lead to, with every bond and drift read on them.
- Path
Outcome 🔒 - What one path contributes.
- Prepared 🔒
- The simulation’s prepared dates and the bonds read on them. The grid — every date a path is read on but a crisis — depends on the note alone.
- Simulated
Gap - The simulated repack gap.
- Simulation
Settings - How a simulation runs.
- State 🔒
- A path’s state: the factors, their integrals, and its time.
- StepLaw 🔒
- One step’s exact law: the Cholesky factor of its innovation covariance and the carries of the state it starts from.
- Stream 🔒
- A path’s own stream: SplitMix64 seeded from
(seed, stream), normals by Box–Muller. The second member of an antithetic pair negates the normals and reflects the uniforms of the first. - Tally 🔒
- One scenario’s running sums over the paths.
- Trajectory 🔒
- A path’s draws read on the grid: the diffusive states, and its crises — each with the state at it and, under a trigger, at its sale.
- Xccy 🔒
- What a cross-currency note adds to the model: the collateral currency’s
Hull-White factor, the correlations, and the FX rate’s spot and
volatility (note units per collateral unit). Under the note currency’s
measure the collateral currency’s factor drifts by
−ρ_fS·σ_f·σ_SandS_t = S_0·exp(∫r_d − ∫r_f − ½σ_S²t + σ_S·W_t), soE[D_d(t)·S_t] = S_0·P_f(0,t).
Enums§
- Off 🔒
- A point a path is read on off the grid: crisis
k, or its sale.
Constants§
- CRISIS_
SALT 🔒 - The salt that keeps a path’s crisis uniforms off its normals’ stream, so the normals never move with the crisis rate.
Functions§
- cholesky 🔒
- The lower Cholesky factor of a covariance, a zero row where a variance is
exhausted (a zero volatility) rather than a
NaN. - cholesky_
n 🔒 - The lower Cholesky factor of an
N×Ncovariance, ascholesky. - cross_
covariance 🔒 - The covariance of
(x, y, ∫x, ∫y, x_f, ∫x_f, σ_S·W)over[s, t]given the state ats, with the means the collateral factor’s quanto drift−ρ_fS·σ_f·σ_Sadds tox_fand∫x_f. - e_int 🔒
∫_{v1}^{v2} e^{−k·v} dv.- evaluate 🔒
- repack_
gap_ 🔒risk_ sweep simulate_repack_gap_risk, with the inputs whose bumps stepped paths of their own.- run_
scenarios 🔒 - Runs every scenario on the same paths. Scenarios that share their dynamics share each path’s trajectory: it is stepped once per path per dynamics, and read under each scenario’s market. Returns the tallies and, per scenario, whether its trajectory was its own rather than the first scenario’s.
- simulate_
repack_ gap - The repack gap of
noteby Monte Carlo againstview— resolved forRepackNote::simulation_factors— undersettings, valuation trigger and crises included. - simulate_
repack_ gap_ risk - The simulated gap’s sensitivity to every lifted market input of
market, by a central difference of ±1e-6 through the lift, every leg on the same paths. An input the simulation does not read is reported as zero without a run; one pinned at the edge of its admissible range is differenced one-sided. - step_
covariance 🔒 - The 4×4 covariance of
(x_t, y_t, ∫_s^t x, ∫_s^t y)given the state ats. - weighted_
quantile 🔒 - The weighted
q-quantile of(weight, value)samples.
Type Aliases§
- Affine 🔒
- A claim or collateral bond at one date:
(amount, A, B_x, B_y)per flow, worthΣ amount·A·e^{−B_x·x − B_y·y}. - Sensitivities 🔒
- Each lifted input with the simulated gap’s sensitivity to it.