Skip to main content

MarketView

Struct MarketView 

pub struct MarketView<'a, R: Scalar> {
    market: &'a MarketContext,
    lifted: &'a LiftedMarket<R>,
    resolutions: Cell<usize>,
}
Expand description

A MarketContext resolved at one mode.

Borrows both the market and the lifted vector, so it owns nothing and costs nothing to drop. Resolving a product’s market data re-slices the same vector; it never copies a curve and never returns to the market to build one.

Fields§

§market: &'a MarketContext§lifted: &'a LiftedMarket<R>§resolutions: Cell<usize>

How many times this view has resolved a product’s risk factors — the number a book valuation keeps at one per distinct key, and the count the test that says so reads. A Cell increment costs nothing next to a resolution and needs no &mut on a view that is shared by design.

Implementations§

§

impl<'a, R: Scalar> MarketView<'a, R>

pub fn market(&self) -> &'a MarketContext

The market this view was lifted from.

pub fn resolutions(&self) -> usize

How many risk-factor resolutions this view has performed.

fn slice_for(&self, key: SourceRef<'_>) -> Option<&'a [R]>

The parameters of the input key names, as this view holds them.

A linear scan over a handful of spans comparing borrowed keys: nothing is owned to ask, and a market has few enough inputs that an index would cost more to keep than the scan.

pub fn curve(&self, id: &CurveId) -> Result<ResolvedCurve<'a, R>, PricingError>

The curve pinned under id, resolved at this mode.

§Errors

PricingError::MissingCurve naming the key if the market holds none.

fn curve_ref( &self, key: CurveIdRef<'_>, ) -> Result<ResolvedCurve<'a, R>, PricingError>

curve by borrowed key — what resolution calls, so a trade’s declared names are looked up without being copied.

fn repo_chain(&self, key: &str) -> Result<ResolvedCurve<'a, R>, PricingError>

A repo key declared over a base: walk the chain to a discount key or a whole-curve repo key, and compose every spread on the way onto it.

fn leaf_ref( &self, key: CurveIdRef<'_>, ) -> Result<ResolvedCurve<'a, R>, PricingError>

The curve stored under key alone, lifted over its own parameters.

fn stored_curve(&self, key: CurveIdRef<'_>) -> Result<&'a Curve, PricingError>

The stored curve pinned under key.

pub fn credit( &self, credit: &CreditCurveId, ) -> Result<ResolvedCredit<'a, R>, PricingError>

entity’s credit data, resolved at this mode.

§Errors

PricingError::MissingCurve naming the entity if the market holds no survival curve for it.

pub fn inflation( &self, index: &str, ) -> Result<ResolvedInflation<'a, R>, PricingError>

The inflation curve under index, lifted with this market at this mode.

§Errors

PricingError::MissingCurve naming the index if no curve is stored under it.

pub fn fx_view(&self) -> Result<FxView<'a, R>, PricingError>

The FX spots lifted with this market, viewed at this mode.

The seam book-level aggregation converts through: conversion inside the lifted mode is what puts the converted amount’s sensitivity on the FX spot’s own risk axis.

§Errors

PricingError::MarketData if the FX store rejects the substituted length.

pub fn fx_vol_view( &self, pair: CurrencyPair, ) -> Result<FxVolView<'a, R>, PricingError>

One pair’s vol surface lifted with this market, viewed at this mode.

§Errors

PricingError::MissingVolSurface if the market carries none for the pair; PricingError::MarketData if the surface rejects the substituted length.

pub fn swaption_vol_view( &self, currency: Currency, ) -> Result<RateSmileView<'a, R>, PricingError>

One currency’s swaption vol surface lifted with this market, viewed at this mode.

§Errors

PricingError::MissingSwaptionVols if the market carries none for the currency; PricingError::MarketData if the surface rejects the substituted length or carries a smile this read cannot name.

fn smile_view( &self, id: VolSurfaceIdRef<'_>, smile: RateSmileRef<'a>, axis: StrikeAxis, what: &'static str, ) -> Result<RateSmileView<'a, R>, PricingError>

A rate smile viewed at this mode: a grid checked for the strike axis its registry’s readers name, a SABR surface as it stands.

pub fn bond_yield_vol_view( &self, key: &str, ) -> Result<RateVolView<'a, R>, PricingError>

One currency’s bond yield vol surface lifted with this market, viewed at this mode.

§Errors

PricingError::MissingBondYieldVols if the market carries none for the currency; PricingError::MarketData if the surface rejects the substituted length or carries a smile this read cannot name.

pub fn cap_vol_view( &self, currency: Currency, ) -> Result<RateSmileView<'a, R>, PricingError>

The currency’s cap vol surface in this view’s mode.

§Errors

PricingError::MissingCapVols if the market carries none for the currency; PricingError::MarketData if the surface rejects the substituted length.

pub fn credit_vol_view( &self, credit: &CreditCurveId, ) -> Result<CreditVolView<'a, R>, PricingError>

The credit name’s vol surface in this view’s mode.

§Errors

PricingError::MissingCreditVols if the market carries none for the name; PricingError::MarketData if the surface rejects the substituted length.

pub fn cpi_vol_view( &self, index: &str, ) -> Result<InflationVolView<'a, R>, PricingError>

The price index’s zero-coupon CPI option vol surface in this view’s mode.

§Errors

PricingError::MissingCpiInflationVols if the market carries none for the index; PricingError::MarketData if the surface rejects the substituted length.

pub fn future_option_vol_view( &self, contract: &ListedFutureId, ) -> Result<FutureOptionVolView<'a, R>, PricingError>

The listed future’s option vol surface in this view’s mode.

§Errors

PricingError::MissingFutureOptionVols if the market carries none for the contract; PricingError::MarketData if the surface rejects the substituted length.

pub fn equity_vol_view( &self, name: &str, ) -> Result<FutureOptionVolView<'a, R>, PricingError>

The equity’s option vol surface in this view’s mode.

§Errors

PricingError::MissingEquityVols if the market carries none for the equity; PricingError::MarketData if the surface rejects the substituted length.

pub fn future_price(&self, contract: &ListedFutureId) -> Result<R, PricingError>

The listed future’s quoted price in this view’s mode.

§Errors

PricingError::MissingFuturePrice if the market quotes none for the contract.

pub fn equity_spot(&self, name: &str) -> Result<R, PricingError>

The equity’s quoted spot in this view’s mode.

§Errors

PricingError::MissingEquitySpot if the market quotes none.

pub fn yoy_vol_view( &self, index: &str, ) -> Result<InflationVolView<'a, R>, PricingError>

The price index’s YoY optionlet vol surface in this view’s mode.

§Errors

PricingError::MissingYoyInflationVols if the market carries none for the index; PricingError::MarketData if the surface rejects the substituted length.

pub fn hull_white( &self, currency: Currency, ) -> Result<HullWhiteParameters<R>, PricingError>

A currency’s Hull-White parameters at this mode, from the canonical exogenous labels: the mean reversion, and the volatility either flat under HW-{CCY}-SIGMA or as a term under one dated label per piece, HW-{CCY}-SIGMA-{date}, each date its piece’s interval end.

Pieces ending on or before the valuation date have expired and are dropped; when every piece has, the last value remains as a flat tail. Each piece is its own exogenous input, so vega arrives per piece.

§Errors

PricingError::MissingExogenous naming the label that is not pinned — the flat sigma label when neither spelling is; PricingError::AmbiguousHullWhiteSigma when both spellings are; PricingError::MalformedDeclaration naming a mean reversion that is not finite and strictly positive, or a volatility that is not finite and non-negative.

pub fn credit_crisis( &self, credit: &CreditCurveId, ) -> Result<CrisisParameters<R>, PricingError>

A credit entity’s crisis parameters at this mode, from the three canonical labels.

§Errors

PricingError::MissingExogenous naming a label that is not pinned; PricingError::MalformedDeclaration naming a label whose value is out of range — a negative rate or jump mean, a probability outside [0, 1].

pub fn credit_intensity( &self, credit: &CreditCurveId, currency: Currency, ) -> Result<GaussianIntensity<R>, PricingError>

A credit entity’s Gaussian intensity at this mode, correlated with currency’s Hull-White factor, from the three canonical labels.

§Errors

PricingError::MissingExogenous naming a label that is not pinned; PricingError::MalformedDeclaration naming a label whose value is out of range — a mean reversion that is not positive, a negative volatility, a correlation outside [−1, 1].

pub fn cross_currency_dynamics( &self, pair: CurrencyPair, domestic: Currency, foreign: Currency, credit: &CreditCurveId, ) -> Result<CrossCurrencyDynamics<R>, PricingError>

The correlations a cross-currency simulation of pair reads, the note currency domestic, the bond currency foreign and the issuer credit named, each in [−1, 1], and jointly a correlation matrix of the four factors (FX, both rates, the intensity) with the intensity’s own correlation to the note currency’s rate.

§Errors

PricingError::MissingExogenous naming a label that is not pinned; PricingError::MalformedDeclaration for a correlation outside [−1, 1] or a set that is not a correlation matrix.

pub fn resolve( &self, factors: &RiskFactors<'a>, ) -> Result<PricingView<'a, R>, PricingError>

The market data factors declares, resolved into a pricing view.

A product declares identifiers; this turns them into data at one mode. Every component is a re-slice of the one lifted vector, so resolving a hundred trades against the same market allocates no parameters at all.

§Errors

PricingError::MissingCurve naming the first key the market cannot answer, or PricingError::MarketData if the fixing or FX store rejects the substituted length.

fn resolve_declared( &self, factors: &RiskFactors<'a>, ) -> Result<PricingView<'a, R>, PricingError>

resolve’s walk, before a missing curve is told what the declaration needs.

fn tranche_marks( &self, factors: &RiskFactors<'_>, ) -> Result<(Option<R>, Option<(R, R)>), PricingError>

A tranche’s market recovery floor and double-t degrees of freedom, as declared: each read in the mode off its index’s lifted parameters, a declared one the market lacks refused by name.

pub fn pinned_input(&self, label: &str) -> Option<R>

A watched scalar at this mode.

pub fn npv<P>(&self, product: &P) -> Result<R, PricingError>

The present value of product against this market at this mode.

§Errors

PricingError from the resolution or from the pricer.

pub fn input_ids(&self) -> Vec<MarketInputId>

Every lifted market input, in lift order — the axes this view could report on.

The order matches LiftedMarket::parameters element for element, so a caller bumping parameter i knows which input it moved.

Walks MarketContext::inputs — the same enumeration that laid the vector out — rather than looking each span’s input back up by key, which is what makes the match element for element rather than by convention. A lift accepted by MarketContext::view shares this market’s layout or equals it by value, so the walk describes the lift too.

fn refusal(&self) -> Option<RiskError>

The first stored input that cannot report correct sensitivities, if any.

Asked of every lifted curve rather than only the ones a valuation touched: a ladder that silently omitted the refusing curve would be a ladder with a hole in it, and the point of the refusal is that the hole is visible.

§

impl MarketView<'_, AReal<f64>>

pub fn collect_adjoints( &self, tape: &Tape<f64>, ) -> Result<RiskVector, RiskError>

The read-back. The adjoint of every lifted market input, after a reverse sweep.

Sparse by construction: an input the valuation did not touch has a zero adjoint and produces no row. That is the difference between “this trade has no exposure here” and “this ladder forgot an axis” — the second one shows up as a missing axis rather than as a plausible-looking zero.

§Errors

RiskError::NonDifferentiable if any lifted curve refuses, and RiskError::Unlifted if a parameter reached the read-back without a tape slot, which would otherwise read as a silent zero.

Trait Implementations§

§

impl<'a, R: Clone + Scalar> Clone for MarketView<'a, R>

§

fn clone(&self) -> MarketView<'a, R>

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, R: Debug + Scalar> Debug for MarketView<'a, R>

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, R> !Freeze for MarketView<'a, R>

§

impl<'a, R> !RefUnwindSafe for MarketView<'a, R>

§

impl<'a, R> !Sync for MarketView<'a, R>

§

impl<'a, R> !UnwindSafe for MarketView<'a, R>

§

impl<'a, R> Send for MarketView<'a, R>

§

impl<'a, R> Unpin for MarketView<'a, R>

§

impl<'a, R> UnsafeUnpin for MarketView<'a, R>

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.