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>
impl<'a, R: Scalar> MarketView<'a, R>
pub fn market(&self) -> &'a MarketContext
pub fn market(&self) -> &'a MarketContext
The market this view was lifted from.
pub fn resolutions(&self) -> usize
pub fn resolutions(&self) -> usize
How many risk-factor resolutions this view has performed.
fn slice_for(&self, key: SourceRef<'_>) -> Option<&'a [R]>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>>
impl MarketView<'_, AReal<f64>>
pub fn collect_adjoints(
&self,
tape: &Tape<f64>,
) -> Result<RiskVector, RiskError>
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>
impl<'a, R: Clone + Scalar> Clone for MarketView<'a, R>
§fn clone(&self) -> MarketView<'a, R>
fn clone(&self) -> MarketView<'a, R>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more