pub struct RelativeStrengthAB { /* private fields */ }Expand description
Comparative relative strength of asset a against asset b.
Each update receives one (a, b) price pair and forms the ratio line
a / b. The ratio is then smoothed with a simple moving average and run
through an RSI, so a single indicator gives you the relative-strength level,
its trend, and whether that trend is overbought or oversold:
ratio = a / b
ratio_ma = SMA(ratio, ma_period)
ratio_rsi = RSI(ratio, rsi_period)A rising ratio means a is outperforming b; ratio_ma shows the trend of
that outperformance and ratio_rsi flags exhaustion (e.g. > 70 after a
strong run of a over b). This is the classic “asset-vs-asset” or
“asset-vs-index” rotation screen.
The first output appears once both the moving average and the RSI have
warmed up; the ratio itself is computed from the first valid pair. A
non-finite price or a zero denominator (b == 0) makes the ratio undefined
and is skipped, leaving the internal averages untouched.
§Example
use wickra_core::{Indicator, RelativeStrengthAB};
let mut rs = RelativeStrengthAB::new(5, 5).unwrap();
let mut last = None;
for _ in 0..20 {
last = rs.update((200.0, 100.0)); // ratio is a constant 2.0
}
let out = last.unwrap();
assert!((out.ratio - 2.0).abs() < 1e-12);
assert!((out.ratio_ma - 2.0).abs() < 1e-12);
// A flat ratio has no gains or losses, so its RSI sits at the neutral 50.
assert!((out.ratio_rsi - 50.0).abs() < 1e-9);Implementations§
Source§impl RelativeStrengthAB
impl RelativeStrengthAB
Sourcepub fn new(ma_period: usize, rsi_period: usize) -> Result<Self>
pub fn new(ma_period: usize, rsi_period: usize) -> Result<Self>
Construct a new comparative relative-strength indicator.
ma_period is the moving-average look-back of the ratio; rsi_period
is the RSI look-back of the ratio.
§Errors
Returns Error::PeriodZero if either period
is zero.
Sourcepub const fn rsi_period(&self) -> usize
pub const fn rsi_period(&self) -> usize
RSI look-back of the ratio.
Trait Implementations§
Source§impl Clone for RelativeStrengthAB
impl Clone for RelativeStrengthAB
Source§fn clone(&self) -> RelativeStrengthAB
fn clone(&self) -> RelativeStrengthAB
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 RelativeStrengthAB
impl Debug for RelativeStrengthAB
Source§impl Indicator for RelativeStrengthAB
impl Indicator for RelativeStrengthAB
Source§type Output = RelativeStrengthOutput
type Output = RelativeStrengthOutput
Source§fn update(&mut self, input: (f64, f64)) -> Option<RelativeStrengthOutput>
fn update(&mut self, input: (f64, f64)) -> Option<RelativeStrengthOutput>
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 RelativeStrengthAB
impl RefUnwindSafe for RelativeStrengthAB
impl Send for RelativeStrengthAB
impl Sync for RelativeStrengthAB
impl Unpin for RelativeStrengthAB
impl UnsafeUnpin for RelativeStrengthAB
impl UnwindSafe for RelativeStrengthAB
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