pub struct StochState { /* private fields */ }Expand description
Incremental stochastic (fast/full via StochasticParams).
§Examples
use finance_solution::stocks::ta::{StochasticParams, StochState, stochastics};
const P: StochasticParams = StochasticParams::fast(5, 3);
let h: Vec<_> = (0..20).map(|i| 10.0 + i as f64).collect();
let l: Vec<_> = (0..20).map(|i| 9.0 + i as f64).collect();
let c: Vec<_> = (0..20).map(|i| 9.5 + i as f64).collect();
let batch = stochastics(&h, &l, &c, P).unwrap();
let mut st = StochState::new(P).unwrap();
let mut last = None;
for i in 0..20 {
last = st.push(h[i], l[i], c[i]).unwrap();
}
let (bk, bd) = batch.last_kd().unwrap();
let (sk, sd) = last.unwrap();
assert!((bk - sk).abs() < 1e-9 && (bd - sd).abs() < 1e-9);Implementations§
Source§impl StochState
impl StochState
pub fn new(params: StochasticParams) -> FinanceResult<Self>
pub fn from_history( params: StochasticParams, high: &[f64], low: &[f64], close: &[f64], ) -> FinanceResult<Self>
pub fn params(&self) -> StochasticParams
pub fn reset(&mut self)
Sourcepub fn push(
&mut self,
high: f64,
low: f64,
close: f64,
) -> FinanceResult<Option<(f64, f64)>>
pub fn push( &mut self, high: f64, low: f64, close: f64, ) -> FinanceResult<Option<(f64, f64)>>
Returns Some((%K, %D)) when both are defined; %K-only warm-up yields None
until %D is ready (same as batch last_kd semantics for the pair).
For finer control use StochState::push_detail.
Sourcepub fn push_detail(
&mut self,
high: f64,
low: f64,
close: f64,
) -> FinanceResult<StochBarOutput>
pub fn push_detail( &mut self, high: f64, low: f64, close: f64, ) -> FinanceResult<StochBarOutput>
Full detail for this bar (either line may still be warming up).
pub fn last_kd(&self) -> Option<(f64, f64)>
Sourcepub fn push_bars(
&mut self,
high: &[f64],
low: &[f64],
close: &[f64],
) -> FinanceResult<Vec<StochBarOutput>>
pub fn push_bars( &mut self, high: &[f64], low: &[f64], close: &[f64], ) -> FinanceResult<Vec<StochBarOutput>>
Push aligned H/L/C slices (same length) from one streaming payload.
Trait Implementations§
Source§impl Clone for StochState
impl Clone for StochState
Source§fn clone(&self) -> StochState
fn clone(&self) -> StochState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StochState
impl RefUnwindSafe for StochState
impl Send for StochState
impl Sync for StochState
impl Unpin for StochState
impl UnsafeUnpin for StochState
impl UnwindSafe for StochState
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