Skip to main content

FxRates

Struct FxRates 

pub struct FxRates {
    pairs: Vec<CurrencyPair>,
    rates: Vec<f64>,
}
Expand description

FX spot rates, one stored direction per pair.

Fields§

§pairs: Vec<CurrencyPair>

Sorted, index-aligned with rates.

§rates: Vec<f64>

The free parameters: quote units per one base, in pair order.

Implementations§

§

impl FxRates

fn route_for(&self, pair: CurrencyPair) -> Option<Vec<Currency>>

The currencies a chain of quoted pairs visits from pair.base to pair.quote, both ends included; None when no chain links them.

Deterministic by construction: the search is breadth-first, so the chain is a shortest one, and each currency’s neighbours are visited in ascending currency-code order, so among chains of equal length the first by code wins — for one intermediate, the first bridging currency in code order. Two stores holding the same rates choose the same route. That matters beyond tidiness — the route decides which legs a conversion reads, and therefore which rows its risk lands on. An insertion-order-dependent choice would give one market two ladders.

fn holds(&self, pair: CurrencyPair) -> bool

Whether this pair is quoted, in either direction.

pub fn new() -> Self

An empty store.

pub fn from_quotes( quotes: &[(CurrencyPair, f64)], ) -> Result<Self, MarketDataError>

Builds a store from (pair, rate) quotes.

§Errors

MarketDataError::Malformed if a rate is not finite and strictly positive, if the same pair is quoted twice with different rates, or if both directions of one pair are supplied — the inverse is derived, and supplying it separately invites the two to disagree.

pub fn parameters(&self) -> &[f64]

The free parameters — one rate per stored pair.

pub fn parameter_keys(&self) -> &[CurrencyPair]

The pair each parameter belongs to, in parameter order.

pub fn len(&self) -> usize

How many pairs the store holds.

pub fn is_empty(&self) -> bool

Whether the store holds no rates.

fn position(&self, pair: CurrencyPair) -> Option<usize>

pub fn view<R: Scalar>(&self) -> FxView<'_, R>

This store lifted into mode R.

pub fn view_with<'a, R: Scalar>( &'a self, params: &'a [R], ) -> Result<FxView<'a, R>, MarketDataError>

This store lifted into mode R over params.

§Errors

MarketDataError::ParameterCountMismatch if params is the wrong length.

Trait Implementations§

§

impl Clone for FxRates

§

fn clone(&self) -> FxRates

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 FxRates

§

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

Formats the value using the given formatter. Read more
§

impl Default for FxRates

§

fn default() -> FxRates

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

impl PartialEq for FxRates

§

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

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.