From 4ceee35f88258663545860449731fa31c281dc2c Mon Sep 17 00:00:00 2001 From: amv-dev Date: Mon, 6 Dec 2021 00:19:27 +0500 Subject: [PATCH] docs: fix --- src/core/mod.rs | 4 ++-- src/core/moving_average.rs | 8 +++----- src/helpers/mod.rs | 8 +------- src/indicators/coppock_curve.rs | 2 +- src/indicators/example.rs | 26 +++++++++++--------------- src/methods/highest_lowest_index.rs | 24 ++++++++++++------------ src/methods/reversal.rs | 6 +++--- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/core/mod.rs b/src/core/mod.rs index 0f73d7e..69f5b72 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -32,7 +32,7 @@ pub use window::Window; /// /// ```toml /// [dependencies] -/// yata = { value_type_f32 = true } +/// yata = { features = [ "value_type_f32" ] } /// ``` /// /// Read more at [Features section](https://doc.rust-lang.org/cargo/reference/features.html#the-features-section) @@ -59,7 +59,7 @@ pub type ValueType = f32; /// /// ```toml /// [dependencies] -/// yata = { period_type_u16 = true } +/// yata = { features = ["period_type_u16"] } /// ``` /// /// Read more at [Features section](https://doc.rust-lang.org/cargo/reference/features.html#the-features-section) diff --git a/src/core/moving_average.rs b/src/core/moving_average.rs index 19f14aa..d6c247a 100644 --- a/src/core/moving_average.rs +++ b/src/core/moving_average.rs @@ -2,26 +2,24 @@ use std::str::FromStr; use super::{Error, Method, PeriodType, ValueType}; -/// A shortcut for dynamically generated moving averages +/// Marker trait for any moving average /// /// Moving average is a [`Method`] which has parameters of single [`PeriodType`], input is single [`ValueType`] and output is single [`ValueType`]. /// /// # See also /// -/// [Default regular methods list](RegularMethods) +/// [Default moving averages methods list](crate::helpers::MA) /// /// [`Method`]: crate::core::Method /// [`ValueType`]: crate::core::ValueType /// [`PeriodType`]: crate::core::PeriodType - -/// Marker trait for any moving average pub trait MovingAverage: Method {} /// Trait for dynamically creation of moving average instances based on it's type and period /// /// This trait plays the same role for moving averages as [`IndicatorConfig`] plays for indicators. /// -/// [`IndicatorConfig`]: crate::core::indicator::IndicatorConfig +/// [`IndicatorConfig`]: crate::core::IndicatorConfig pub trait MovingAverageConstructor: Clone + FromStr { /// Used for comparing MA types type Type: Eq; diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index cdc9112..0a50e3e 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -125,7 +125,7 @@ pub fn assert_neq_float(value1: ValueType, value2: ValueType) { } /// Random Candles iterator for testing purposes -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] #[allow(missing_copy_implementations)] pub struct RandomCandles(u16); @@ -151,12 +151,6 @@ impl RandomCandles { } } -impl Default for RandomCandles { - fn default() -> Self { - Self(0) - } -} - impl Iterator for RandomCandles { type Item = Candle; diff --git a/src/indicators/coppock_curve.rs b/src/indicators/coppock_curve.rs index d91a3d9..c905e80 100644 --- a/src/indicators/coppock_curve.rs +++ b/src/indicators/coppock_curve.rs @@ -37,7 +37,7 @@ pub struct CoppockCurve { /// Period range in \[`2`; [`PeriodType::MAX`](crate::core::PeriodType)\). pub ma1: M, - /// Signal line MA type . + /// Signal line MA type . /// /// Default is [`EMA(5)`](crate::methods::EMA) /// diff --git a/src/indicators/example.rs b/src/indicators/example.rs index a0a4911..75eeb2c 100644 --- a/src/indicators/example.rs +++ b/src/indicators/example.rs @@ -115,23 +115,19 @@ impl IndicatorInstance for ExampleInstance { fn next(&mut self, candle: &T) -> IndicatorResult { let new_signal = self.cross.next(&(candle.close(), self.cfg.price)); - let signal = match new_signal { - Action::None => { - self.last_signal = new_signal; - self.last_signal_position = 0; - new_signal - } - _ => { - if let Action::None = self.last_signal { - self.last_signal - } else { - self.last_signal_position += 1; - if self.last_signal_position > self.cfg.period { - self.last_signal = Action::None; - } - self.last_signal + let signal = if new_signal == Action::None { + self.last_signal = new_signal; + self.last_signal_position = 0; + new_signal + } else { + if Action::None != self.last_signal { + self.last_signal_position += 1; + if self.last_signal_position > self.cfg.period { + self.last_signal = Action::None; } } + + self.last_signal }; let some_other_signal = Action::from(0.5); diff --git a/src/methods/highest_lowest_index.rs b/src/methods/highest_lowest_index.rs index 47a1850..0373c63 100644 --- a/src/methods/highest_lowest_index.rs +++ b/src/methods/highest_lowest_index.rs @@ -97,12 +97,12 @@ impl Method for HighestIndex { self.value = value; self.index = 0; } else if self.index == self.window.len() { - let (index, value) = - self.window - .iter() - .copied() - .enumerate() - .fold((0, value), |a, b| if b.1 > a.1 { b } else { a }); + let (index, value) = self + .window + .iter() + .copied() + .enumerate() + .fold((0, value), |a, b| if b.1 > a.1 { b } else { a }); self.index = index as PeriodType; // self.window.len() - index as PeriodType - 1; self.value = value; @@ -205,12 +205,12 @@ impl Method for LowestIndex { self.value = value; self.index = 0; } else if self.index == self.window.len() { - let (index, value) = - self.window - .iter() - .copied() - .enumerate() - .fold((0, value), |a, b| if b.1 < a.1 { b } else { a }); + let (index, value) = self + .window + .iter() + .copied() + .enumerate() + .fold((0, value), |a, b| if b.1 < a.1 { b } else { a }); self.index = index as PeriodType; // self.window.len() - index as PeriodType - 1; self.value = value; diff --git a/src/methods/reversal.rs b/src/methods/reversal.rs index 7c454a9..daeffdf 100644 --- a/src/methods/reversal.rs +++ b/src/methods/reversal.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; /// /// `left` should be > `0` and `right` should be > `0` /// -/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]::MAX. +/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]`::MAX`. /// So if your [`PeriodType`] is default `u8`, then `left`+`right`+1 should be <= `255` /// /// [Read more about `PeriodType`][`PeriodType`] @@ -93,7 +93,7 @@ impl Method for ReversalSignal { /// /// `left` should be > 0 and `right` should be > 0 /// -/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]::MAX. +/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]`::MAX`. /// So if your [`PeriodType`] is default `u8`, then `left`+`right`+1 should be <= 255 /// /// [Read more about `PeriodType`][`PeriodType`] @@ -224,7 +224,7 @@ impl Method for UpperReversalSignal { /// /// `left` should be > 0 and `right` should be > 0 /// -/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]::MAX. +/// There is an additional restriction on parameters: `left`+`right`+1 should be <= [`PeriodType`]`::MAX`. /// So if your [`PeriodType`] is default `u8`, then `left`+`right`+1 should be <= 255 /// /// [Read more about `PeriodType`][`PeriodType`]