Skip to main content

PriceIndex

Struct PriceIndex 

pub struct PriceIndex {
    pub name: String,
    pub region: String,
    pub currency: String,
    pub publication_frequency: Frequency,
    pub observation_lag_months: u32,
    pub interpolation: IndexInterpolation,
}
Expand description

A price-index (inflation) definition.

A value type carrying only conventions (region, monthly publication, observation lag, interpolation). It binds no curve; pricing supplies the inflation curve / fixings separately. See PriceIndex::reference_month and PriceIndex::observe. PartialEq compares the whole set of conventions, which is what code matches a registered index on: two price indices are the same index when they agree on every convention, not merely on a name.

Fields§

§name: String

Index name (e.g. "CPURNSA").

§region: String

Region/territory the index covers (e.g. "US").

§currency: String

ISO 4217 currency of the linked cashflows.

§publication_frequency: Frequency

Publication frequency (monthly for the standard CPIs).

§observation_lag_months: u32

Observation (availability) lag, in whole months.

§interpolation: IndexInterpolation

How a coupon date maps onto monthly prints.

Implementations§

§

impl PriceIndex

pub fn reference_month(&self, date: NaiveDate) -> NaiveDate

The first day of the lagged reference month for date: date’s month shifted back by observation_lag_months, snapped to the 1st.

§Panics

Only if date minus the lag falls outside chrono’s year range. The month is normalised with rem_euclid before use, so the day and month are always valid and only the year can leave range.

pub fn observe<R: CopyableReal<Passive = f64>, F>( &self, date: NaiveDate, lookup: F, ) -> R
where F: Fn(NaiveDate) -> R,

Resolves the index level for date from a month-keyed lookup (a price print is keyed by the first of its month), applying the observation lag and interpolation method. Month returns the lagged month’s print; Interpolated blends it with the next month by date’s day-of-month.

Generic in the AD mode: the level comes back in whatever mode lookup supplies. A passive lookup yields a passive level; a lookup reading a lifted inflation curve yields a level carrying that curve’s sensitivity. The interpolation weight is a calendar quantity and stays passive.

pub fn observation_months( &self, date: NaiveDate, lag_months: u32, ) -> (NaiveDate, Option<(NaiveDate, f64)>)

The month-keyed prints an observation at date under lag_months reads, and the weight that blends them.

(m0, None) under IndexInterpolation::Month — one print, the lagged month’s. (m0, Some((m1, w))) under IndexInterpolation::Interpolated — the lagged month’s and the next, blended by the day of the month.

Both dates are firsts of a month, which is how a price index is published and keyed. That is the whole reason this is exposed rather than kept inside observe: a caller that lags a date by whole months and then looks the result up directly asks the fixing store for, say, 11 February, finds nothing because prints are keyed on the first, and silently projects a published observation off a curve. lag_months is the caller’s rather than this index’s, because a product may be written on a lag of its own.

pub fn observation_months_under( &self, date: NaiveDate, lag_months: u32, interpolation: IndexInterpolation, ) -> (NaiveDate, Option<(NaiveDate, f64)>)

observation_months under a stated interpolation rather than this index’s own, as a product written on its own convention reads it.

pub fn reference_month_under( &self, date: NaiveDate, lag_months: u32, ) -> NaiveDate

reference_month under a stated lag rather than this index’s own.

§Panics

Only if date minus the lag falls outside chrono’s year range. The month is normalised with rem_euclid before use, so the day and month are always valid and only the year can leave range.

§

impl PriceIndex

pub fn new( name: impl Into<String>, region: impl Into<String>, currency: impl Into<String>, publication_frequency: Frequency, observation_lag_months: u32, interpolation: IndexInterpolation, ) -> Self

Builds a price index from its conventions, for a market the registry does not carry.

Registers nothing, on the same terms as IborIndex::new and OvernightIndex::new.

pub fn code(&self) -> String

The key a market stores this index’s curve under, and the spelling a linked product declares: the registry code where this index is a registered one, its name otherwise.

Unlike OvernightIndex::code, this cannot be rebuilt from the conventions. US-CPI-U is registered as cpi("CPURNSA", "US", "USD", 3, Interpolated), and no combination of those yields the code — every registered price index has a name that differs from its code. So the registry is read, by value.

By value, not by name: a constructed index that reuses a registered name while differing elsewhere is a different index, and borrowing the registered code would key its curve where a product expects the other one’s.

Reading the registry is not registering in it — the builder still adds nothing, which is the invariant the three constructors share.

Trait Implementations§

§

impl Clone for PriceIndex

§

fn clone(&self) -> PriceIndex

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 PriceIndex

§

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

Formats the value using the given formatter. Read more
§

impl Eq for PriceIndex

§

impl PartialEq for PriceIndex

§

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

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.