pub struct PointAndFigureBars { /* private fields */ }Expand description
Point-and-Figure bar builder using the fixed box-size, N-box reversal method.
Price is quantised to a box_size grid (each close maps to the box that
contains it). An X column extends upward while price makes new box highs; an
O column extends downward while price makes new box lows. A reversal needs
price to move reversal boxes against the column, at which point the current
column is closed (returned from BarBuilder::update) and a new column
starts one box offset from the prior extreme.
- The first candle seeds the grid box and prints no column.
- The first one-box move sets the initial column direction.
- At most one column completes per candle, so
updatereturns an empty vector or a singlePnfColumn.
Closes are mapped to their containing box via floor(close / box_size) for
both directions, so the construction is fully deterministic.
§Example
use wickra_core::{BarBuilder, Candle, PointAndFigureBars};
let flat = |price: f64| Candle::new(price, price, price, price, 1.0, 0).unwrap();
let mut pnf = PointAndFigureBars::new(1.0, 3).unwrap();
pnf.update(flat(10.0)); // seed
pnf.update(flat(15.0)); // X column up to 15
let cols = pnf.update(flat(12.0)); // 3-box reversal closes the X column
assert_eq!(cols.len(), 1);
assert_eq!(cols[0].direction, 1);Implementations§
Source§impl PointAndFigureBars
impl PointAndFigureBars
Sourcepub fn new(box_size: f64, reversal: usize) -> Result<Self>
pub fn new(box_size: f64, reversal: usize) -> Result<Self>
Construct a Point-and-Figure builder with the given box size and reversal (in boxes).
§Errors
Returns Error::InvalidPeriod if box_size is not finite and positive,
and Error::PeriodZero if reversal is zero.
Trait Implementations§
Source§impl BarBuilder for PointAndFigureBars
impl BarBuilder for PointAndFigureBars
Source§impl Clone for PointAndFigureBars
impl Clone for PointAndFigureBars
Source§fn clone(&self) -> PointAndFigureBars
fn clone(&self) -> PointAndFigureBars
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 PointAndFigureBars
impl RefUnwindSafe for PointAndFigureBars
impl Send for PointAndFigureBars
impl Sync for PointAndFigureBars
impl Unpin for PointAndFigureBars
impl UnsafeUnpin for PointAndFigureBars
impl UnwindSafe for PointAndFigureBars
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