stock-trek 0.6.0

Stock Trek time-series analysis
Documentation
use crate::{
    asset_id::AssetId,
    exchange_id::ExchangeId,
    market_data::market::Market,
    statistics::{
        advanced::Advanced, decompose::Decompose, evaluation::Evaluation,
        exponential_smoothing::ExponentialSmoothing, filter::Filter, frequency::Frequency,
        hypothesis::Hypothesis, moving_average::MovingAverage, stats::Stats,
        time_series::TimeSeries, transformation::Transformation, wavelet::Wavelet,
    },
};
use std::collections::HashMap;

pub struct StrategyContext {
    market_data: HashMap<ExchangeId, MarketDataByBaseContext>,
    pub stats: Stats,
}

impl StrategyContext {
    pub fn new(market_data: HashMap<ExchangeId, MarketDataByBaseContext>) -> Self {
        Self {
            market_data,
            stats: Stats {
                advanced: Advanced,
                decompose: Decompose,
                evaluation: Evaluation,
                exponential_smoothing: ExponentialSmoothing,
                filter: Filter,
                frequency: Frequency,
                hypothesis: Hypothesis,
                moving_average: MovingAverage,
                time_series: TimeSeries,
                transformation: Transformation,
                wavelet: Wavelet,
            },
        }
    }
    pub fn exchange_markets_for<'context>(
        &'context self,
        base: &'context AssetId,
        quote: &'context AssetId,
    ) -> impl Iterator<Item = (ExchangeId, &'context Market)> + 'context {
        self.market_data
            .iter()
            .filter_map(move |(exchange, by_base)| {
                by_base
                    .markets_by_base
                    .get(base)
                    .and_then(|by_quote| by_quote.markets_by_quote.get(quote))
                    .map(|market| (exchange.clone(), market))
            })
    }
    pub fn market_for(
        &self,
        exchange_id: &ExchangeId,
        base: &AssetId,
        quote: &AssetId,
    ) -> Option<&Market> {
        self.market_data
            .get(exchange_id)
            .and_then(|m| m.markets_by_base.get(base))
            .and_then(|m| m.markets_by_quote.get(quote))
    }
}

pub struct MarketDataByBaseContext {
    markets_by_base: HashMap<AssetId, MarketDataByQuoteContext>,
}

impl MarketDataByBaseContext {
    pub fn new(markets_by_base: HashMap<AssetId, MarketDataByQuoteContext>) -> Self {
        Self { markets_by_base }
    }
}

pub struct MarketDataByQuoteContext {
    markets_by_quote: HashMap<AssetId, Market>,
}

impl MarketDataByQuoteContext {
    pub fn new(markets_by_quote: HashMap<AssetId, Market>) -> Self {
        Self { markets_by_quote }
    }
}