Skip to main content

Module repack_sim

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 factor y and 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 p of the weight defaults at once; the rest continues with the intensity raised by an exponential jump of mean m. Later crises enter through the exact factor exp(−Λ_J(θ, t)), which keeps the default mass unbiased (the process is independent of the diffusion and memoryless). With repeat_crises every 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·N the note terminates and the collateral is sold liquidation_lag_days later.

Structs§

Claim 🔒
A default claim: its note-currency flows, affine in x, and its collateral-currency flows, affine in x_f and worth S each.
CrisisDraw 🔒
CrossStep 🔒
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.
GapProfileRow
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.
PathOutcome 🔒
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.
SimulatedGap
The simulated repack gap.
SimulationSettings
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·σ_S and S_t = S_0·exp(∫r_d − ∫r_f − ½σ_S²t + σ_S·W_t), so E[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×N covariance, as cholesky.
cross_covariance 🔒
The covariance of (x, y, ∫x, ∫y, x_f, ∫x_f, σ_S·W) over [s, t] given the state at s, with the means the collateral factor’s quanto drift −ρ_fS·σ_f·σ_S adds to x_f and ∫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 note by Monte Carlo against view — resolved for RepackNote::simulation_factors — under settings, 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 at s.
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.