Skip to main content

RiskFactors

Struct RiskFactors 

pub struct RiskFactors<'a> {
Show 32 fields pub discount: &'a CollateralSpec, pub projection: Option<&'a str>, pub credit_entity: Option<&'a CreditCurveId>, pub security_spread: Option<&'a str>, pub needs_market_recovery: bool, pub needs_base_correlation: bool, pub hull_white: Option<Currency>, pub credit_dynamics: CreditDynamics, pub cross_currency: Option<(CurrencyPair, Currency)>, pub foreign_discount: Option<&'a CollateralSpec>, pub foreign_discount_basket: Option<&'a [CollateralSpec]>, pub fx_vol: Option<CurrencyPair>, pub swaption_vol: Option<Currency>, pub bond_yield_vol: Option<&'a str>, pub cap_vol: Option<Currency>, pub credit_vol: Option<&'a CreditCurveId>, pub yoy_vol: Option<&'a str>, pub cpi_vol: Option<&'a str>, pub repo: Option<&'a str>, pub second_projection: Option<&'a str>, pub inflation: Option<&'a str>, pub credit_basket: Option<&'a [CreditCurveId]>, pub repo_basket: Option<&'a [String]>, pub basket_correlation: Option<&'a str>, pub cms_spread_correlation: Option<(&'a str, &'a str)>, pub recovery_floor: Option<&'a CreditIndexId>, pub copula_dof: Option<&'a CreditIndexId>, pub future_price: Option<&'a ListedFutureId>, pub equity_spots: Option<&'a [String]>, pub future_option_vol: Option<&'a ListedFutureId>, pub equity_vol: Option<&'a str>, pub projection_basket: Option<&'a [String]>,
}
Expand description

What a product declares it is priced against. Identifiers only.

§It is a cache key, not a description

The type reads like a description of a product’s needs, and every one of its properties is better explained the other way round: it is the key a book deduplicates market resolution by. pricing-seam requires that a book resolve each distinct set of declared factors once per pass and price every trade declaring the same factors through that one view, and the rest follows.

PropertyBecause it is a key
Eq + Hashtwo trades declaring the same thing must compare equal
identifiers, never numbersa float is not a sane thing to compare on
no scalar, no type parameterone key serves f64, Jet1, Jet2, AReal alike, so a book resolves once and prices many ways
every string borrowedresolution allocates nothing for keys, however many trades
flat, fixed aritycomparison is a handful of pointer and slice compares, made once a trade

Note that declaration and resolution are deduplicated differently: Book::npv calls risk_factors() once a trade, and only the resolve that follows is shared across trades that declared alike.

§The shape, as it is

Eighteen fields, and they are not of equal weight. Across the crate’s product implementations four are read by nearly everything — the discount curve, the projection index, the fixings and the FX rates — and eight are read by exactly one product each: fx_vol by an FX option, swaption_vol by a swaption, credit_vol by a CDS option, bond_yield_vol by a bond option, base_correlation by a tranche, inflation by a linker, credit_basket by an nth-to-default swap, repo_basket by a bond future position, second_projection by a tenor basis swap. Reading this as a narrow shape that refuses anything unusual is the wrong model; it is a small core plus a long tail of single-tenant slots.

A product whose needs are not expressible here still reports PricingError::UnsupportedForProduct naming its own entry point, rather than a single-curve answer that would resolve the wrong data and price successfully against it.

§Two asymmetries with PricingView

The two structs mirror each other across MarketView::resolve, but not field for field, and both exceptions are deliberate:

  • security_spread has no view field. It is a modifier, not a factor: resolution composes the named spread onto the discount curve and hands the pricer one disc. A pricing body never asks whether a spread was applied, and must not — declaring one and being priced without it would be a silent mispricing, which is why the composition happens at resolution rather than in each pricer. needs_market_recovery and needs_base_correlation are flags for the same reason: what they resolve to lands inside ResolvedCredit and in base_correlation, keyed off the entity.
  • fixings and fx are declared by nobody. They are on every view, unconditionally, and appear nowhere here. Fixings and FX are ambient; everything else is declared. See PricingView::fixings for why an empty store and no store are different things.

