Skip to main content

AnyInstrument

Enum AnyInstrument 

#[non_exhaustive]
pub enum AnyInstrument {
Show 52 variants Vanilla(VanillaSwap), Ois(OvernightIndexedSwap), Cds(CreditDefaultSwap), Callable(Box<CallableBond>), FxForward(FxForward), CurvePin(CurvePin), InterestRateCapFloor(Box<InterestRateCapFloor>), CmsSwap(Box<CmsSwap>), FxSwap(FxSwap), FxOption(FxOption), BondForward(Box<BondForward>), BondFuturePosition(Box<BondFuturePosition>), BondTotalReturnSwap(Box<BondTotalReturnSwap>), Repo(Box<Repo>), OpenRepo(Box<OpenRepo>), SecuritiesLoan(Box<SecuritiesLoan>), TriPartyRepo(Box<TriPartyRepo>), CrossCurrencyAssetSwap(Box<CrossCurrencyAssetSwap>), Fra(ForwardRateAgreement), Deposit(MoneyMarketDeposit), ZeroCouponBond(Box<ZeroCouponBond>), RateFuture(RateFuture), Zcs(Box<ZeroCouponSwap>), ZcInflationSwap(Box<ZeroCouponInflationSwap>), YoyInflationSwap(Box<YoyInflationSwap>), TenorBasis(Box<TenorBasisSwap>), CrossCurrency(Box<CrossCurrencySwap>), FloatingRateNote(Box<FloatingRateNote>), InflationLinkedBond(Box<InflationLinkedBond>), IndexCds(Box<IndexCreditDefaultSwap>), CreditLinkedNote(Box<CreditLinkedNote>), CreditLinkedSwap(Box<CreditLinkedSwap>), CdsOption(Box<CreditDefaultSwapOption>), CdoTranche(Box<CdoTranche>), NthToDefault(Box<NthToDefaultSwap>), EuropeanSwaption(Box<EuropeanSwaption>), BermudanSwaption(Box<BermudanSwaption>), BondOption(Box<BondOption>), PaymentInKindBond(Box<PaymentInKindBond>), AssetSwap(Box<AssetSwap>), StructuredNote(Box<StructuredNote>), YoyInflationCapFloor(Box<YoyInflationCapFloor>), ZeroCouponInflationCapFloor(Box<ZeroCouponInflationCapFloor>), BondFutureOption(Box<BondFutureOption>), RepackNote(Box<RepackNote>), CallableSwap(Box<CallableSwap>), EquityTotalReturnSwap(Box<EquityTotalReturnSwap>), EquityOption(Box<EquityOption>), Fee(Box<Fee>), Loan(Box<Loan>), CallableLoan(Box<CallableLoan>), Straddle(Box<Straddle>),
}
Expand description

The closed instrument set.

Closed for the usual reason — the pricers dispatch on it generically and a new product should be a variant the compiler makes every caller handle — and with one rule: no arm panics. An arm that cannot answer an entry point returns a typed error naming itself.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Vanilla(VanillaSwap)

A vanilla fixed-versus-IBOR swap.

§

Ois(OvernightIndexedSwap)

An overnight-indexed swap.

§

Cds(CreditDefaultSwap)

A single-name credit default swap.

§

Callable(Box<CallableBond>)

A callable (or puttable) fixed-rate bond, priced on the short-rate lattice; with an empty schedule, the bullet bond itself.

§

FxForward(FxForward)

An outright FX forward, physically or cash settled.

§

CurvePin(CurvePin)

A curve’s own reading at a date, as a calibration target.

§

InterestRateCapFloor(Box<InterestRateCapFloor>)

A strip of caplets or floorlets on a term index.

§

CmsSwap(Box<CmsSwap>)

A CMS leg — a swap index’s convexity-adjusted rate each period — against another leg.

§

FxSwap(FxSwap)

An FX swap: a near and a far forward in opposite directions.

§

FxOption(FxOption)

A European FX vanilla, priced by Garman-Kohlhagen off the pair’s surface.

§

BondForward(Box<BondForward>)

