Skip to main content

ValuationContext

Struct ValuationContext 

Source
pub struct ValuationContext { /* private fields */ }
Expand description

When we are valuing, on which market data, and with which curves.

Implementations§

Source§

impl ValuationContext

Source

pub fn value_position( &self, position: &ValuationPosition, account_currency: &Currency, scenario: &MarketScenario, ) -> Result<PositionValuation, ValuationContextError>

Values one position under a scenario.

Source

pub fn value_portfolio( &self, positions: &[ValuationPosition], account_currency: &Currency, scenario: &MarketScenario, ) -> Result<Valued<PortfolioValuation>, ValuationContextError>

Values every position under one scenario and sums them in account currency.

Source

pub fn stress_portfolio( &self, positions: &[ValuationPosition], account_currency: &Currency, scenario: &MarketScenario, ) -> Result<Valued<PortfolioScenarioResult>, ValuationContextError>

Values the portfolio as it stands and under scenario, and measures the sensitivities by revaluing under one defined move each.

Source§

impl ValuationContext

Source

pub fn new( valuation_date: Date, as_of: i64, data_version: impl Into<String>, ) -> Self

An empty context. Curves and rates are added explicitly; nothing is assumed.

Source

pub fn with_discount_curve( self, currency: Currency, curve: DiscountCurve, ) -> Self

Source

pub fn with_forward_curve(self, currency: Currency, curve: ForwardCurve) -> Self

Source

pub fn with_volatility_surface( self, symbol: impl Into<String>, surface: VolatilitySurface, ) -> Self

Adds a volatility surface for one underlying.

Keyed by the underlying’s symbol rather than by currency: two instruments quoted in the same currency have their own smiles, and sharing one between them would be a statement about the market that nobody made.

Source

pub fn volatility_surface( &self, symbol: &str, ) -> Result<&VolatilitySurface, ValuationContextError>

Source

pub fn with_fx_rate(self, rate: FxRate) -> Self

Source

pub fn valuation_date(&self) -> Date

Source

pub fn stamp(&self) -> ValuationStamp

The inputs this context stands for.

Source

pub fn discount_curve( &self, currency: &Currency, ) -> Result<&DiscountCurve, ValuationContextError>

Source

pub fn forward_curve( &self, currency: &Currency, ) -> Result<&ForwardCurve, ValuationContextError>

Source

pub fn convert( &self, amount: f64, from: &Currency, to: &Currency, ) -> Result<f64, ValuationContextError>

Converts an amount between currencies using the rates this context holds.

Direct and inverse quotations both count; no cross rates are constructed through a third currency, because which currency to route through is a decision this crate has no basis for making.

Source

pub fn price_bond( &self, bond: &FixedRateBond, currency: &Currency, ) -> Result<Valued<BondCurveValuation>, ValuationContextError>

Present value of a bond’s outstanding cashflows on the currency’s discount curve.

This is the curve-based counterpart to FixedRateBond::price, which discounts at a single yield. Accrued interest is the same figure in both — it comes from the schedule, not from the discounting.

Source

pub fn price_bond_shifted( &self, bond: &FixedRateBond, currency: &Currency, rate_shift: f64, ) -> Result<Valued<BondCurveValuation>, ValuationContextError>

ValuationContext::price_bond with every zero rate shifted in parallel by rate_shift (absolute rate units). The scenario machinery in portfolio uses this; a shift of zero is the unshocked case.

Source

pub fn price_european_option( &self, currency: &Currency, option_type: OptionType, spot: f64, strike: f64, expiry: Date, volatility: f64, dividend_yield: f64, ) -> Result<Valued<OptionPricingResult>, ValuationContextError>

Prices a European option, taking the interest rate from the currency’s discount curve.

The rate used is the zero rate to expiry. For a European option that is not an approximation: only the discount factor to expiry and the forward enter the formula, and both follow from that single rate.

Volatility and dividend yield are passed in rather than read from the context: a volatility surface over strike and maturity is not modelled yet, and inventing a flat one here would hide that.

Source

pub fn price_european_option_on_surface( &self, symbol: &str, currency: &Currency, option_type: OptionType, spot: f64, strike: f64, expiry: Date, dividend_yield: f64, ) -> Result<Valued<OptionPricingResult>, ValuationContextError>

Prices a European option taking both the rate and the volatility from the context: the rate from the currency’s discount curve, the volatility from the underlying’s surface at this option’s own strike and expiry.

The surface is what makes this different from ValuationContext::price_european_option, which takes a volatility from the caller. A strike or expiry outside the surface’s declared validity fails here rather than being answered with the nearest quoted value.

Source

pub fn price_european_option_shifted( &self, currency: &Currency, option_type: OptionType, spot: f64, strike: f64, expiry: Date, volatility: f64, dividend_yield: f64, rate_shift: f64, ) -> Result<Valued<OptionPricingResult>, ValuationContextError>

ValuationContext::price_european_option with the curve shifted in parallel by rate_shift (absolute rate units).

Trait Implementations§

Source§

impl Clone for ValuationContext

Source§

fn clone(&self) -> ValuationContext

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
Source§

impl Debug for ValuationContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ValuationContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ValuationContext

Source§

fn eq(&self, other: &ValuationContext) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for ValuationContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ValuationContext

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.