§Growth

A later input is a new field, not a wider signature — the contract stated on PricingView, and kept across nine additions without one Priceable signature changing. What makes it safe rather than merely tidy is that every construction site — discounted_by, PricingView::passive, and the tail of resolve — is a full struct literal with no ..Default::default(). Field nineteen therefore breaks the build in each place it must be handled, instead of defaulting to None somewhere nobody looked.

The one escape from fixed arity is a slice slot, used twice (credit_basket, repo_basket). A slice of String is still Eq, Hash and borrowed, so it costs the key nothing structural — but it crosses the seam carrying no arity: neither the number of rows nor, where a slot is a flattened cascade, the stride. Only the declaring product can decode such a slot, which is why a product declaring one is responsible for checking its own correspondence before declaring it, and reports PricingError::MalformedDeclaration when it does not hold.

Fields§

§discount: &'a CollateralSpec

The discount-curve key, borrowed from the instrument like every other key here — a named collateral would otherwise cost one allocation per trade to restate a key the instrument already holds.

§projection: Option<&'a str>

The projection index’s canonical name, if the product has a floating leg.

Borrowed from the instrument that reported it, which owns the name and outlives the pricing call — cloning it would cost one allocation per trade in a book valuation to restate a name already being held.

§credit_entity: Option<&'a CreditCurveId>

The credit reference entity, if the product is a credit product.

§security_spread: Option<&'a str>

The security-spread key, if the product is an outright bond.

§needs_market_recovery: bool

Whether the product needs the entity’s market recovery to price.

§needs_base_correlation: bool

Whether the product needs a base-correlation curve to price.

§hull_white: Option<Currency>

The currency whose Hull-White parameters the product prices under, if it is valued on the short-rate lattice. Resolution reads the canonical exogenous labels (hull_white_mean_reversion_label, hull_white_sigma_label).

§credit_dynamics: CreditDynamics

Which of the credit entity’s model parameters the product reads beyond its curve: none, its Gaussian intensity, or the intensity and its crises.

§cross_currency: Option<(CurrencyPair, Currency)>

A cross-currency simulation’s pair (bond currency per note currency quoted as pair) and the bond currency, whose Hull-White factor and correlations it reads beyond hull_white’s.

§foreign_discount: Option<&'a CollateralSpec>

The discount-curve key for the other currency of an FX product — the base currency’s collateral-keyed curve, where discount is the quote currency’s. Borrowed like the first.

§foreign_discount_basket: Option<&'a [CollateralSpec]>

Discount-curve keys beyond foreign_discount, for a product whose legs discount on several collateral keys — a credit-linked swap with legs in three currencies. Borrowed like every other key; resolved key by key in this order, strictly, each as discount is. foreign_discounts walks the single key and this basket as one list.

§fx_vol: Option<CurrencyPair>

The pair whose vol surface the product prices under, if it is an option on FX.

§swaption_vol: Option<Currency>

The currency whose swaption vol surface the product prices under, if it is an option on a swap quoted off the surface.

§bond_yield_vol: Option<&'a str>

The key of the bond yield vol surface the product prices under — a currency code, or the security it names — if it is an option on a bond quoted off yield vols.

§cap_vol: Option<Currency>

The currency whose cap vol surface the product prices under, if it is a cap or floor on a term index.

§credit_vol: Option<&'a CreditCurveId>

The credit name whose vol surface the product prices under, if it is an option on a CDS.

§yoy_vol: Option<&'a str>

The price index whose year-on-year optionlet vol surface the product prices under, if it carries an option on a YoY rate.

§cpi_vol: Option<&'a str>

