pub struct Tii { /* private fields */ }Expand description
M.H. Pee’s Trend Intensity Index — a [0, 100] oscillator that measures
what fraction of the recent SMA deviations are positive.
First, compute an SMA(close, sma_period) (canonical sma_period = 60).
On each bar t that the SMA is defined, compute the deviation
dev_t = close_t − SMA_t. Then, over the most recent dev_period
deviations (canonical dev_period = 30, i.e. sma_period / 2), sum the
positive and negative magnitudes separately:
SD_pos = Σ_{i ∈ window, dev_i > 0} dev_i
SD_neg = Σ_{i ∈ window, dev_i < 0} |dev_i|
TII = 100 · SD_pos / (SD_pos + SD_neg)TII is bounded in [0, 100]: high readings (> 80) signal a sustained
uptrend (most recent closes above the SMA), low readings (< 20) a
sustained downtrend. A perfectly flat window produces 50 (every deviation
is zero, so the indicator falls back to its neutral mid-point).
The first output is emitted once both the SMA is ready (sma_period
inputs) and the deviation ring is full (dev_period − 1 more inputs):
warmup = sma_period + dev_period − 1.
§Example
use wickra_core::{Indicator, Tii};
let mut indicator = Tii::new(20, 10).unwrap();
let mut last = None;
for i in 0..60 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl Tii
impl Tii
Sourcepub fn new(sma_period: usize, dev_period: usize) -> Result<Self>
pub fn new(sma_period: usize, dev_period: usize) -> Result<Self>
Construct a new TII with the SMA period and the deviation window length.
The canonical Pee parameters are (sma_period = 60, dev_period = 30);
expose them as the Python defaults.
§Errors
Returns Error::PeriodZero if either period is 0.
Trait Implementations§
Source§impl Indicator for Tii
impl Indicator for Tii
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> 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 Tii
impl RefUnwindSafe for Tii
impl Send for Tii
impl Sync for Tii
impl Unpin for Tii
impl UnsafeUnpin for Tii
impl UnwindSafe for Tii
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