pub struct Alpha { /* private fields */ }Expand description
Rolling Jensen’s Alpha.
Each update receives one (asset_return, benchmark_return) pair. Over
the trailing window of period pairs:
Beta = cov(asset, bench) / var(bench)
Alpha = mean(asset) − ( risk_free + Beta · (mean(bench) − risk_free) )Alpha is the risk-adjusted excess return — the slice of the asset’s performance that cannot be explained by simple exposure to the benchmark. A positive alpha indicates outperformance net of the market premium implied by the asset’s beta; negative alpha is the opposite.
Population covariance and variance are used (matching common
implementations in pandas-ta / quantstats); the rolling estimator stays
unbiased in the steady state for fixed period.
If the benchmark is flat (var(bench) = 0) the indicator falls back to
alpha = mean(asset) − risk_free — the asset’s mean excess return, with
no market-risk adjustment, since the regression slope is undefined.
Each update is O(1).
Implementations§
Trait Implementations§
Source§impl Indicator for Alpha
impl Indicator for Alpha
Source§type Input = (f64, f64)
type Input = (f64, f64)
f64 for a price, or Candle / Tick).Source§fn update(&mut self, input: (f64, f64)) -> Option<f64>
fn update(&mut self, input: (f64, 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 Alpha
impl RefUnwindSafe for Alpha
impl Send for Alpha
impl Sync for Alpha
impl Unpin for Alpha
impl UnsafeUnpin for Alpha
impl UnwindSafe for Alpha
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