The price index whose zero-coupon CPI option vol surface the product prices under, if it carries an option on an index ratio.

§repo: Option<&'a str>

The repo curve a financed product carries its reference bond on, by key. Borrowed like every other key.

§second_projection: Option<&'a str>

A second projection index, for a product on two floating indices — a tenor basis swap’s base leg. Borrowed like the first.

§inflation: Option<&'a str>

The price index an inflation-linked product scales its flows by. Borrowed like every other key.

§credit_basket: Option<&'a [CreditCurveId]>

A bounded basket of credit entities, for a product on several names — an nth-to-default swap. Borrowed like every other key; resolved entity by entity in this order.

§repo_basket: Option<&'a [String]>

A bounded basket of repo keys, for a product carrying several bonds on their own carry curves — a bond future’s deliverable basket. Borrowed like every other key; resolved key by key in this order, and a key the market does not hold resolves to None rather than failing, because a repo curve’s absence is the documented fall back to the discount curve rather than a missing input.

§basket_correlation: Option<&'a str>

The market basket correlation a product reads its asset correlation from, by key — an nth-to-default basket on a market correlation.

§cms_spread_correlation: Option<(&'a str, &'a str)>

The pair of swap-index codes whose market CMS spread correlation a product reads — a CMS spread coupon on a market correlation.

§recovery_floor: Option<&'a CreditIndexId>

The credit index whose market recovery floor a product reads — a tranche on a market Amraoui–Hitier floor.

§copula_dof: Option<&'a CreditIndexId>

The credit index whose market double-t degrees of freedom a product reads — a tranche on a market copula.

§future_price: Option<&'a ListedFutureId>

The listed future whose quoted price a product reads — an option on the future. Borrowed like every other key.

§equity_spots: Option<&'a [String]>

The equities whose quoted spots a product reads, in this order — an equity TRS’s constituents. Borrowed like every other key.

§future_option_vol: Option<&'a ListedFutureId>

The listed future whose option vol surface a product reads.

§equity_vol: Option<&'a str>

The equity whose option vol surface a product reads.

§projection_basket: Option<&'a [String]>

Projection indices beyond the first two, for a product whose legs read more — a CMS swap against a stubbed leg on two further tenors. Borrowed like every other key; resolved index by index in this order, strictly.

Implementations§

§

impl RiskFactors<'_>

pub fn needs(&self) -> Vec<(String, String)>

Every input this declaration names, as (role, key) in the identifier’s canonical spelling — the one its vocabulary parses back — in one walk over every field, so a key added to the declaration is listed where it is added. A flag is listed as "true".

pub fn axes(&self) -> AxisSet

The risk axes these factors can move the value on — read off the keys, so the declaration a product already makes to be priced is the one that says what it can be risked on. A second, hand-kept statement of the same thing would be the drift products! warns about.

A superset, by design: a key that happens to contribute nothing on a given trade still names an axis the product can move on.

pub fn curves(&self) -> Vec<(RiskAxis, CurveId)>

Every curve these factors name, with the axis it is read on — what a par reading would need a ladder for.

§

impl<'a> RiskFactors<'a>

