pub struct PerpetualPremiumIndex { /* private fields */ }Expand description
Perpetual Premium Index — the perpetual’s mark price relative to the spot index it tracks, as a fraction.
premium = (mark_price − index_price) / index_priceA perpetual swap is pegged to spot by the funding mechanism, but it can still trade at a premium (above spot) or discount (below). A positive premium signals net long demand willing to pay up to hold the perp — bullish positioning, and the proximate driver of positive funding; a negative premium signals the reverse. Sustained extremes flag crowded positioning ripe for a funding-driven mean reversion.
The output is centred on zero and dimensionless (a fraction; multiply by 100
for percent). index_price is validated strictly positive on the tick, so the
division is always defined. It is stateless — each tick yields one value (no
warmup). Each update is O(1).
§Example
use wickra_core::{DerivativesTick, Indicator, PerpetualPremiumIndex};
let mut indicator = PerpetualPremiumIndex::new();
// Mark 101 vs index 100 -> +1% premium.
let tick = DerivativesTick::new(0.0, 101.0, 100.0, 101.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0).unwrap();
let premium = indicator.update(tick).unwrap();
assert!((premium - 0.01).abs() < 1e-12);Implementations§
Source§impl PerpetualPremiumIndex
impl PerpetualPremiumIndex
Sourcepub const fn new() -> PerpetualPremiumIndex
pub const fn new() -> PerpetualPremiumIndex
Construct a new Perpetual Premium Index. The indicator is parameter-free.
Trait Implementations§
Source§impl Clone for PerpetualPremiumIndex
impl Clone for PerpetualPremiumIndex
Source§fn clone(&self) -> PerpetualPremiumIndex
fn clone(&self) -> PerpetualPremiumIndex
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 PerpetualPremiumIndex
impl Debug for PerpetualPremiumIndex
Source§impl Default for PerpetualPremiumIndex
impl Default for PerpetualPremiumIndex
Source§fn default() -> PerpetualPremiumIndex
fn default() -> PerpetualPremiumIndex
Source§impl Indicator for PerpetualPremiumIndex
impl Indicator for PerpetualPremiumIndex
Source§type Input = DerivativesTick
type Input = DerivativesTick
f64 for a price, or Candle / Tick).Source§fn update(&mut self, tick: DerivativesTick) -> Option<f64>
fn update(&mut self, tick: DerivativesTick) -> 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 PerpetualPremiumIndex
impl RefUnwindSafe for PerpetualPremiumIndex
impl Send for PerpetualPremiumIndex
impl Sync for PerpetualPremiumIndex
impl Unpin for PerpetualPremiumIndex
impl UnsafeUnpin for PerpetualPremiumIndex
impl UnwindSafe for PerpetualPremiumIndex
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