Skip to main content

Model

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>

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 bb(&self, s: f64, t: f64) -> f64

B_b(s, t).

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>

∫₀ᵗ φ = −ln P(0,t) + ½·Var(∫₀ᵗx).

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>

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>

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>

∫₀ᵗ φ_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>

The collateral currency’s Hull-White zero bond, as (A, B).

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

The FX rate on state given its drift: one on a single-currency note.

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

The collateral’s value on state, in the note’s currency.

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>

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>

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<'_, '_>

fn prepare(&self, note: &RepackNote) -> Result<Prepared, PricingError>

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>

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

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>

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

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)

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>

One path’s outcome under this model’s market, read off trajectory.

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>

Everything a run reads from the market, as bits: an input that moves none of it is not read.

Auto Trait Implementations§

§

impl<'v, 'a> !RefUnwindSafe for Model<'v, 'a>

§

impl<'v, 'a> !Send for Model<'v, 'a>

§

impl<'v, 'a> !Sync for Model<'v, 'a>

§

impl<'v, 'a> !UnwindSafe for Model<'v, 'a>

§

impl<'v, 'a> Freeze for Model<'v, 'a>

§

impl<'v, 'a> Unpin for Model<'v, 'a>

§

impl<'v, 'a> UnsafeUnpin for Model<'v, 'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.