pub struct BomarBands { /* private fields */ }Expand description
Bomar Bands: percentage bands whose width adapts so that a fixed coverage
fraction of recent closes falls inside them.
The Bomar Bands predate Bollinger Bands; John Bollinger cites them as an
inspiration — percentage bands around a moving average, with the percentage
tuned so a fixed share (classically ~85%) of price stayed within. Wickra
realises that idea deterministically: the half-width is the coverage
quantile of the relative deviations from the midline, so by construction
coverage of the window’s closes lie inside the bands.
middle = SMA(close, period)
dev_i = | close_i / middle − 1 | // relative distance from midline
p = coverage-quantile of { dev_i } // type-7 interpolation
upper = middle + |middle| · p
lower = middle − |middle| · pUnlike the fixed-percentage MaEnvelope, the offset
here is data-driven: the bands widen in turbulent regimes and tighten in
quiet ones without a volatility input. Unlike Bollinger Bands, the width is
an order statistic of the actual deviations rather than a multiple of the
standard deviation, so it is unaffected by the shape of the tails beyond the
coverage rank. When the midline is zero the relative deviation is
undefined and the bands collapse onto the midline.
§Example
use wickra_core::{BomarBands, Indicator};
let mut indicator = BomarBands::new(20, 0.85).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i % 7));
}
assert!(last.is_some());Implementations§
Source§impl BomarBands
impl BomarBands
Sourcepub fn new(period: usize, coverage: f64) -> Result<Self>
pub fn new(period: usize, coverage: f64) -> Result<Self>
Construct new Bomar Bands.
coverage is the target fraction of closes to contain, in (0.0, 1.0].
§Errors
Returns Error::PeriodZero if period == 0, or
Error::InvalidParameter if coverage is not a finite value in
(0.0, 1.0].
Trait Implementations§
Source§impl Clone for BomarBands
impl Clone for BomarBands
Source§fn clone(&self) -> BomarBands
fn clone(&self) -> BomarBands
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BomarBands
impl Debug for BomarBands
Source§impl Indicator for BomarBands
impl Indicator for BomarBands
Source§type Output = BomarBandsOutput
type Output = BomarBandsOutput
Source§fn update(&mut self, value: f64) -> Option<BomarBandsOutput>
fn update(&mut self, value: f64) -> Option<BomarBandsOutput>
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 BomarBands
impl RefUnwindSafe for BomarBands
impl Send for BomarBands
impl Sync for BomarBands
impl Unpin for BomarBands
impl UnsafeUnpin for BomarBands
impl UnwindSafe for BomarBands
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