[][src]Trait yata::core::Method

pub trait Method: Debug {
    type Params;
    type Input: Copy;
    type Output: Copy;
    fn new(parameters: Self::Params, initial_value: Self::Input) -> Self
    where
        Self: Sized
;
fn next(&mut self, value: Self::Input) -> Self::Output; fn name(&self) -> &str { ... }
fn memsize(&self) -> (usize, usize)
    where
        Self: Sized
, { ... }
fn iter_data<I>(&mut self, input: I) -> MethodOverIterator<'_, Self, I>
    where
        I: Iterator<Item = Self::Input>,
        Self: Sized
, { ... }
fn over<I>(&mut self, sequence: I) -> Sequence<Self::Output>
    where
        I: Iterator<Item = Self::Input>,
        Self: Sized
, { ... } }

Trait for creating methods for timeseries

Regular methods usage

Iterate over vector's values

use yata::methods::SMA;
use yata::prelude::*;

let s:Vec<f64> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.];
let mut ma = SMA::new(2, s[0]);

s.iter().enumerate().for_each(|(index, &value)| {
	assert_eq!(ma.next(value), (value + s[index.saturating_sub(1)])/2.);
});

Get a whole new vector over the input vector

use yata::methods::SMA;
use yata::prelude::*;

let s:Vec<f64> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.];
let mut ma = SMA::new(2, s[0]);

let result = ma.over(s.iter().copied());
assert_eq!(result.as_slice(), &[1., 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]);

Change vector values using method

use yata::core::Sequence;
use yata::methods::SMA;
use yata::prelude::*;

let mut s:Sequence<f64> = Sequence::from(vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]);
let mut ma = SMA::new(2, s[0]);

s.apply(&mut ma);
assert_eq!(s.as_slice(), &[1., 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]);

Be advised

There is no reset method on the trait. If you need reset a state of the Method instance, you should just create a new one.

Associated Types

type Params

Method parameters

type Input: Copy

Input value type

type Output: Copy

Output value type

Loading content...

Required methods

fn new(parameters: Self::Params, initial_value: Self::Input) -> Self where
    Self: Sized

Static method for creating an instance of the method with given parameters and initial value (simply first input value)

fn next(&mut self, value: Self::Input) -> Self::Output

Generates next output value based on the given input value

Loading content...

Provided methods

fn name(&self) -> &str

Returns a name of the method

fn memsize(&self) -> (usize, usize) where
    Self: Sized

Returns memory size of the method (size, align)

fn iter_data<I>(&mut self, input: I) -> MethodOverIterator<'_, Self, I> where
    I: Iterator<Item = Self::Input>,
    Self: Sized

Creates an iterator which produces values by the Method over given input data iterator

fn over<I>(&mut self, sequence: I) -> Sequence<Self::Output> where
    I: Iterator<Item = Self::Input>,
    Self: Sized

Iterates the Method over the given Sequence and returns timeserie of output values

Guarantees

The length of an output Sequence is always equal to the length of input one

use yata::methods::SMA;
use yata::prelude::*;

let s:Vec<f64> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.];
let mut ma = SMA::new(5, s[0]);

let result = ma.over(s.iter().copied());
assert_eq!(result.len(), s.len());
use yata::methods::SMA;
use yata::prelude::*;

let s:Vec<f64> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.];
let mut ma = SMA::new(100, s[0]);

let result = ma.over(s.iter().copied());
assert_eq!(result.len(), s.len());
Loading content...

Implementors

impl Method for Conv[src]

type Params = Vec<ValueType>

type Input = ValueType

type Output = Self::Input

impl Method for Cross[src]

type Params = ()

type Input = (ValueType, ValueType)

type Output = Action

impl Method for CrossAbove[src]

type Params = ()

type Input = (ValueType, ValueType)

type Output = Action

impl Method for CrossUnder[src]

type Params = ()

type Input = (ValueType, ValueType)

type Output = Action

impl Method for DEMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for DMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for Derivative[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for EMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for HMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for Highest[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for HighestLowestDelta[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for Integral[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for LinReg[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for LinearVolatility[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for Lowest[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for Momentum[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for PivotHighSignal[src]

type Params = (PeriodType, PeriodType)

type Input = ValueType

type Output = Action

impl Method for PivotLowSignal[src]

type Params = (PeriodType, PeriodType)

type Input = ValueType

type Output = Action

impl Method for PivotSignal[src]

type Params = (PeriodType, PeriodType)

type Input = ValueType

type Output = Action

impl Method for RMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for RateOfChange[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for SMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for SMM[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for SWMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for StDev[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for TEMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for TMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl Method for VWMA[src]

type Params = PeriodType

type Input = (ValueType, ValueType)

type Output = ValueType

impl Method for WMA[src]

type Params = PeriodType

type Input = ValueType

type Output = Self::Input

impl<T> Method for Past<T> where
    T: Sized + Copy + Default + Debug
[src]

type Params = PeriodType

type Input = T

type Output = T

impl<T: OHLCV> Method for ADI<T>[src]

type Params = PeriodType

type Input = T

type Output = ValueType

Loading content...