Skip to main content

PyInstrument

Struct PyInstrument 

pub struct PyInstrument {
    pub(crate) inner: AnyInstrument,
}
Expand description

A tradable instrument.

Fields§

§inner: AnyInstrument

Implementations§

§

impl PyInstrument

pub(crate) fn product(&self) -> &'static str

The product family’s name.

pub(crate) fn __repr__(&self) -> String

pub(crate) fn engine(&self) -> Option<&'static str>

Which model prices this instrument, for the products that choose one: a European swaption’s engine (surface or hull_white) or a bond option’s (yield_vol or hull_white). None for every other product, which prices one way.

pub(crate) fn underlying(&self) -> Option<PyInstrument>

The instrument an option is written on, as an instrument of its own: a European swaption’s swap, a bond option’s bond. None for a product with no underlying.

pub(crate) fn market_data_needs(&self) -> PyResult<Vec<(String, String)>>

The market data this instrument needs, as identifiers only.

A dictionary of strings — no numbers, because a declaration carries none. Every value is the identifier’s canonical spelling, the one the vocabulary parses back to the same identifier — never debug formatting, which nothing round-trips.

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

The published fixings a valuation on valuation will read, as (index, date) pairs.

A query over the instrument’s own resets, not a valuation: it takes no market, and the date decides only which resets are already past — those are the ones a fixings store must hold, and the only ones reported, because a reset still to come is projected off a curve. Every index spelling is the canonical store key, so a reported pair goes straight into MarketContext.with_fixings unretyped. An instrument with no floating reset reports an empty list.

pub(crate) fn contract_dates(&self) -> Vec<(String, 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.

Empty for a product with no stated form: the listing names what a caller could state, not every date a product holds. final_payment_date remains the accessor for a calibration pillar.

pub(crate) fn diagnostics( &self, py: Python<'_>, market: &PyMarket, ) -> PyResult<PyObject>

What this product’s valuation resolved to on market: a bond option (yield-vol engine), a bond future option, an FX option, a CDS or a credit-linked swap, each as its own diagnostics class. Any other product raises ValueError naming diagnostics.

pub(crate) fn with_hull_white_convexity(&self) -> PyResult<Self>

This rate future with its convexity modelled under Hull-White on the market’s parameters for its currency, rather than stated — a term contract by the Hull-White convexity bias, a compounded overnight one in arrears from its first unprinted day, an averaged one print by print. Any other product raises ValueError naming it.

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

The date of the instrument’s final payment — the pillar a calibration rung on it belongs to — or None for a product no ladder is built from.

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

The latest date the instrument reads: the latest of its payment dates and of its IBOR coupons’ fixing-window ends. None for a product with no legs.

pub(crate) fn legs(&self) -> PyResult<Option<Vec<PyLeg>>>

The instrument’s legs, in the order it declares them, or None for a product that carries no coupon schedule.

Each carries the discount key this instrument declares, so a leg taken out of an instrument values on the same curve it valued on inside it. Two legs the instrument declares that a caller sums must therefore come to the instrument’s own present value, and a test asserts they do.

A cross-currency swap’s legs are on the sides the trade has them, each discounted on its own currency’s collateral, so each values to its leg_npvs row in its own currency. A resetting leg comes back for its schedule and refuses to be valued: its notionals are forward FX.

pub(crate) fn npv( &self, py: Python<'_>, market: &PyMarket, currency: Option<&str>, ) -> PyResult<f64>

The instrument’s present value against market.

The core’s AnyInstrument::npv — the passive instantiation of the same seam a book values through — with the interpreter lock released for the duration, as Book.npv releases it.

pub(crate) fn par_rate( &self, py: Python<'_>, market: &PyMarket, ) -> PyResult<f64>

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

pub(crate) fn par_spread( &self, py: Python<'_>, market: &PyMarket, ) -> PyResult<f64>

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

pub(crate) fn cashflow_records( &self, py: Python<'_>, market: &PyMarket, ) -> PyResult<PyRecords>

The instrument’s cashflow schedule against market, as named parallel columns.

One row per coupon, over the instrument’s legs in the order it declares them. It takes a market, not a curve: 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. The same lift-view-resolve seam npv walks, with the interpreter lock released for the duration.

A product carrying no leg raises rather than returning an empty table, which would be indistinguishable from a schedule whose coupons have all paid.

pub(crate) fn implied_vol( &self, py: Python<'_>, market: &PyMarket, premium: Option<f64>, ) -> PyResult<f64>

The one flat volatility under which this option or straddle, priced at it, is worth premium — or, with none given, its own value against market. An FX option, a surface-engine European swaption, or a straddle of either.

pub(crate) fn npv_ccy(&self) -> String

The currency npv is in: a cash-settled forward’s settlement currency, a cross-currency swap’s quoted leg’s whichever side is paid.

pub(crate) fn leg_npvs( &self, py: Python<'_>, market: &PyMarket, pnl_ccy: Option<&str>, ) -> PyResult<PyRecords>

A cross-currency swap’s value by leg against market, pay leg first: side, ccy, npv_local, npv_ccy, npv, pnl_ccy, npv_pnl — each leg in its own currency, in npv_ccy and in pnl_ccy (default npv_ccy), each value column summing to the swap’s value in that currency.

Trait Implementations§

§

impl Clone for PyInstrument

§

fn clone(&self) -> PyInstrument

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 DerefToPyAny for PyInstrument

§

impl IntoPy<Py<PyAny>> for PyInstrument

§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
§

impl PyClass for PyInstrument

§

type Frozen = True

Whether the pyclass is frozen. Read more
§

impl PyClassImpl for PyInstrument

§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
§

type BaseType = PyAny

Base class
§

type ThreadChecker = SendablePyClass<PyInstrument>

This handles following two situations: Read more
§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild

Immutable or mutable
§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
§

fn items_iter() -> PyClassItemsIter

§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

§

fn dict_offset() -> Option<isize>

§

fn weaklist_offset() -> Option<isize>

§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a PyInstrument

§

type Holder = Option<PyRef<'py, PyInstrument>>

§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

§

impl PyMethods<PyInstrument> for PyClassImplCollector<PyInstrument>

§

fn py_methods(self) -> &'static PyClassItems

§

impl PyTypeInfo for PyInstrument

§

const NAME: &'static str = "Instrument"

Class name.
§

const MODULE: Option<&'static str>

Module name, if any.
§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
§

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
§

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
§

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.

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.

§

impl<T> FromPyObject<'_> for T
where T: PyClass + Clone,

§

fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
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.

§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
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.
§

impl<T> Ungil for T
where T: Send,