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
impl FxRates
fn route_for(&self, pair: CurrencyPair) -> Option<Vec<Currency>>
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
fn holds(&self, pair: CurrencyPair) -> bool
Whether this pair is quoted, in either direction.
pub fn new() -> Self
pub fn new() -> Self
An empty store.
pub fn from_quotes(
quotes: &[(CurrencyPair, f64)],
) -> Result<Self, MarketDataError>
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]
pub fn parameters(&self) -> &[f64]
The free parameters — one rate per stored pair.
pub fn parameter_keys(&self) -> &[CurrencyPair]
pub fn parameter_keys(&self) -> &[CurrencyPair]
The pair each parameter belongs to, in parameter order.
fn position(&self, pair: CurrencyPair) -> Option<usize>
pub fn view_with<'a, R: Scalar>(
&'a self,
params: &'a [R],
) -> Result<FxView<'a, R>, MarketDataError>
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.