pub struct VolatilityCone { /* private fields */ }Expand description
Volatility Cone — the current realized volatility positioned within the historical range (“cone”) of realized volatilities over a lookback window.
r_t = ln(close_t / close_{t−1})
vol_t = stddev_sample(r over window) (rolling realized volatility)
cone = { min, median, max, percentile } of vol over the last `lookback`A volatility cone (Burghardt & Lane 1990) shows whether current volatility is
high or low relative to its own history, rather than as an absolute number.
This streaming form tracks one horizon: it maintains the rolling realized
volatility of log returns over window, then reports the latest reading
(current) alongside the min, median, max and percentile rank of that
volatility series over the trailing lookback. current always lies within
[min, max] because it is itself the newest member of the lookback set.
Only the candle’s close is used (the log-return series); the high and low
are ignored. The volatility is per-period (sample stddev of log returns, not
annualised) — multiply by √trading_periods for an annual figure. Each
update is O(lookback log lookback) from sorting the envelope.
Non-positive closes are ignored (the log return would be undefined): the tick is dropped, state is left untouched, and the last value is returned.
§Example
use wickra_core::{Candle, Indicator, VolatilityCone};
let mut indicator = VolatilityCone::new(20, 60).unwrap();
let mut last = None;
for i in 0..120 {
let c = 100.0 + (f64::from(i) * 0.3).sin() * 5.0;
let candle = Candle::new(c, c + 1.0, c - 1.0, c, 1_000.0, 0).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl VolatilityCone
impl VolatilityCone
Sourcepub fn new(window: usize, lookback: usize) -> Result<Self>
pub fn new(window: usize, lookback: usize) -> Result<Self>
Construct a new volatility-cone indicator.
window is the realized-volatility estimation window; lookback is the
number of volatility readings forming the historical cone.
§Errors
Returns Error::PeriodZero if either argument is 0, or
Error::InvalidPeriod if window < 2 (a sample stddev needs two
returns) or lookback < 2 (an envelope needs at least two readings).
Sourcepub const fn value(&self) -> Option<VolatilityConeOutput>
pub const fn value(&self) -> Option<VolatilityConeOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for VolatilityCone
impl Clone for VolatilityCone
Source§fn clone(&self) -> VolatilityCone
fn clone(&self) -> VolatilityCone
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 VolatilityCone
impl Debug for VolatilityCone
Source§impl Indicator for VolatilityCone
impl Indicator for VolatilityCone
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = VolatilityConeOutput
type Output = VolatilityConeOutput
Source§fn update(&mut self, candle: Candle) -> Option<VolatilityConeOutput>
fn update(&mut self, candle: Candle) -> Option<VolatilityConeOutput>
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 VolatilityCone
impl RefUnwindSafe for VolatilityCone
impl Send for VolatilityCone
impl Sync for VolatilityCone
impl Unpin for VolatilityCone
impl UnsafeUnpin for VolatilityCone
impl UnwindSafe for VolatilityCone
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