pub struct VwapState { /* private fields */ }Expand description
Incremental VWAP (cumulative or rolling). Call VwapState::reset at session open if desired.
§Examples
use finance_solution::stocks::ta::{VwapParams, VwapState};
let mut v = VwapState::new(VwapParams::cumulative_typical()).unwrap();
let a = v.push(10.0, 9.0, 9.5, 100.0).unwrap().unwrap();
let b = v.push(11.0, 10.0, 10.5, 200.0).unwrap().unwrap();
assert!(b > a || (b - a).abs() < 1.0); // volume-weighted drift
v.reset(); // e.g. new regular trading day — caller decides
assert!(v.push(10.0, 10.0, 10.0, 50.0).unwrap().unwrap() - 10.0 < 1e-12);Implementations§
Source§impl VwapState
impl VwapState
pub fn new(params: VwapParams) -> FinanceResult<Self>
pub fn from_history( params: VwapParams, high: &[f64], low: &[f64], close: &[f64], volume: &[f64], ) -> FinanceResult<Self>
pub fn params(&self) -> VwapParams
pub fn push( &mut self, high: f64, low: f64, close: f64, volume: f64, ) -> FinanceResult<Option<f64>>
pub fn last(&self) -> Option<f64>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VwapState
impl RefUnwindSafe for VwapState
impl Send for VwapState
impl Sync for VwapState
impl Unpin for VwapState
impl UnsafeUnpin for VwapState
impl UnwindSafe for VwapState
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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