Skip to main content

PyLeg

Struct PyLeg 

pub(crate) struct PyLeg {
    inner: Leg,
    discount: CollateralSpec,
    projections: Vec<String>,
    unvalued: Option<&'static str>,
}
Expand description

A compiled leg: coupons in payment order, the side they are on, and the discount key they are valued under.

The discount key is the one thing a leg does not carry in the core, because an instrument’s collateral belongs to the instrument. Naming it here is what lets a bare leg declare what it needs and resolve a market for itself.

Fields§

§inner: Leg§discount: CollateralSpec§projections: Vec<String>

The indices the leg’s floating coupons name, in first-seen order: the first two declared as the projection and second projection, any further in the projection basket.

§unvalued: Option<&'static str>

Why this leg cannot be valued alone, for one whose value lives outside its coupons: a cross-currency leg whose notional resets on forward FX.

Implementations§

§

impl PyLeg

One of an instrument’s own legs, discounted on the key the instrument declares.

This is how a caller gets hold of a leg the engine built, rather than one they composed — and it is what makes the reproduction gate possible: the coupons a composed leg is built from can be the instrument’s own, so nothing about the leg surface has to restate a convention to be checked.

fn valued(&self) -> PyResult<()>

pub(crate) fn parts(&self) -> (&Leg, &CollateralSpec)

The core leg and the discount key it is valued under — what an instrument assembled from this leg takes as its collateral.

§

impl PyLeg

fn __eq__(&self, other: &Self) -> bool

Structural equality: the same coupons on the same side, accumulating alike, discounted on the same key.

fn new( coupons: Vec<PyAnyCoupon>, direction: Named<Direction>, discount: &str, ) -> PyResult<Self>

A leg from already-built coupons.

direction is the core’s own vocabulary — "Receive" or "Pay", with the aliases it accepts — and discount is the discount key the leg is valued under: a currency code for cash collateral in that currency, or a named curve for anything else.

fn coupons(&self) -> Vec<PyAnyCoupon>

The coupons, in payment order.

fn with_collar(&self, cap: Option<f64>, floor: Option<f64>) -> PyResult<Self>

This leg with every IBOR, overnight, CMS and year-on-year inflation coupon’s rate capped at cap and floored at floor (either may be None), and every CPI notional’s growth held within (1+floor)^τ and (1+cap)^τ, annualised from its base_date and valued off the index’s CPI vol surface. Other coupons are unchanged. A collared coupon still to fix is valued with its options off the currency’s cap vol surface — a YoY coupon’s off its price index’s YoY vol surface — which the leg then declares.

fn with_digital( &self, call: Option<(f64, Option<f64>, bool)>, put: Option<(f64, Option<f64>, bool)>, naked: bool, gap: f64, ) -> PyResult<Self>

This leg with digital options on every IBOR, overnight, CMS and year-on-year inflation coupon’s rate. Other coupons are unchanged. call and put are each (strike, payoff, long): the strike on the rate, a cash-or-nothing rate or None for asset-or-nothing, and whether the option is bought. The coupon pays its own rate as well unless naked. Still to fix, each digital is a call spread gap wide, centred on its strike, off the currency’s cap vol surface, which the leg then declares.

fn direction(&self) -> &'static str

The side this leg is on.

fn accumulation(&self) -> &'static str

How this leg’s coupons combine into what it is worth: "per_coupon" for a leg whose coupons each pay on their own date, or the zero-coupon rule the leg accumulates under.

fn pays(&self) -> Option<NaiveDate>

The single date a zero-coupon leg pays on, or None where each coupon pays on its own.

fn currency(&self) -> Option<String>

The currency the leg pays in, or None for an empty leg.

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

The market data this leg needs, as identifiers only — the same declaration, in the same shape, an instrument makes.

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

The leg’s present value against market.

The same lift-view-resolve seam an instrument’s npv walks, resolving the declaration this leg makes rather than one an instrument makes for it, with the interpreter lock released for the duration.

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

This leg’s cashflow schedule against market, as named parallel columns — the same table, with the same columns in the same order, that Instrument.cashflow_records produces for the instrument holding it.

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

This leg’s basis-point sensitivity against market: one basis point of every accruing coupon’s rate, discounted. A redemption adds nothing; a paid leg’s BPS is negative.

fn bps_by_flow(&self, py: Python<'_>, market: &PyMarket) -> PyResult<Vec<f64>>

bps flow by flow: one figure per cashflow_records row, in its order, each flow’s one basis point on its own. A redemption gives zero.

fn __len__(&self) -> usize

fn __repr__(&self) -> String

§

impl PyLeg

unsafe fn __pymethod___eq____( py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

§

impl PyLeg

unsafe extern "C" fn __pymethod___richcmp____( slf: *mut PyObject, other: *mut PyObject, op: c_int, ) -> *mut PyObject

§

impl PyLeg

fn factors(&self) -> RiskFactors<'_>

What this leg declares it is priced against: the core’s reading.

Trait Implementations§

§

impl Clone for PyLeg

§

fn clone(&self) -> PyLeg

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 PyLeg

§

impl IntoPy<Py<PyAny>> for PyLeg

§

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

Performs the conversion.
§

impl PyClass for PyLeg

§

type Frozen = True

Whether the pyclass is frozen. Read more
§

impl PyClassImpl for PyLeg

§

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

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 PyClassNewTextSignature<PyLeg> for PyClassImplCollector<PyLeg>

§

fn new_text_signature(self) -> Option<&'static str>

§

impl PyClass__eq__SlotFragment<PyLeg> for PyClassImplCollector<PyLeg>

§

unsafe fn __eq__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
§

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

§

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

§

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

§

impl PyMethods<PyLeg> for PyClassImplCollector<PyLeg>

§

fn py_methods(self) -> &'static PyClassItems

§

impl PyTypeInfo for PyLeg

§

const NAME: &'static str = "Leg"

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§

§

impl Freeze for PyLeg

§

impl RefUnwindSafe for PyLeg

§

impl Send for PyLeg

§

impl Sync for PyLeg

§

impl Unpin for PyLeg

§

impl UnsafeUnpin for PyLeg

§

impl UnwindSafe for PyLeg

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,