Skip to content

Commit

Permalink
docs: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amv-dev committed Dec 5, 2021
1 parent 3cd0f3b commit 4ceee35
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/core/moving_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Input = ValueType, Output = ValueType> {}

/// 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;
Expand Down
8 changes: 1 addition & 7 deletions src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -151,12 +151,6 @@ impl RandomCandles {
}
}

impl Default for RandomCandles {
fn default() -> Self {
Self(0)
}
}

impl Iterator for RandomCandles {
type Item = Candle;

Expand Down
2 changes: 1 addition & 1 deletion src/indicators/coppock_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct CoppockCurve<M: MovingAverageConstructor = MA> {
/// 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)
///
Expand Down
26 changes: 11 additions & 15 deletions src/indicators/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,19 @@ impl IndicatorInstance for ExampleInstance {
fn next<T: OHLCV>(&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);
Expand Down
24 changes: 12 additions & 12 deletions src/methods/highest_lowest_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/methods/reversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down Expand Up @@ -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`]
Expand Down Expand Up @@ -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`]
Expand Down

0 comments on commit 4ceee35

Please sign in to comment.