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: StringIndex name (e.g. "CPURNSA").
region: StringRegion/territory the index covers (e.g. "US").
currency: StringISO 4217 currency of the linked cashflows.
publication_frequency: FrequencyPublication frequency (monthly for the standard CPIs).
observation_lag_months: u32Observation (availability) lag, in whole months.
interpolation: IndexInterpolationHow a coupon date maps onto monthly prints.
Implementations§
§impl PriceIndex
impl PriceIndex
pub fn reference_month(&self, date: NaiveDate) -> NaiveDate
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
pub fn observe<R: CopyableReal<Passive = f64>, F>( &self, date: NaiveDate, lookup: F, ) -> 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)>)
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)>)
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
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
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
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
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
impl Clone for PriceIndex
§fn clone(&self) -> PriceIndex
fn clone(&self) -> PriceIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more