pub fn discounted_by(discount: &'a CollateralSpec) -> Self

The single-curve shape: one discount key and nothing else.

pub fn projecting_basket(self, indices: &'a [String]) -> Self

This shape with projection indices beyond the first two.

pub fn in_basket(self, credits: &'a [CreditCurveId]) -> Self

This shape with a basket of credit entities.

pub fn financed_on_basket(self, keys: &'a [String]) -> Self

This shape with a basket of repo keys, one per bond the product carries.

pub fn under_base_correlation(self) -> Self

This shape requiring the entity’s base-correlation curve.

pub fn indexed_on(self, index: &'a str) -> Self

This shape with an inflation curve, by index name.

pub fn also_projecting(self, index: &'a str) -> Self

This shape with a second projection index.

pub fn financed_on(self, repo: &'a str) -> Self

This shape with a repo curve to carry a reference bond on.

pub fn with_vol_surface(self, pair: CurrencyPair) -> Self

This shape with a pair’s vol surface.

pub fn with_swaption_vols(self, currency: Currency) -> Self

This shape with a currency’s swaption vol surface.

pub fn with_cms_spread_correlation( self, first: &'a str, second: &'a str, ) -> Self

This shape reading the market’s CMS spread correlation for the pair of swap-index codes first and second, in either order.

pub fn with_bond_yield_vols(self, key: &'a str) -> Self

This shape with the bond yield vol surface under key.

pub fn with_cap_vols(self, currency: Currency) -> Self

This shape with a currency’s cap vol surface.

pub fn with_yoy_vols(self, index: &'a str) -> Self

This shape with a price index’s year-on-year optionlet vol surface.

pub fn with_cpi_vols(self, index: &'a str) -> Self

This shape with a price index’s zero-coupon CPI option vol surface.

pub fn on_equities(self, names: &'a [String]) -> Self

This shape reading the quoted spots of the equities names.

pub fn with_equity_vols(self, name: &'a str) -> Self

This shape reading the equity name’s option vol surface.

pub fn on_listed_future(self, contract: &'a ListedFutureId) -> Self

This shape reading a listed future’s quoted price and its option vol surface — an option on the future.

pub fn with_credit_vols(self, credit: &'a CreditCurveId) -> Self

This shape with a credit name’s vol surface.

pub fn also_discounted_by(self, foreign: &'a CollateralSpec) -> Self

This shape with a second discount curve, for the other currency of an FX pair.

pub fn also_discounted_by_each(self, foreign: &'a [CollateralSpec]) -> Self

This shape with further discount curves, one per key, for a product whose legs discount on several collateral keys beyond discount.

pub fn foreign_discounts(&self) -> impl Iterator<Item = &'a CollateralSpec>

Every discount key beyond discount, in declaration order: the single foreign key where one is declared, then the basket. The compatibility reading of the pair of fields as one list.

pub fn under_hull_white(self, currency: Currency) -> Self

This shape with per-currency Hull-White model parameters.

pub fn under_cross_currency(self, pair: CurrencyPair, foreign: Currency) -> Self

This shape with a cross-currency simulation’s dynamics: the bond currency foreign’s Hull-White factor, the correlations of the pair pair with both rates and the credit, of the two rates, and of the foreign rate with the credit, and the pair’s vol surface.

pub fn under_credit_crisis(self) -> Self

This shape with the credit entity’s crisis parameters.

pub fn under_credit_intensity(self, currency: Currency) -> Self

This shape with the credit entity’s Gaussian intensity, correlated with the Hull-White factor of currency — which it also declares.

pub fn projecting(self, index: &'a str) -> Self

This shape with a projection index.

pub fn referencing(self, credit: &'a CreditCurveId) -> Self

This shape referencing a credit curve — a reference entity in a currency, or an index.

pub fn spread_by(self, key: &'a str) -> Self

This shape with a security spread over the discount curve.

Trait Implementations§

§

impl<'a> Clone for RiskFactors<'a>

§

fn clone(&self) -> RiskFactors<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> Debug for RiskFactors<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl<'a> Eq for RiskFactors<'a>

§

impl<'a> Hash for RiskFactors<'a>

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<'a> PartialEq for RiskFactors<'a>

§

fn eq(&self, other: &RiskFactors<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> StructuralPartialEq for RiskFactors<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RiskFactors<'a>

§

impl<'a> RefUnwindSafe for RiskFactors<'a>

§

impl<'a> Send for RiskFactors<'a>

§

impl<'a> Sync for RiskFactors<'a>

§

impl<'a> Unpin for RiskFactors<'a>

§

impl<'a> UnsafeUnpin for RiskFactors<'a>

§

impl<'a> UnwindSafe for RiskFactors<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.