Struct Model
struct Model<'v, 'a> {
view: &'v PricingView<'a, f64>,
as_of: NaiveDate,
hw: HullWhiteParameters<f64>,
b: f64,
eta: f64,
rho: f64,
crisis: CrisisParameters<f64>,
recovery: f64,
face: f64,
maturity: NaiveDate,
terms: ClaimTerms<f64>,
xccy: Option<Xccy>,
}Expand description
Everything deterministic a simulation reads, resolved from one view.
Fields§
§view: &'v PricingView<'a, f64>§as_of: NaiveDate§hw: HullWhiteParameters<f64>§b: f64§eta: f64§rho: f64§crisis: CrisisParameters<f64>§recovery: f64§face: f64§maturity: NaiveDate§terms: ClaimTerms<f64>§xccy: Option<Xccy>A cross-currency note’s second rate factor, correlations and FX.
Implementations§
§impl<'v, 'a> Model<'v, 'a>
impl<'v, 'a> Model<'v, 'a>
fn of( note: &RepackNote, view: &'v PricingView<'a, f64>, ) -> Result<Self, PricingError>
fn t(&self, date: NaiveDate) -> Result<f64, PricingError>
fn date_at(&self, t: f64) -> NaiveDate
fn lambda_j(&self, s: f64, t: f64) -> f64
fn lambda_j(&self, s: f64, t: f64) -> f64
Λ_J(s, t) = κ ∫_s^t [1 − (1−p)/(1 + m·B_b(u,t))] du, by 8-point
Gauss–Legendre on quarter-year panels.
fn int_phi(&self, date: NaiveDate) -> Result<f64, PricingError>
fn int_phi(&self, date: NaiveDate) -> Result<f64, PricingError>
∫₀ᵗ φ = −ln P(0,t) + ½·Var(∫₀ᵗx).
fn int_psi(&self, date: NaiveDate) -> Result<f64, PricingError>
fn int_psi(&self, date: NaiveDate) -> Result<f64, PricingError>
∫₀ᵗ ψ = −ln S_mkt(t) + ½·Var(∫₀ᵗy) + Cov(∫₀ᵗx, ∫₀ᵗy) − Λ_J(0,t).
fn zero_bond(
&self,
t_date: NaiveDate,
u: NaiveDate,
) -> Result<(f64, f64), PricingError>
fn zero_bond( &self, t_date: NaiveDate, u: NaiveDate, ) -> Result<(f64, f64), PricingError>
The Hull-White zero bond P(t,u|x) = A·e^{−B·x} as (A, B).
fn claim(&self, t_date: NaiveDate) -> Result<Claim, PricingError>
fn claim(&self, t_date: NaiveDate) -> Result<Claim, PricingError>
The claim bond at t_date: affine in x alone, or for a
cross-currency note its floating periods in x and the collateral’s
flows on the collateral currency’s zero bonds in x_f.
fn int_phi_foreign(&self, date: NaiveDate) -> Result<f64, PricingError>
fn int_phi_foreign(&self, date: NaiveDate) -> Result<f64, PricingError>
∫₀ᵗ φ_f = −ln P_f(0,t) + ½·Var(∫₀ᵗx_f), the collateral currency’s.
fn foreign_zero_bond(
&self,
t_date: NaiveDate,
u: NaiveDate,
) -> Result<(f64, f64), PricingError>
fn foreign_zero_bond( &self, t_date: NaiveDate, u: NaiveDate, ) -> Result<(f64, f64), PricingError>
The collateral currency’s Hull-White zero bond, as (A, B).
fn fx_drift(&self, date: NaiveDate) -> Result<f64, PricingError>
fn fx_drift(&self, date: NaiveDate) -> Result<f64, PricingError>
ln S_0 + ∫₀ᵗφ_d − ∫₀ᵗφ_f − ½σ_S²t: the FX rate’s log at date less
its state part; zero, and the rate one, on a single-currency note.
fn fx(&self, drift: f64, state: &State) -> f64
fn fx(&self, drift: f64, state: &State) -> f64
The FX rate on state given its drift: one on a single-currency note.
fn claim_value(claim: &Claim, state: &State, fx: f64) -> f64
fn claim_value(claim: &Claim, state: &State, fx: f64) -> f64
A claim’s value on state at the FX rate fx.
fn collateral_price(
&self,
collateral: &Vec<(f64, f64, f64, f64)>,
state: &State,
fx: f64,
) -> f64
fn collateral_price( &self, collateral: &Vec<(f64, f64, f64, f64)>, state: &State, fx: f64, ) -> f64
The collateral’s value on state, in the note’s currency.
fn survival_factor(
&self,
t_date: NaiveDate,
u: NaiveDate,
) -> Result<(f64, f64), PricingError>
fn survival_factor( &self, t_date: NaiveDate, u: NaiveDate, ) -> Result<(f64, f64), PricingError>
The issuer’s survival from t to u given the path’s y, with the
rate covariance folded in: exp(−∫_t^uψ + ½Var(∫y) + Cov(∫x,∫y) − Λ_J(t,u)) and the factor e^{−B_b(t,u)·y}, as (Q, B_y).
fn foreign_survival_factor(
&self,
t_date: NaiveDate,
u: NaiveDate,
) -> Result<(f64, f64), PricingError>
fn foreign_survival_factor( &self, t_date: NaiveDate, u: NaiveDate, ) -> Result<(f64, f64), PricingError>
survival_factor for a collateral in the
other currency, valued under its own measure: the covariance with its
own rate factor, and the intensity’s quanto drift ρ_yS·η·σ_S, which
lowers survival by exp(−ρ_yS·η·σ_S·∫_t^u B_b).
fn collateral(
&self,
t_date: NaiveDate,
) -> Result<(Vec<(f64, f64, f64, f64)>, Vec<(f64, f64, f64, f64)>), PricingError>
fn collateral( &self, t_date: NaiveDate, ) -> Result<(Vec<(f64, f64, f64, f64)>, Vec<(f64, f64, f64, f64)>), PricingError>
The collateral’s risky price at t_date on the path’s (x, y): its
flows survival-weighted, plus recovery of face over the 91-day grid
risky_value uses, each
interval’s default discounted at its midpoint.
§impl Model<'_, '_>
impl Model<'_, '_>
fn prepare(&self, note: &RepackNote) -> Result<Prepared, PricingError>
fn laws(&self, prep: &Prepared) -> Vec<StepLaw>
fn laws(&self, prep: &Prepared) -> Vec<StepLaw>
The laws of the grid’s steps under this model’s dynamics.
fn trajectory(
&self,
prep: &Prepared,
laws: &[StepLaw],
settings: &SimulationSettings,
crisis_rng: &mut Stream,
rng: &mut Stream,
) -> Result<Trajectory, PricingError>
fn trajectory( &self, prep: &Prepared, laws: &[StepLaw], settings: &SimulationSettings, crisis_rng: &mut Stream, rng: &mut Stream, ) -> Result<Trajectory, PricingError>
A path’s draws: its crises from their own stream, then the factors
stepped exactly through the grid and the crisis dates in time order.
They depend on the dynamics (a, σ, b, η, ρ, κ) and the seed alone.
fn default_gap(
&self,
claim: &Claim,
state: &State,
fx: f64,
nodes: &[(f64, f64)],
) -> f64
fn default_gap( &self, claim: &Claim, state: &State, fx: f64, nodes: &[(f64, f64)], ) -> f64
The gap of the claim at date on the state: (claim − N_f − R·N)⁺,
over the recovery’s nodes.
fn recovery_nodes(
&self,
volatility: f64,
) -> Result<Vec<(f64, f64)>, PricingError>
fn recovery_nodes( &self, volatility: f64, ) -> Result<Vec<(f64, f64)>, PricingError>
The recovery’s nodes under volatility: the market recovery alone at
zero; otherwise a beta with its mean and that standard deviation,
integrated by Gauss–Legendre over eight deviations either side of the
mean inside [0, 1], the weights normalised.
§Errors
PricingError::MalformedDeclaration for a volatility whose beta
would pile its mass at 0 or 1: either shape parameter below one.
fn survival_weight(
&self,
iy: f64,
psi: f64,
t: f64,
after: Option<f64>,
multiplier: f64,
) -> f64
fn survival_weight( &self, iy: f64, psi: f64, t: f64, after: Option<f64>, multiplier: f64, ) -> f64
The survival weight at time t on iy, given ∫₀ᵗψ, with later
crises after the first in expectation.
fn sale_gap(
&self,
claim: &Claim,
collateral: &Vec<(f64, f64, f64, f64)>,
(phi, fx_drift): (f64, f64),
at: &State,
) -> (f64, f64)
fn sale_gap( &self, claim: &Claim, collateral: &Vec<(f64, f64, f64, f64)>, (phi, fx_drift): (f64, f64), at: &State, ) -> (f64, f64)
The gap at a sale — (claim − N_f − B)⁺ — and its discount factor.
fn evaluate(
&self,
prep: &Prepared,
settings: &SimulationSettings,
trajectory: &Trajectory,
) -> Result<PathOutcome, PricingError>
fn evaluate( &self, prep: &Prepared, settings: &SimulationSettings, trajectory: &Trajectory, ) -> Result<PathOutcome, PricingError>
One path’s outcome under this model’s market, read off trajectory.
fn dynamics_key(&self) -> Vec<u64>
fn dynamics_key(&self) -> Vec<u64>
The dynamics a trajectory depends on, as bits: two models with the same key draw the same paths from one seed.
fn fingerprint(&self, prep: &Prepared) -> Vec<u64>
fn fingerprint(&self, prep: &Prepared) -> Vec<u64>
Everything a run reads from the market, as bits: an input that moves none of it is not read.