pub struct MaEnvelope { /* private fields */ }Expand description
Moving Average Envelope: an SMA centerline with constant-percent bands on each side.
middle = SMA(period)
upper = middle · (1 + percent)
lower = middle · (1 − percent)The envelope is a fixed multiplicative offset around the moving average,
so the band width scales with price rather than with realised volatility
(contrast Bollinger Bands, whose width is 2·k·σ, or Keltner Channels,
whose width is 2·k·ATR). It is the oldest band-style overlay still in
regular use; chart vendors typically default to period = 20,
percent = 0.025 (2.5 %).
§Example
use wickra_core::{Indicator, MaEnvelope};
let mut indicator = MaEnvelope::new(20, 0.025).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl MaEnvelope
impl MaEnvelope
Sourcepub fn new(period: usize, percent: f64) -> Result<Self>
pub fn new(period: usize, percent: f64) -> Result<Self>
Construct a new Moving Average Envelope.
§Errors
Returns Error::PeriodZero if period == 0 and
Error::NonPositiveMultiplier if percent is not strictly positive
and finite.
Trait Implementations§
Source§impl Clone for MaEnvelope
impl Clone for MaEnvelope
Source§fn clone(&self) -> MaEnvelope
fn clone(&self) -> MaEnvelope
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MaEnvelope
impl Debug for MaEnvelope
Source§impl Indicator for MaEnvelope
impl Indicator for MaEnvelope
Source§type Output = MaEnvelopeOutput
type Output = MaEnvelopeOutput
Type of one output value.
Source§fn update(&mut self, input: f64) -> Option<MaEnvelopeOutput>
fn update(&mut self, input: f64) -> Option<MaEnvelopeOutput>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for MaEnvelope
impl RefUnwindSafe for MaEnvelope
impl Send for MaEnvelope
impl Sync for MaEnvelope
impl Unpin for MaEnvelope
impl UnsafeUnpin for MaEnvelope
impl UnwindSafe for MaEnvelope
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
Run the indicator over a slice of inputs in order, returning one output (or
None during warmup) per input.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more