pub struct TickBars { /* private fields */ }Expand description
Tick bar builder — emits one OHLCV bar for every ticks input candles.
Classic time bars (1-minute, 1-hour) sample the market on a clock; tick bars
sample it on activity by grouping a fixed number of trades — here modelled as a
fixed number of input candles. In fast markets a tick bar closes quickly; in
quiet markets it takes longer, so each bar carries roughly equal information
content. This is the simplest of the information-driven bar types; the
VolumeBars and DollarBars builders
extend the idea to equal traded volume and equal traded value respectively.
The open is the first candle’s open, the high and low are the extremes across the
group, the close is the last candle’s close, and the volume is the group sum.
Exactly one bar completes every ticks candles, so BarBuilder::update
returns either an empty vector or a single TickBar.
§Example
use wickra_core::{BarBuilder, Candle, TickBars};
let c = |o, h, l, cl, v| Candle::new(o, h, l, cl, v, 0).unwrap();
let mut bars = TickBars::new(3).unwrap();
assert!(bars.update(c(10.0, 11.0, 9.0, 10.5, 100.0)).is_empty());
assert!(bars.update(c(10.5, 12.0, 10.0, 11.0, 150.0)).is_empty());
let out = bars.update(c(11.0, 11.5, 10.8, 11.2, 120.0));
assert_eq!(out.len(), 1);
assert_eq!(out[0].volume, 370.0);Implementations§
Trait Implementations§
Source§impl BarBuilder for TickBars
impl BarBuilder for TickBars
Auto Trait Implementations§
impl Freeze for TickBars
impl RefUnwindSafe for TickBars
impl Send for TickBars
impl Sync for TickBars
impl Unpin for TickBars
impl UnsafeUnpin for TickBars
impl UnwindSafe for TickBars
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