pub struct VolumeBars { /* private fields */ }Expand description
Volume bar builder — emits a bar each time accumulated volume reaches
volume_per_bar.
Where TickBars sample on trade count, volume bars sample on
traded quantity: a bar closes once the candles fed into it have accumulated at
least volume_per_bar of volume. This gives each bar roughly equal participation,
which de-emphasises quiet periods and resolves bursts of heavy trading into more
bars. The companion DollarBars builder uses traded value
(price × volume) instead, which is more robust to price-level drift over long
histories.
The bar is candle-granular: at most one bar closes per candle, and the candle
that crosses the threshold closes the bar with its overshoot included (the next
bar starts fresh). BarBuilder::update therefore returns either an empty vector
or a single VolumeBar.
§Example
use wickra_core::{BarBuilder, Candle, VolumeBars};
let c = |cl, v| Candle::new(cl, cl, cl, cl, v, 0).unwrap();
let mut bars = VolumeBars::new(100.0).unwrap();
assert!(bars.update(c(10.0, 60.0)).is_empty());
let out = bars.update(c(10.5, 60.0)); // 120 >= 100 -> close
assert_eq!(out.len(), 1);
assert_eq!(out[0].volume, 120.0);Implementations§
Source§impl VolumeBars
impl VolumeBars
Sourcepub fn new(volume_per_bar: f64) -> Result<Self>
pub fn new(volume_per_bar: f64) -> Result<Self>
Construct a volume-bar builder with the given volume threshold.
§Errors
Returns Error::InvalidPeriod if volume_per_bar is not finite and positive.
Sourcepub const fn volume_per_bar(&self) -> f64
pub const fn volume_per_bar(&self) -> f64
Configured volume threshold per bar.
Sourcepub const fn accumulated(&self) -> f64
pub const fn accumulated(&self) -> f64
Volume accumulated into the in-progress bar.
Trait Implementations§
Source§impl BarBuilder for VolumeBars
impl BarBuilder for VolumeBars
Source§impl Clone for VolumeBars
impl Clone for VolumeBars
Source§fn clone(&self) -> VolumeBars
fn clone(&self) -> VolumeBars
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for VolumeBars
impl RefUnwindSafe for VolumeBars
impl Send for VolumeBars
impl Sync for VolumeBars
impl Unpin for VolumeBars
impl UnsafeUnpin for VolumeBars
impl UnwindSafe for VolumeBars
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