Struct yata::methods::Renko [−][src]
Converts timeseries to Renko timeseries
Renko is very different from the simple timeseries. On each step it may generate any amount of blocks or not genereate it at all. That’s why it needs to be implement throw three different structures:
Renko
method itself.
When call Method::next
on Renko
, it always returns RenkoOutput
.
RenkoOutput
which isRenko
’s method output type.
It implements an Iterator
trait for generating RenkoBlock
s after each step of calling Method::next
on Renko
.
RenkoOutput
may produce any amount of RenkoBlock
s or may not produce it at all.
RenkoBlock
is final entity of Renko chart.
It has open
and close
values which are similar to corresponding OHLCV
’s values.
So the final workflow is like that:
- Call
Renko
’sMethod::next
on someValueType
and getRenkoOutput
. - Iterate over taken
RenkoOutput
to get some (or none)RenkoBlock
s. - Use produced
RenkoBlock
s on your own.
Parameters
Has a tuple of 2 parameters (size
: ValueType
, source
: Source
)
size
:ValueType
. Represents relative block size.
size
must be in range (0.0
; 1.0
)
source
:Source
. Represents which value of input’s OHLCV it will use.
use yata::prelude::*; use yata::core::Source; use yata::methods::Renko; let first_timeseries_value = Candle { close: 123.456, ..Candle::default() }; let renko = Renko::new((0.01, Source::Close), &first_timeseries_value); // creates a Renko method with relative block size of 1%.
Input type
Input type is reference to OHLCV
Output type
Input type is RenkoOutput
Examples
use yata::prelude::*; use yata::core::Source; use yata::methods::Renko; // Here we just creating `Vec` of `OHLCV`s with only `close` value inside let inputs = (&[100.0, 100.5, 101.506, 105.0, 102.0, 101.4, 100.0]) .iter() .map(|&v| Candle { close: v, ..Candle::default() }) .collect::<Vec<_>>(); let mut renko = Renko::new((0.01, Source::Close), &inputs[0]).unwrap(); // renko with relative block size of 1% assert!(renko.next(&inputs[0]).is_empty()); assert!(renko.next(&inputs[1]).is_empty()); assert_eq!(renko.next(&inputs[2]).len(), 1); let blocks = renko.next(&inputs[3]); assert_eq!(blocks.len(), 3); blocks.for_each(|block| { println!("{:?}", &block); }); assert_eq!(renko.next(&inputs[4]).len(), 1); assert_eq!(renko.next(&inputs[5]).len(), 1); assert_eq!(renko.next(&inputs[6]).len(), 1);
Performance
O(1)
See also
Trait Implementations
impl Clone for Renko
[src]
impl Copy for Renko
[src]
impl Debug for Renko
[src]
impl<'de> Deserialize<'de> for Renko
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<'a> Method<'a> for Renko
[src]
type Params = (ValueType, Source)
Method parameters
type Input = &'a dyn OHLCV
Input value type
type Output = RenkoOutput
Output value type
fn new(
(brick_size, src): Self::Params,
candle: Self::Input
) -> Result<Self, Error>
[src]
(brick_size, src): Self::Params,
candle: Self::Input
) -> Result<Self, Error>
fn next(&mut self, candle: Self::Input) -> Self::Output
[src]
fn name(&self) -> &str
[src]
fn memsize(&self) -> (usize, usize) where
Self: Sized,
[src]
Self: Sized,
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,
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,
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,
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,
fn into_fn(self) -> Box<dyn FnMut(Self::Input) -> Self::Output> where
Self: Sized + 'static,
[src]
Self: Sized + 'static,
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,
impl Serialize for Renko
[src]
Auto Trait Implementations
impl RefUnwindSafe for Renko
impl Send for Renko
impl Sync for Renko
impl Unpin for Renko
impl UnwindSafe for Renko
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,