Struct yata::methods::renko::Renko

source ·
pub struct Renko { /* private fields */ }
Expand description

Converts timeseries to Renko timeseries

Renko is very different from a simple timeseries. On each step it may generate any amount of blocks or not generate it at all. That’s why it needs to be implemented throw three different structures:

When call Method::next on Renko, it always returns RenkoOutput.

It implements an Iterator trait for generating RenkoBlocks after each step of calling Method::next on Renko. RenkoOutput may produce any amount of RenkoBlocks or may not produce it at all.

It has open and close values which are similar to corresponding OHLCV’s values.

So the final workflow is like that:

  1. Call Renko’s Method::next on some ValueType and get RenkoOutput.
  2. Iterate over taken RenkoOutput to get some (or none) RenkoBlocks.
  3. Use produced RenkoBlocks 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 a `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§

source§

impl Clone for Renko

source§

fn clone(&self) -> Renko

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Renko

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Renko

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Method for Renko

§

type Params = (f64, Source)

Method parameters
§

type Input = dyn OHLCV

Input value type
§

type Output = RenkoOutput

Output value type
source§

fn new( (brick_size, src): Self::Params, candle: &Self::Input ) -> Result<Self, Error>

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

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

Generates next output value based on the given input value
source§

fn with_history( parameters: Self::Params, initial_value: &Self::Input ) -> Result<WithHistory<Self, Self::Output>, Error>
where Self: Sized, Self::Output: Debug + Clone,

Creates an instance of the method with given parameters and initial value, wrapped by historical data holder
source§

fn with_last_value( parameters: Self::Params, initial_value: &Self::Input ) -> Result<WithLastValue<Self, Self::Output>, Error>
where Self: Sized, Self::Output: Debug + Clone,

Creates an instance of the method with given parameters and initial value, wrapped by last produced value holder
source§

fn name(&self) -> &str

Returns a name of the method
source§

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

👎Deprecated
Returns memory size of the method (size, align)
source§

fn apply<T, S>(&mut self, sequence: &mut S)
where S: Sequence<T> + AsMut<[T]> + ?Sized, Self: Method<Input = T, Output = T> + Sized,

Applies method to the sequence in-place.
source§

fn new_apply<T, S>( parameters: Self::Params, sequence: &mut S ) -> Result<(), Error>
where S: Sequence<T> + AsMut<[T]>, Self: Method<Input = T, Output = T> + Sized,

Creates new Method instance and applies it to the sequence.
source§

fn into_fn<'a>( self ) -> Box<dyn FnMut(&'a <Self as Method>::Input) -> <Self as Method>::Output>
where Self: Sized + 'static, Self::Input: 'static,

Creates a function from the Method instance
source§

fn new_fn( params: Self::Params, initial_value: &Self::Input ) -> Result<Box<dyn FnMut(&'_ <Self as Method>::Input) -> <Self as Method>::Output>, Error>
where Self: Sized + 'static,

Creates new function based on the method
source§

impl Serialize for Renko

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Renko

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,