[−][src]Trait yata::core::Method
Trait for creating methods for timeseries
Regular methods usage
Iterate over vector's values
use yata::methods::SMA; use yata::prelude::*; let s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(2, s[0]).unwrap(); 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
You can call method over
any Sequence
:
use yata::methods::SMA; use yata::prelude::*; let s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(2, s[0]).unwrap(); let result = ma.over(s); assert_eq!(result.as_slice(), &[1., 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]);
Or you can provide Method
to Sequence
:
use yata::methods::SMA; use yata::prelude::*; let s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(2, s[0]).unwrap(); let result = s.call(ma); assert_eq!(result.as_slice(), &[1., 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]);
Or you can even change Sequence
values in-place:
use yata::methods::SMA; use yata::prelude::*; let mut s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(2, s[0]).unwrap(); s.apply(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
[src]
Method parameters
type Input
[src]
Input value type
type Output: Copy
[src]
Output value type
Required methods
pub fn new(
parameters: Self::Params,
initial_value: Self::Input
) -> Result<Self, Error> where
Self: Sized,
[src]
parameters: Self::Params,
initial_value: Self::Input
) -> Result<Self, Error> where
Self: Sized,
Static method for creating an instance of the method with given parameters
and initial value
(simply first input value)
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
Generates next output value based on the given input value
Provided methods
pub fn name(&self) -> &str
[src]
Returns a name of the method
pub fn memsize(&self) -> (usize, usize) where
Self: Sized,
[src]
Self: Sized,
Returns memory size of the method (size, align)
pub fn over<S>(&'a mut self, inputs: S) -> Vec<Self::Output> where
S: Sequence<Self::Input>,
Self: Sized,
[src]
S: Sequence<Self::Input>,
Self: Sized,
Iterates the Method
over the given inputs
slice and returns Vec
of output values.
Guarantees
The length of an output Vec
is always equal to the length of an inputs
slice.
use yata::methods::SMA; use yata::prelude::*; let s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(5, s[0]).unwrap(); let result = ma.over(&s); assert_eq!(result.len(), s.len());
use yata::methods::SMA; use yata::prelude::*; let s: Vec<_> = vec![1.,2.,3.,4.,5.,6.,7.,8.,9.,10.]; let mut ma = SMA::new(100, s[0]).unwrap(); let result = ma.over(&s); assert_eq!(result.len(), s.len());
pub fn apply<'b: 'a, T, S>(&'a mut self, sequence: &'b mut S) where
S: Sequence<T> + AsMut<[T]>,
Self: Method<'a, Input = T, Output = T> + Sized,
T: Copy,
[src]
S: Sequence<T> + AsMut<[T]>,
Self: Method<'a, Input = T, Output = T> + Sized,
T: Copy,
Applies method to the sequence in-place.
pub fn new_over<S>(
parameters: Self::Params,
inputs: S
) -> Result<Vec<Self::Output>, Error> where
S: Sequence<Self::Input>,
Self::Input: Clone,
Self: Sized + 'a,
[src]
parameters: Self::Params,
inputs: S
) -> Result<Vec<Self::Output>, Error> where
S: Sequence<Self::Input>,
Self::Input: Clone,
Self: Sized + 'a,
Creates new Method
instance and iterates it over the given inputs
slice and returns Vec
of output values.
Guarantees
The length of an output Vec
is always equal to the length of an inputs
slice.
pub fn new_apply<T, S>(
parameters: Self::Params,
sequence: &'a mut S
) -> Result<(), Error> where
T: Copy,
S: Sequence<T> + AsMut<[T]>,
Self: Method<'a, Input = T, Output = T> + Sized + 'a,
[src]
parameters: Self::Params,
sequence: &'a mut S
) -> Result<(), Error> where
T: Copy,
S: Sequence<T> + AsMut<[T]>,
Self: Method<'a, Input = T, Output = T> + Sized + 'a,
Creates new Method
instance and applies it to the sequence
.
pub fn into_fn(self) -> Box<dyn FnMut(Self::Input) -> Self::Output> where
Self: Sized + 'static,
[src]
Self: Sized + 'static,
Creates a function from the Method
instance
pub fn new_fn(
params: Self::Params,
initial_value: Self::Input
) -> Result<Box<dyn FnMut(Self::Input) -> Self::Output>, Error> where
Self: Sized + 'static,
[src]
params: Self::Params,
initial_value: Self::Input
) -> Result<Box<dyn FnMut(Self::Input) -> Self::Output>, Error> where
Self: Sized + 'static,
Creates new function based on the method
Implementations on Foreign Types
impl<'a, M: Method<'a>> Method<'a> for &'a mut M
[src]
type Params = M::Params
type Input = M::Input
Input value type
type Output = M::Output
Output value type
pub fn new(
_parameters: Self::Params,
_initial_value: Self::Input
) -> Result<Self, Error>
[src]
_parameters: Self::Params,
_initial_value: Self::Input
) -> Result<Self, Error>
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
Generates next output value based on the given input value
Implementors
impl Method<'_> for CCI
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Conv
[src]
type Params = Vec<ValueType>
type Input = ValueType
type Output = Self::Input
pub fn new(weights: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Cross
[src]
type Params = ()
type Input = (ValueType, ValueType)
type Output = Action
pub fn new(_: Self::Params, value: Self::Input) -> Result<Self, Error> where
Self: Sized,
[src]
Self: Sized,
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for CrossAbove
[src]
type Params = ()
type Input = (ValueType, ValueType)
type Output = Action
pub fn new(_: Self::Params, value: Self::Input) -> Result<Self, Error> where
Self: Sized,
[src]
Self: Sized,
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for CrossUnder
[src]
type Params = ()
type Input = (ValueType, ValueType)
type Output = Action
pub fn new(_: Self::Params, value: Self::Input) -> Result<Self, Error> where
Self: Sized,
[src]
Self: Sized,
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for DEMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for DMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Derivative
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for EMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for HMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Highest
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> ValueType
[src]
impl Method<'_> for HighestIndex
[src]
type Params = PeriodType
type Input = ValueType
type Output = PeriodType
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for HighestLowestDelta
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error> where
Self: Sized,
[src]
Self: Sized,
pub fn next(&mut self, value: Self::Input) -> ValueType
[src]
impl Method<'_> for Integral
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for LinReg
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for LinearVolatility
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for LowerReversalSignal
[src]
type Params = (PeriodType, PeriodType)
type Input = ValueType
type Output = Action
pub fn new(params: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Lowest
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> ValueType
[src]
impl Method<'_> for LowestIndex
[src]
type Params = PeriodType
type Input = ValueType
type Output = PeriodType
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for MeanAbsDev
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for MedianAbsDev
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Momentum
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for RMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for RateOfChange
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for ReversalSignal
[src]
type Params = (PeriodType, PeriodType)
type Input = ValueType
type Output = Action
pub fn new(params: Self::Params, value: Self::Input) -> Result<Self, Error> where
Self: Sized,
[src]
Self: Sized,
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for SMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for SMM
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for SWMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for StDev
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for TEMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for TMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for TRIMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for TSI
[src]
type Params = (PeriodType, PeriodType)
type Input = ValueType
type Output = Self::Input
pub fn new(params: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for UpperReversalSignal
[src]
type Params = (PeriodType, PeriodType)
type Input = ValueType
type Output = Action
pub fn new(params: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for VWMA
[src]
type Params = PeriodType
type Input = (ValueType, ValueType)
type Output = ValueType
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for Vidya
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, input: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, input: Self::Input) -> Self::Output
[src]
impl Method<'_> for WMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl Method<'_> for WSMA
[src]
type Params = PeriodType
type Input = ValueType
type Output = Self::Input
pub fn new(length: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl<'a> Method<'a> for ADI
[src]
type Params = PeriodType
type Input = &'a dyn OHLCV
type Output = ValueType
pub fn new(length: Self::Params, candle: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, candle: Self::Input) -> Self::Output
[src]
impl<'a> Method<'a> for HeikinAshi
[src]
type Params = ()
type Input = &'a dyn OHLCV
type Output = Candle
pub fn new(_: Self::Params, value: Self::Input) -> Result<Self, Error>
[src]
pub fn next(&mut self, value: Self::Input) -> Self::Output
[src]
impl<'a, T> Method<'a> for Past<T> where
T: Copy + Debug,
[src]
T: Copy + Debug,