pub struct Mama { /* private fields */ }Expand description
Ehlers’ MESA Adaptive Moving Average (MAMA).
MAMA adapts its smoothing constant from the rate-of-change of price phase, derived via a truncated Hilbert transform — full math in “Cycle Analytics for Traders” (Ehlers 2013, ch. 8) and the original 2001 MESA paper.
The two-parameter (fast_limit, slow_limit) is the range over which the
adaptive alpha can vary; defaults (0.5, 0.05) match the canonical
EasyLanguage implementation. The companion FAMA is `mama * 0.5 * fast_limit
- fama_prev * (1 - 0.5 * fast_limit)`, lagging MAMA so crossovers signal trend reversals.
The indicator emits both lines as a MamaOutput. Use the crate::Fama wrapper
in this module to expose just the slow line if needed (e.g. for chaining).
§Example
use wickra_core::{Indicator, Mama};
let mut mama = Mama::new(0.5, 0.05).unwrap();
let mut last = None;
for i in 0..100 {
last = mama.update(100.0 + (f64::from(i) * 0.2).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl Mama
impl Mama
Sourcepub fn new(fast_limit: f64, slow_limit: f64) -> Result<Self>
pub fn new(fast_limit: f64, slow_limit: f64) -> Result<Self>
Construct with custom (fast_limit, slow_limit) adaptive alpha bounds.
§Errors
Returns Error::InvalidPeriod if either limit is outside (0, 1]
or if slow_limit > fast_limit.
Sourcepub const fn value(&self) -> Option<MamaOutput>
pub const fn value(&self) -> Option<MamaOutput>
Current (mama, fama) pair if available.
Trait Implementations§
Source§impl Indicator for Mama
impl Indicator for Mama
Source§type Output = MamaOutput
type Output = MamaOutput
Source§fn update(&mut self, input: f64) -> Option<MamaOutput>
fn update(&mut self, input: f64) -> Option<MamaOutput>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for Mama
impl RefUnwindSafe for Mama
impl Send for Mama
impl Sync for Mama
impl Unpin for Mama
impl UnsafeUnpin for Mama
impl UnwindSafe for Mama
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>>
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
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>
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>
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