pub struct FundingImpliedApr { /* private fields */ }Expand description
Funding-Implied APR — the perpetual’s per-interval funding rate scaled to an annualised rate.
APR = funding_rate · intervals_per_yearFunding is paid in small per-interval amounts (commonly every 8 hours, i.e.
1095 intervals per year). Annualising it converts the headline funding number
into the carry cost (or yield) of holding the position for a year, which is far
easier to reason about and to compare against spot lending rates, basis trades,
and other yields. A large positive APR means longs pay a steep carry to shorts
(and vice versa) — the economic incentive behind cash-and-carry and
funding-arbitrage strategies.
The output is a fraction (multiply by 100 for percent) and may be negative.
It is stateless — each tick yields one value (no warmup). Each update is O(1).
§Example
use wickra_core::{DerivativesTick, Indicator, FundingImpliedApr};
// 0.01% per 8h funding -> 0.0001 * 1095 ≈ 10.95% APR.
let mut indicator = FundingImpliedApr::new(1095.0).unwrap();
let tick = DerivativesTick::new(0.0001, 100.0, 100.0, 100.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0).unwrap();
let apr = indicator.update(tick).unwrap();
assert!((apr - 0.1095).abs() < 1e-9);Implementations§
Source§impl FundingImpliedApr
impl FundingImpliedApr
Sourcepub fn new(intervals_per_year: f64) -> Result<Self>
pub fn new(intervals_per_year: f64) -> Result<Self>
Construct a Funding-Implied APR with the number of funding intervals per
year (e.g. 1095 for 8-hour funding, 365 for daily).
§Errors
Returns Error::InvalidParameter if intervals_per_year is not finite
and positive.
Sourcepub const fn intervals_per_year(&self) -> f64
pub const fn intervals_per_year(&self) -> f64
Configured intervals per year.
Trait Implementations§
Source§impl Clone for FundingImpliedApr
impl Clone for FundingImpliedApr
Source§fn clone(&self) -> FundingImpliedApr
fn clone(&self) -> FundingImpliedApr
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 FundingImpliedApr
impl Debug for FundingImpliedApr
Source§impl Indicator for FundingImpliedApr
impl Indicator for FundingImpliedApr
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 FundingImpliedApr
impl RefUnwindSafe for FundingImpliedApr
impl Send for FundingImpliedApr
impl Sync for FundingImpliedApr
impl Unpin for FundingImpliedApr
impl UnsafeUnpin for FundingImpliedApr
impl UnwindSafe for FundingImpliedApr
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