Skip to main content

FixingHistory

Struct FixingHistory 

pub struct FixingHistory {
    prints: BTreeMap<(String, NaiveDate), Vec<Version>>,
}
Expand description

Every print a market has seen, each with the date it was known on.

A store answers one value per (index, date); a history keeps every version, so a restatement learnt later sits beside the value learnt first rather than in its place. A version learnt by a fetch is known on the fetch’s date; a version pinned by hand is known from the market’s date when it was pinned, or the print’s own date where that is later. What a market at a date reads is as_known_on that date: the latest pin known by then, else the latest fetched version.

Fields§

§prints: BTreeMap<(String, NaiveDate), Vec<Version>>

(index, date) to its versions, ascending by knowledge date.

Implementations§

§

impl FixingHistory

pub fn new() -> Self

An empty history.

fn insert( &mut self, index: &str, date: NaiveDate, known: NaiveDate, pinned: bool, value: f64, )

Inserts one version, keeping the versions in knowledge order; a version already held with the same knowledge date and kind is replaced.

fn pick(versions: &[Version], on: NaiveDate) -> Option<Version>

The version a market at on reads: the latest pin known by on, else the latest fetched version known by on.

fn visible( &self, index: &str, date: NaiveDate, on: NaiveDate, ) -> Option<Version>

The version of (index, date) a market at on reads, for a print dated on or before it.

pub fn as_known_on(&self, on: NaiveDate) -> FixingStore

What a market at on has seen: per print dated on or before on, the version it reads.

pub fn learnt_before(&self, index: &str, date: NaiveDate, on: NaiveDate) -> bool

Whether the version of (index, date) a market at on reads was learnt by a fetch on an earlier date — a value that may since have been restated, and so one a fetch at on asks again. A pin is never asked again.

fn pinned_on(date: NaiveDate, at: Option<NaiveDate>) -> NaiveDate

When a pin of a print dated date is known: the market’s date at, or the print’s own date where that is later or the market is undated.

pub fn with_pinned(self, store: FixingStore, at: Option<NaiveDate>) -> Self

This history with its prints pinned by hand replaced by store’s, pinned at the market date at; versions a fetch returned are kept.

store decides which prints are pinned, not what earlier dates knew: a print it pins again keeps its pins known before the new one, and a value equal to the one pinned by then adds no version — so pinning the full set again on a later date leaves every earlier date as it was.

pub fn with_pinned_added( self, store: &FixingStore, at: Option<NaiveDate>, ) -> Self

This history with store’s prints added as pins at the market date at, a pin already held from that date replaced.

pub fn with_fetched( self, prints: &[(String, NaiveDate, f64)], on: NaiveDate, ) -> Self

This history with prints learnt by a fetch on on. A print that repeats the value a market at on already reads adds no version, so a long-lived market re-asking unchanged prints does not grow.

pub fn without_fetched_on(self, on: NaiveDate) -> Self

This history without the versions a fetch on on learnt, so a fetch at on asks for those prints again; pins and versions learnt on other dates are kept. What a same-day re-fetch needs: without it, a print corrected during the day was never asked for, as the demand re-asks only what an earlier date learnt.

pub fn versions(&self) -> Vec<(&str, NaiveDate, NaiveDate, bool, f64)>

Every version: (index, date, known_on, pinned, value) in key then knowledge order.

pub fn is_empty(&self) -> bool

Whether the history holds no print at all.

Trait Implementations§

§

impl Clone for FixingHistory

§

fn clone(&self) -> FixingHistory

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 FixingHistory

§

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

Formats the value using the given formatter. Read more
§

impl Default for FixingHistory

§

fn default() -> FixingHistory

Returns the “default value” for a type. Read more
§

impl PartialEq for FixingHistory

§

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

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.