pub struct ValuationContext { /* private fields */ }Expand description
When we are valuing, on which market data, and with which curves.
Implementations§
Source§impl ValuationContext
impl ValuationContext
Sourcepub fn value_position(
&self,
position: &ValuationPosition,
account_currency: &Currency,
scenario: &MarketScenario,
) -> Result<PositionValuation, ValuationContextError>
pub fn value_position( &self, position: &ValuationPosition, account_currency: &Currency, scenario: &MarketScenario, ) -> Result<PositionValuation, ValuationContextError>
Values one position under a scenario.
Sourcepub fn value_portfolio(
&self,
positions: &[ValuationPosition],
account_currency: &Currency,
scenario: &MarketScenario,
) -> Result<Valued<PortfolioValuation>, ValuationContextError>
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.
Sourcepub fn stress_portfolio(
&self,
positions: &[ValuationPosition],
account_currency: &Currency,
scenario: &MarketScenario,
) -> Result<Valued<PortfolioScenarioResult>, ValuationContextError>
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
impl ValuationContext
Sourcepub fn new(
valuation_date: Date,
as_of: i64,
data_version: impl Into<String>,
) -> Self
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.
pub fn with_discount_curve( self, currency: Currency, curve: DiscountCurve, ) -> Self
pub fn with_forward_curve(self, currency: Currency, curve: ForwardCurve) -> Self
Sourcepub fn with_volatility_surface(
self,
symbol: impl Into<String>,
surface: VolatilitySurface,
) -> Self
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.
pub fn volatility_surface( &self, symbol: &str, ) -> Result<&VolatilitySurface, ValuationContextError>
pub fn with_fx_rate(self, rate: FxRate) -> Self
pub fn valuation_date(&self) -> Date
Sourcepub fn stamp(&self) -> ValuationStamp
pub fn stamp(&self) -> ValuationStamp
The inputs this context stands for.
pub fn discount_curve( &self, currency: &Currency, ) -> Result<&DiscountCurve, ValuationContextError>
pub fn forward_curve( &self, currency: &Currency, ) -> Result<&ForwardCurve, ValuationContextError>
Sourcepub fn convert(
&self,
amount: f64,
from: &Currency,
to: &Currency,
) -> Result<f64, ValuationContextError>
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.
Sourcepub fn price_bond(
&self,
bond: &FixedRateBond,
currency: &Currency,
) -> Result<Valued<BondCurveValuation>, ValuationContextError>
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.
Sourcepub fn price_bond_shifted(
&self,
bond: &FixedRateBond,
currency: &Currency,
rate_shift: f64,
) -> Result<Valued<BondCurveValuation>, ValuationContextError>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub 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>
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
impl Clone for ValuationContext
Source§fn clone(&self) -> ValuationContext
fn clone(&self) -> ValuationContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more