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.
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)
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
impl PyLeg
fn __eq__(&self, other: &Self) -> bool
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>
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>
fn coupons(&self) -> Vec<PyAnyCoupon>
The coupons, in payment order.
fn with_collar(&self, cap: Option<f64>, floor: Option<f64>) -> PyResult<Self>
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>
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 accumulation(&self) -> &'static str
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>
fn pays(&self) -> Option<NaiveDate>
The single date a zero-coupon leg pays on, or None where each coupon
pays on its own.
fn market_data_needs(&self) -> Vec<(String, String)>
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>
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>
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>
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>>
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
impl PyLeg
unsafe fn __pymethod___eq____( py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>
§impl PyLeg
impl PyLeg
unsafe extern "C" fn __pymethod___richcmp____( slf: *mut PyObject, other: *mut PyObject, op: c_int, ) -> *mut PyObject
§impl PyLeg
impl PyLeg
fn factors(&self) -> RiskFactors<'_>
fn factors(&self) -> RiskFactors<'_>
What this leg declares it is priced against: the core’s reading.
Trait Implementations§
impl DerefToPyAny for PyLeg
§impl PyClassImpl for PyLeg
impl PyClassImpl for PyLeg
§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type ThreadChecker = SendablePyClass<PyLeg>
type ThreadChecker = SendablePyClass<PyLeg>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
§impl PyClassNewTextSignature<PyLeg> for PyClassImplCollector<PyLeg>
impl PyClassNewTextSignature<PyLeg> for PyClassImplCollector<PyLeg>
fn new_text_signature(self) -> Option<&'static str>
§impl PyMethods<PyLeg> for PyClassImplCollector<PyLeg>
impl PyMethods<PyLeg> for PyClassImplCollector<PyLeg>
fn py_methods(self) -> &'static PyClassItems
§impl PyTypeInfo for PyLeg
impl PyTypeInfo for PyLeg
§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.