pub trait Indicator {
type Input;
type Output;
// Required methods
fn update(&mut self, input: Self::Input) -> Option<Self::Output>;
fn reset(&mut self);
fn warmup_period(&self) -> usize;
fn is_ready(&self) -> bool;
fn name(&self) -> &'static str;
// Provided methods
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
where Self::Input: Copy,
Self::Output: Into<f64> { ... }
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
where Self::Input: Copy,
Self::Output: Into<f64> { ... }
}Expand description
A streaming technical indicator.
Every indicator in Wickra implements this trait. The contract is:
updateis called once per input point and must be O(1) in the input length. Pre-existing buffered state may be touched, but no full recomputation over the entire series is permitted.- The returned
Option<Output>isNonewhile the indicator is still in its warmup phase (insufficient inputs to produce a defined value), andSomeonce it is ready. resetclears all state, returning the indicator to the exact configuration it had immediately after construction.
Implementors that consume scalar prices use Input = f64 so they automatically
gain access to chaining via Chain.
Required Associated Types§
Required Methods§
Sourcefn update(&mut self, input: Self::Input) -> Option<Self::Output>
fn update(&mut self, input: Self::Input) -> Option<Self::Output>
Feed one new data point into the indicator and return the freshly
computed output, or None if there is no value for this input.
None covers exactly two cases:
- the indicator is still warming up, and
- the input was rejected as non-finite.
A rejected input is skipped: it does not enter the indicator’s state, so a single bad tick cannot corrupt the values that follow it. The alternative — repeating the last computed value — was rejected because it hands the caller a stale number that looks exactly like a fresh one.
Sourcefn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly constructed instance with the same parameters.
Sourcefn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-None output can be produced.
Provided Methods§
Sourcefn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Run the indicator over inputs, writing one output per input into the
caller-owned out buffer (NaN where update
returns None). It exists for every indicator whose output converts to an
f64; the batch pipelines use it for the scalar f64 -> f64 ones.
This is the exact batch: every value is bit-for-bit the one a replay of
update produces, and the indicator is left in the state that replay
leaves it in. The default replays update; indicators with a faster exact
formulation override it, and every binding and extension method routes
through here, so the override reaches all of them. Writing into a buffer
the caller owns skips the output allocation, which on a large series costs
more than the arithmetic of a simple indicator.
The bounds name only the associated types, so Indicator stays usable as
a trait object and the method, called through a dyn Indicator, reaches
the concrete indicator’s override.
§Panics
Panics if out.len() != inputs.len().
Sourcefn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Opt-in fast batch: like batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware.
The kernel only runs from a fresh (just constructed or reset) indicator over an all-finite slice; any other call is served by the exact batch. Afterwards the indicator continues streaming from the kernel’s final state. The default is the exact batch, so every scalar indicator offers this method and the ones without a kernel simply return exact values.
§Panics
Panics if out.len() != inputs.len().
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".