pub struct RollingWindow { /* private fields */ }Expand description
Rolling window calculator for time-series metrics.
§Example
use quant_metrics::RollingWindow;
use rust_decimal_macros::dec;
let equity = vec![dec!(100), dec!(101), dec!(102), dec!(101), dec!(103), dec!(105)];
let rolling = RollingWindow::new(3);
let returns = rolling.returns(&equity).unwrap();
let volatility = rolling.volatility(&equity).unwrap();Implementations§
Source§impl RollingWindow
impl RollingWindow
Sourcepub fn returns(&self, equity: &[Decimal]) -> Result<Vec<Decimal>, MetricsError>
pub fn returns(&self, equity: &[Decimal]) -> Result<Vec<Decimal>, MetricsError>
Calculate rolling returns.
Returns the period return for each window.
Sourcepub fn volatility(
&self,
equity: &[Decimal],
) -> Result<Vec<Decimal>, MetricsError>
pub fn volatility( &self, equity: &[Decimal], ) -> Result<Vec<Decimal>, MetricsError>
Calculate rolling volatility (standard deviation of returns).
Sourcepub fn sharpe(
&self,
equity: &[Decimal],
risk_free_rate: Decimal,
periods_per_year: u32,
) -> Result<Vec<Decimal>, MetricsError>
pub fn sharpe( &self, equity: &[Decimal], risk_free_rate: Decimal, periods_per_year: u32, ) -> Result<Vec<Decimal>, MetricsError>
Calculate rolling Sharpe ratio.
§Arguments
equity- Equity curverisk_free_rate- Annual risk-free rateperiods_per_year- Trading periods per year
Sourcepub fn max_drawdown(
&self,
equity: &[Decimal],
) -> Result<Vec<Decimal>, MetricsError>
pub fn max_drawdown( &self, equity: &[Decimal], ) -> Result<Vec<Decimal>, MetricsError>
Calculate rolling maximum drawdown.
Auto Trait Implementations§
impl Freeze for RollingWindow
impl RefUnwindSafe for RollingWindow
impl Send for RollingWindow
impl Sync for RollingWindow
impl Unpin for RollingWindow
impl UnsafeUnpin for RollingWindow
impl UnwindSafe for RollingWindow
Blanket Implementations§
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
Mutably borrows from an owned value. Read more