pub struct GeneralPriceIndex {
pub currency: String,
pub source: String,
pub observations: Vec<(NaiveDate, Decimal)>,
}Expand description
Time series of general-price-index (CPI) observations for a hyperinflationary economy. The index is monotonically non-decreasing in normal use; the lookup helpers tolerate out-of-order dates by sorting on access.
Fields§
§currency: StringISO 4217 currency code the index applies to (e.g. “ARS”, “TRY”). Joins to entity functional currency for lookup.
source: StringSource / methodology label (e.g. “INDEC IPC General”, “TÜİK CPI”). Carried for audit-trail purposes.
observations: Vec<(NaiveDate, Decimal)>Observed (date, index level) pairs. Index level convention:
any positive Decimal — the helpers compute relative
indexation factors (new / old), so absolute scale is free.
Implementations§
Source§impl GeneralPriceIndex
impl GeneralPriceIndex
Sourcepub fn new(currency: impl Into<String>, source: impl Into<String>) -> Self
pub fn new(currency: impl Into<String>, source: impl Into<String>) -> Self
Construct an empty index for currency from a labelled
source.
Sourcepub fn observe(&mut self, date: NaiveDate, level: Decimal) -> &mut Self
pub fn observe(&mut self, date: NaiveDate, level: Decimal) -> &mut Self
Append an observation. Caller is responsible for ordering;
Self::lookup sorts on access.
Sourcepub fn lookup(&self, date: NaiveDate) -> Option<Decimal>
pub fn lookup(&self, date: NaiveDate) -> Option<Decimal>
Look up the index level for a date. Returns the level on the
most recent observation at or before date, mirroring
the conservative IAS 29 convention of using the latest
available CPI for each measurement date. Returns None when
no observation exists at or before the date.
Sourcepub fn indexation_factor(
&self,
from_date: NaiveDate,
to_date: NaiveDate,
) -> Option<Decimal>
pub fn indexation_factor( &self, from_date: NaiveDate, to_date: NaiveDate, ) -> Option<Decimal>
Compute the IAS 29 § 12 indexation factor for restating a
historical-cost amount from from_date to to_date:
factor = index(to_date) / index(from_date)
Returns None when either lookup misses, or when the
from_date index is zero (would otherwise divide-by-zero).
Trait Implementations§
Source§impl Clone for GeneralPriceIndex
impl Clone for GeneralPriceIndex
Source§fn clone(&self) -> GeneralPriceIndex
fn clone(&self) -> GeneralPriceIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GeneralPriceIndex
impl Debug for GeneralPriceIndex
Source§impl<'de> Deserialize<'de> for GeneralPriceIndex
impl<'de> Deserialize<'de> for GeneralPriceIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for GeneralPriceIndex
impl PartialEq for GeneralPriceIndex
Source§fn eq(&self, other: &GeneralPriceIndex) -> bool
fn eq(&self, other: &GeneralPriceIndex) -> bool
self and other values to be equal, and is used by ==.