A bond forward: the reference bond carried on its repo curve against a locked strike.

§

BondFuturePosition(Box<BondFuturePosition>)

A position in a bond future: a resolved deliverable basket, margined daily, valued off the cheapest to deliver’s forward.

§

BondTotalReturnSwap(Box<BondTotalReturnSwap>)

A bond total return swap: the bond’s total return against a funding leg, carried on its repo curve.

§

Repo(Box<Repo>)

A repo, reverse repo or buy/sell-back: cash against a bond, its cash leg valued on the repo curve the collateral finances on.

§

OpenRepo(Box<OpenRepo>)

An open repo: no far date, valued each day as the repo ending on the next business day.

§

SecuritiesLoan(Box<SecuritiesLoan>)

A securities loan: a bond lent for a fee on its value, against cash at a rebate or against other securities.

§

TriPartyRepo(Box<TriPartyRepo>)

A tri-party repo: cash against a basket an agent allocates.

§

CrossCurrencyAssetSwap(Box<CrossCurrencyAssetSwap>)

A cross-currency asset swap: a bond packaged with a floating leg in another currency at a contract FX rate.

§

Fra(ForwardRateAgreement)

A forward-rate agreement.

§

Deposit(MoneyMarketDeposit)

A money-market deposit: one simple accrual, principal at both ends, self-discounting and naming no index.

§

ZeroCouponBond(Box<ZeroCouponBond>)

A zero-coupon bond: one face payment, quoted on a discount basis.

§

RateFuture(RateFuture)

A STIR futures position.

§

Zcs(Box<ZeroCouponSwap>)

A zero-coupon swap.

§

ZcInflationSwap(Box<ZeroCouponInflationSwap>)

A zero-coupon inflation swap: one payment each side at maturity.

§

YoyInflationSwap(Box<YoyInflationSwap>)

A year-on-year inflation swap: a strip of annual index ratios.

§

TenorBasis(Box<TenorBasisSwap>)

A single-currency tenor basis swap.

§

CrossCurrency(Box<CrossCurrencySwap>)

A cross-currency swap, valued in its pay currency.

§

FloatingRateNote(Box<FloatingRateNote>)

A floating-rate note.

§

InflationLinkedBond(Box<InflationLinkedBond>)

An inflation-linked bond.

§

IndexCds(Box<IndexCreditDefaultSwap>)

An index CDS on its index curve, scaled by the index factor.

§

CreditLinkedNote(Box<CreditLinkedNote>)

A credit-linked note.

§

CreditLinkedSwap(Box<CreditLinkedSwap>)

A credit-linked swap: legs tagged independent, contingent, default or recovery against one reference entity, in one currency or several.

§

CdsOption(Box<CreditDefaultSwapOption>)

A European option on a CDS, off the name’s credit vol surface.

§

CdoTranche(Box<CdoTranche>)

A synthetic CDO tranche under base correlation.

§

NthToDefault(Box<NthToDefaultSwap>)

An nth-to-default basket swap.

§

EuropeanSwaption(Box<EuropeanSwaption>)

A European swaption, off the surface or under Hull-White.

§

BermudanSwaption(Box<BermudanSwaption>)

A Bermudan swaption on the Hull-White lattice.

§

BondOption(Box<BondOption>)

A European option on a cash bond, off the yield vol surface or under Hull-White.

§

PaymentInKindBond(Box<PaymentInKindBond>)

A fixed-rate payment-in-kind bond: one accreted redemption at maturity.

§

AssetSwap(Box<AssetSwap>)

An asset swap: a bullet bond packaged with a floating spread leg.

§

StructuredNote(Box<StructuredNote>)

A note paying a leg of composed coupons and redeeming its face.

§

YoyInflationCapFloor(Box<YoyInflationCapFloor>)

A strip of year-on-year inflation caplets or floorlets.

§

ZeroCouponInflationCapFloor(Box<ZeroCouponInflationCapFloor>)

A zero-coupon inflation cap or floor: one option on an index ratio.

§

BondFutureOption(Box<BondFutureOption>)

