Skip to main content

FxVolSurface

Struct FxVolSurface 

pub struct FxVolSurface {
    pair: CurrencyPair,
    convention: DeltaConvention,
    reference: NaiveDate,
    expiries: Vec<NaiveDate>,
    smiles: Vec<FxVolSmile>,
    flat: Vec<f64>,
    day_count: DayCountFraction,
}
Expand description

A delta-quoted vol surface for one pair: one smile per expiry, every smile quoting the same deltas.

Fields§

§pair: CurrencyPair§convention: DeltaConvention§reference: NaiveDate§expiries: Vec<NaiveDate>§smiles: Vec<FxVolSmile>§flat: Vec<f64>

Every node vol, smile by smile — the free parameters.

§day_count: DayCountFraction

The day count the total variance σ²τ is measured in.

A vol is a quote per unit of time, so it cannot be read back without the measure it was quoted under — unlike a discount factor, which is a pure number at a date. ACT/365 fixed by default, which is what this surface measured before the measure could be stated, and what all four major FX markets quote.

Implementations§

§

impl FxVolSurface

pub fn scaled(&self, factor: f64) -> Self

This surface with every node vol multiplied by factor — a relative vol shock. Expiries, quotes, convention and day count carry over, so each smile keeps its shape.

A positive factor keeps every node positive and finite, so this cannot fail; a caller refuses a non-positive one first.

pub fn mapped(&self, f: impl Fn(f64, f64) -> f64) -> Option<Self>

This surface with each node vol replaced by f(expiry_years, vol), the expiry in years Act/365F from the surface’s reference date — a vol shock by expiry, reaching every quote of a smile. None when a node leaves (0, ∞). The smiles and the flat parameter list stay in step.

pub fn mapped_nodes( &self, f: impl Fn(f64, DeltaQuote, f64) -> f64, ) -> Option<Self>

mapped with each node’s quote as well: f(expiry_years, quote, vol) — a smile-shape shock reads the node’s side of ATM from it.

pub fn new( pair: CurrencyPair, convention: DeltaConvention, reference: NaiveDate, smiles: Vec<(NaiveDate, FxVolSmile)>, ) -> Result<Self, FxVolError>

A surface from (expiry, smile) pairs, sorted by expiry.

§Errors

FxVolError::Empty with no smiles; FxVolError::Malformed for a duplicate expiry, one on or before the reference date, or smiles that do not quote the same deltas.

pub fn with_day_count(self, day_count: DayCountFraction) -> Self

This surface with its total variance measured under day_count.

The interpolation rule is untouched: linear in σ²τ between expiries and flat in vol beyond the last is a statement about the shape of total variance, not about how τ is counted.

pub fn day_count(&self) -> DayCountFraction

The day count the total variance is measured in.

pub fn pair(&self) -> CurrencyPair

The pair the surface belongs to.

pub fn convention(&self) -> DeltaConvention

The delta convention the smiles are quoted under.

pub fn reference_date(&self) -> NaiveDate

The reference date time is measured from.

pub fn expiries(&self) -> &[NaiveDate]

The smile expiries, ascending.

pub fn quotes(&self) -> &[DeltaQuote]

The quotes every smile carries, in smile order.

pub fn smile(&self, expiry: NaiveDate) -> Option<&FxVolSmile>

The smile stored at exactly expiry, or None where the surface holds no smile on that date — a reading of what was stored, not an interpolation, which is what FxVolView::vol_at_strike does.

pub fn parameters(&self) -> &[f64]

The free parameters — every node vol, smile by smile.

pub fn parameter_keys(&self) -> Vec<(NaiveDate, DeltaQuote)>

(expiry, quote) per parameter, in parameter order.

pub fn len(&self) -> usize

How many parameters the surface holds.

pub fn is_empty(&self) -> bool

Whether the surface holds no parameters.

pub fn view<R: Scalar>(&self) -> FxVolView<'_, R>

The surface at mode R: the passive lift borrows, every active mode converts.

pub fn view_with<'a, R: Scalar>( &'a self, params: &'a [R], ) -> Result<FxVolView<'a, R>, FxVolError>

The surface over a caller’s parameter vector.

§Errors

FxVolError::ParameterCountMismatch on the wrong length.

fn tau(&self, date: NaiveDate) -> f64

fn offset(&self, k: usize) -> usize

The parameter offset of smile k.

Trait Implementations§

§

impl Clone for FxVolSurface

§

fn clone(&self) -> FxVolSurface

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 Debug for FxVolSurface

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for FxVolSurface

§

fn eq(&self, other: &FxVolSurface) -> 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 StructuralPartialEq for FxVolSurface

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> 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.