quantaxis_rs/traits.rs
1// Indicator traits
2//
3
4/// Resets an indicator to the initial state.
5pub trait Reset {
6 fn reset(&mut self);
7}
8
9/// Consumes a data item of type `T` and returns `Output`.
10///
11/// Typically `T` can be `f64` or a struct similar to [DataItem](struct.DataItem.html), that implements
12/// traits necessary to calculate value of a particular indicator.
13///
14/// In most cases `Output` is `f64`, but sometimes it can be different. For example for
15/// [MACD](indicators/struct.MovingAverageConvergenceDivergence.html) it is `(f64, f64, f64)` since
16/// MACD returns 3 values.
17///
18pub trait Next<T> {
19 type Output;
20 fn next(&mut self, input: T) -> Self::Output;
21}
22
23pub trait Update<T> {
24 type Output;
25 fn update(&mut self, input: T) -> Self::Output;
26}
27
28
29/// Open price of a particular period.
30pub trait Open {
31 fn open(&self) -> f64;
32}
33
34/// Close price of a particular period.
35pub trait Close {
36 fn close(&self) -> f64;
37}
38
39/// Lowest price of a particular period.
40pub trait Low {
41 fn low(&self) -> f64;
42}
43
44/// Highest price of a particular period.
45pub trait High {
46 fn high(&self) -> f64;
47}
48
49/// Trading volume of a particular trading period.
50pub trait Volume {
51 fn volume(&self) -> f64;
52}