An option on a listed bond future, off the quoted futures price and the contract’s option vol surface.

§

RepackNote(Box<RepackNote>)

A single-asset repack note: an SPV’s asset swap on a credit-risky bond, booked from the bank’s or the noteholders’ side, with its gap.

§

CallableSwap(Box<CallableSwap>)

A swap cancellable on Bermudan dates by its holder or the counterparty.

§

EquityTotalReturnSwap(Box<EquityTotalReturnSwap>)

A quantity of one equity’s total return against a funding leg.

§

EquityOption(Box<EquityOption>)

A European option on a quoted equity.

§

Fee(Box<Fee>)

A standalone fee: one known amount on a date.

§

Loan(Box<Loan>)

A fixed-rate loan: drawdown, interest and repayment.

§

CallableLoan(Box<CallableLoan>)

A fixed-rate loan the borrower may prepay or the lender demand back, on the Hull-White lattice.

§

Straddle(Box<Straddle>)

Two options of one strategy, quoted on one flat vol.

Implementations§

§

impl AnyInstrument

pub const PRODUCT_NAMES: [&'static str; 52]

Every product name product_name can return, in declaration order — what a caller resolving a name at runtime matches against.

pub fn product_name(&self) -> &'static str

A short name for the arm, for error messages that have to name a product.

§

impl AnyInstrument

pub fn axes(&self) -> Result<AxisSet, PricingError>

The risk axes this instrument’s value can move on, read off the risk factors it declares to be priced.

§Errors

PricingError where the instrument cannot state its factors.

pub fn implied_vol( &self, market: &MarketContext, premium: Option<f64>, ) -> Result<f64, PricingError>

The one flat volatility under which this option or straddle is worth premium — or, with none given, its own value — on market: a book of this one trade, read by Book::implied_vol_on.

§Errors

As Book::implied_vol_on.

pub fn currency(&self) -> Currency

The currency the instrument pays in.

pub fn final_payment_date(&self) -> Option<NaiveDate>

The date of the instrument’s final payment — the pillar a calibration rung on it belongs to — where the product has one: the last coupon of a swap’s legs, a FRA’s or future’s accrual end, a deposit’s or a zero-coupon swap’s maturity. None for products no ladder is built from.

pub fn latest_relevant_date(&self) -> Option<NaiveDate>

The latest date the instrument reads: the latest of its legs’ payment dates and of its IBOR coupons’ fixing-window ends. On indexed coupons the last fixing’s window can end past the final payment. None for a product with no legs.

pub fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>

The instrument re-struck at the par rate rate, where it carries one — see Product::restruck_at_rate.

pub fn restruck_at_spread(&self, spread: f64) -> Option<AnyInstrument>

The instrument re-struck at the basis spread spread, where it quotes one — see Product::restruck_at_spread.

§

impl AnyInstrument

pub fn legs(&self) -> Option<Vec<&Leg>>

The legs this instrument itself holds, in a declared order, or None for a product that holds none.

The distinction None draws is between a product with no coupon schedule and a schedule that happens to be empty. A matured bond has a leg whose future coupons are gone; a European FX option has no leg at all, and the two must not report the same thing.

Legs reachable through an embedded product are not returned. A bond option holds a bond, an index CDS holds a single-name CDS, a bond forward holds the bond it is struck on — and in none of those cases are the embedded product’s coupons the outer instrument’s own payments. Returning them would present a CDS’s premium schedule as a CDO tranche’s cashflows.

Note that most bonds hold no compiled leg to return: FixedRateBond carries a raw schedule, a coupon and a frequency, and materialises its flows when priced. Only the floating-rate note holds a Leg.

Each product states its own in its Product impl, where legs has no default, so a new product cannot be added without stating which it is.

pub fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>

The contract dates this instrument resolved to, as (name, date) pairs.

These are exactly the dates a stated constructor takes, so a product built through the derived form can be read back and rebuilt through the stated one — which is what makes the two forms checkable against each other rather than merely both present. A FRA lists accrual_start, accrual_end and fixing_date; a rate future accrual_start and accrual_end; a zero-coupon swap and a CDS effective and maturity; a deposit start and maturity; a vanilla or overnight swap built from dates effective and termination, the unadjusted dates its schedule was generated from.

Empty for a product with no stated form — a swap assembled from legs among them: the listing names what a caller could state, not every date a product holds. final_payment_date remains the accessor for a calibration pillar. Each product states its own in its Product impl, where contract_dates has no default.

pub fn with_hull_white_convexity(self) -> Result<Self, NotTheProduct>

This rate future with its convexity modelled under Hull-White, as RateFuture::with_hull_white_convexity; any other product is refused by name.

§Errors

NotTheProduct for any product other than a rate future.

fn refused( &self, entry_point: &'static str, wanted: &'static str, ) -> NotTheProduct

The typed refusal a product-specific reading returns for another product: the verb, the product it takes and the product it was given.

pub(crate) fn callable( &self, entry_point: &'static str, ) -> Result<&CallableBond, NotTheProduct>

The callable bond inside, or the refusal naming entry_point.

pub(crate) fn floating_rate_note( &self, entry_point: &'static str, ) -> Result<&FloatingRateNote, NotTheProduct>

The floating-rate note inside, or the refusal naming entry_point.

pub(crate) fn structured_note( &self, entry_point: &'static str, ) -> Result<&StructuredNote, NotTheProduct>

The structured note inside, or the refusal naming entry_point.

pub(crate) fn bond_total_return_swap( &self, entry_point: &'static str, ) -> Result<&BondTotalReturnSwap, NotTheProduct>

The bond total return swap inside, or the refusal naming entry_point.

pub(crate) fn repo( &self, entry_point: &'static str, ) -> Result<&Repo, NotTheProduct>

The repo inside, or the refusal naming entry_point.

pub(crate) fn payment_in_kind( &self, entry_point: &'static str, ) -> Result<&PaymentInKindBond, NotTheProduct>

The payment-in-kind bond inside, or the refusal naming entry_point.

pub(crate) fn bond_option( &self, entry_point: &'static str, ) -> Result<&BondOption, NotTheProduct>

The bond option inside, or the refusal naming entry_point.

pub(crate) fn bond_future_option( &self, entry_point: &'static str, ) -> Result<&BondFutureOption, NotTheProduct>

The bond future option inside, or the refusal naming entry_point.

pub(crate) fn zero_coupon_bond( &self, entry_point: &'static str, ) -> Result<&ZeroCouponBond, NotTheProduct>

The zero inside, or the refusal naming entry_point.

§

impl AnyInstrument

pub fn diagnostics( &self, market: &MarketContext, ) -> Result<Diagnostics, BondReadingError>

What this product’s valuation resolved to on market, for the products that state it: a bond option (yield-vol engine), a bond future option, an FX option, a CDS and a credit-linked swap.

§Errors

BondReadingError::Product naming diagnostics for any other product; otherwise BondReadingError::Pricing with whatever the valuation refuses, a bond option on the Hull-White engine among them, which has no such decomposition.

§

impl AnyInstrument

pub(crate) fn priced<T>( &self, market: &MarketContext, measure: impl FnOnce(&Self, &PricingView<'_, f64>) -> Result<T, PricingError>, ) -> Result<T, PricingError>

The passive instantiation of the seam a book values through: lift market, view it, resolve this product’s declaration, measure. Every market-level reading of one instrument goes through here, so the Python binding forwards to these methods rather than assembling the seam.

pub fn npv(&self, market: &MarketContext) -> Result<f64, PricingError>

This instrument’s present value against market.

The bare verb: it lifts and views the market itself. A caller holding a view already prices through MarketView::npv or the Priceable trait’s npv(&view).

§Errors

PricingError from the resolution or the pricer.

pub fn npv_in( &self, market: &MarketContext, currency: Currency, ) -> Result<f64, PricingError>

This instrument’s value against market in currency: npv, converted from the currency it is native to at the market’s FX rate — the rate leg_npvs converts at, from the same valuation.

§Errors

As npv, and the FX error where the market cannot price the pair.

pub fn par_rate(&self, market: &MarketContext) -> Result<f64, PricingError>

The par rate — the fixed rate, coupon or forward that values this instrument at zero against market.

§Errors

As npv.

pub fn par_spread(&self, market: &MarketContext) -> Result<f64, PricingError>

The par spread — the margin over the floating side that values this instrument at zero against market, where the product defines one.

§Errors

As npv.

pub fn cashflow_records( &self, market: &MarketContext, ) -> Result<Records, PricingError>

This instrument’s cashflow schedule against market, as named parallel columns: one row per coupon, over the legs in the order the product declares them. It takes a market, not a curve, because the projected rate, the pay-date discount factor and the present value are priced quantities and which curve fills which role is the market’s to resolve.

Whether a table exists at all is a property of the product, so it is answered before the market is asked for anything. Otherwise a product that could never have a table would first report whichever curve this market happens to lack.

§Errors

PricingError::UnsupportedForProduct for a product carrying no leg or one a table could not describe; otherwise as npv.

pub fn leg_npvs( &self, market: &MarketContext, pnl: Option<Currency>, ) -> Result<Records, PricingError>

A cross-currency swap’s value by leg against market, pay leg first: side, the leg’s ccy, npv_local in that currency, npv_ccy and npv in it, pnl_ccy and npv_pnl in it — pnl, else npv_ccy. Each converts at the market’s spot from the same valuation as npv, resets and exchanges included, so each value column sums to the swap’s value in that currency.

§Errors

PricingError::UnsupportedForProduct for any other product; otherwise as npv.

§

impl AnyInstrument

The published fixings a valuation of product on valuation will read, as (index, date) pairs in store order.

A query over the instrument’s own compiled resets, not a valuation: it takes no market, prices nothing and compiles nothing — it reads the legs the instrument already holds. It takes a valuation date because which resets are past is a function of it; there is no such thing as “the fixings this instrument needs” without one.

The report is exactly the set of prints whose absence makes the valuation refuse: every reset dated strictly before valuation — an IBOR reset already published, an overnight observation whose day is over. It is the Less arm of FixingsView::observe, which is where the pricer refuses. A reset dated valuation itself is not reported: the pricer reads it when it is published and projects it off the curve otherwise (an overnight print comes out the next morning, a term fixing may not be out when a spot-starting trade is priced), so a store without it refuses nothing. A reset still to come is projected, and reporting either would invite a caller to publish a fixing nothing needs. Nor is a reset reported once the valuation no longer values its coupon: a summing leg’s coupon paid on or before valuation, or every coupon of a non-summing leg once its single payment has been made — until then a zero-coupon leg still owes the growth of every reset behind the valuation, and they are all reported. The comparison is the same in every arm below.

Every index spelling is the canonical store key — the coupon’s own index field, which is what the pricer reads under — so a reported pair goes straight back into MarketContext.with_fixings and no key is retyped. This is the discovery half of fixing-key validation.

An instrument with no floating reset — no legs at all, or legs that carry none — reports an empty set rather than refusing: unlike a cashflow table, an empty answer here is meaningful.

pub fn fixings_needed(&self, valuation: NaiveDate) -> Vec<(String, NaiveDate)>

The published fixings a valuation of this instrument on valuation will read, as (index, date) pairs — see the module notes above.

Trait Implementations§

§

impl Clone for AnyInstrument

§

fn clone(&self) -> AnyInstrument

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 AnyInstrument

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for AnyInstrument

§

fn eq(&self, other: &AnyInstrument) -> 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<R: Scalar> Priceable<R> for AnyInstrument

§

fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

Present value against the resolved market view. Read more
§

fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

The par rate — the fixed rate at which the product is worth nothing. Read more
§

fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>

The par (breakeven) floating-leg spread. Zero for a product with no floating leg. Read more
§

impl PricingRiskFactors for AnyInstrument

§

fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>

The market data this product is priced against. Read more
§

impl StructuralPartialEq for AnyInstrument

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.