pub struct RogersSatchellVolatility { /* private fields */ }Expand description
Rogers-Satchell Volatility — a drift-free OHLC realised-volatility estimator.
Rogers, Satchell & Yoon (1994) extended the Garman-Klass framework to handle non-zero drift between bars without introducing the bias the Garman-Klass estimator picks up in trending markets. The per-bar sample is
s_t = ln(H_t / C_t) · ln(H_t / O_t) + ln(L_t / C_t) · ln(L_t / O_t)and the indicator returns the annualised square root of the rolling
mean of s_t:
out = sqrt(max(mean(s_t over `period`), 0)) · sqrt(trading_periods) · 100The estimator is exact under a Brownian Motion with arbitrary drift —
the drift component cancels out algebraically. Each per-bar sample is
also guaranteed non-negative (both products contribute non-negative
terms by construction: H >= O,C and L <= O,C), so the rolling mean
cannot drift below zero except through FP cancellation.
§Example
use wickra_core::{Candle, Indicator, RogersSatchellVolatility};
let mut indicator = RogersSatchellVolatility::new(20, 252).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let candle = Candle::new(base, base + 2.0, base - 2.0, base + 0.5, 1.0, i64::from(i))
.unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl RogersSatchellVolatility
impl RogersSatchellVolatility
Sourcepub fn new(period: usize, trading_periods: usize) -> Result<Self>
pub fn new(period: usize, trading_periods: usize) -> Result<Self>
Construct a Rogers-Satchell Volatility estimator.
period is the rolling window of bars; trading_periods is the
annualisation factor (252 daily, 52 weekly, 12 monthly, or
1 for raw per-bar volatility).
§Errors
Returns Error::PeriodZero if either parameter is 0.
Trait Implementations§
Source§impl Clone for RogersSatchellVolatility
impl Clone for RogersSatchellVolatility
Source§fn clone(&self) -> RogersSatchellVolatility
fn clone(&self) -> RogersSatchellVolatility
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RogersSatchellVolatility
impl Debug for RogersSatchellVolatility
Source§impl Indicator for RogersSatchellVolatility
impl Indicator for RogersSatchellVolatility
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for RogersSatchellVolatility
impl RefUnwindSafe for RogersSatchellVolatility
impl Send for RogersSatchellVolatility
impl Sync for RogersSatchellVolatility
impl Unpin for RogersSatchellVolatility
impl UnsafeUnpin for RogersSatchellVolatility
impl UnwindSafe for RogersSatchellVolatility
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.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