pub struct RunBars { /* private fields */ }Expand description
Run bar builder — a simplified form of López de Prado’s run bars.
A run is an uninterrupted sequence of same-signed ticks: a streak of up-ticks
(a buy run) or down-ticks (a sell run), with unchanged closes extending the
current run. This builder counts the current run’s length and closes a bar when
it reaches run_length; a tick in the opposite direction restarts the run from
one. Where ImbalanceBars sample on the net signed
imbalance (which oscillating flow can cancel back to zero), run bars sample on
persistence: they fire only when the market pushes the same way without
interruption, making them a cleaner sequential-trend detector.
Simplification. The full method estimates a dynamic expected run length from an EWMA and can weight runs by volume or traded value. This builder uses a fixed run-length threshold on unweighted ticks. See López de Prado (2018), ch. 2, for the adaptive estimator and weighted variants.
At most one bar closes per candle, so BarBuilder::update returns either an
empty vector or a single RunBar.
§Example
use wickra_core::{BarBuilder, Candle, RunBars};
let flat = |price: f64| Candle::new(price, price, price, price, 1.0, 0).unwrap();
let mut bars = RunBars::new(3).unwrap();
bars.update(flat(10.0)); // seed
bars.update(flat(11.0)); // run 1
bars.update(flat(12.0)); // run 2
let out = bars.update(flat(13.0)); // run 3 -> close
assert_eq!(out.len(), 1);
assert_eq!(out[0].direction, 1);Implementations§
Trait Implementations§
Source§impl BarBuilder for RunBars
impl BarBuilder for RunBars
Auto Trait Implementations§
impl Freeze for RunBars
impl RefUnwindSafe for RunBars
impl Send for RunBars
impl Sync for RunBars
impl Unpin for RunBars
impl UnsafeUnpin for RunBars
impl UnwindSafe for RunBars
Blanket Implementations§
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