Skip to main content

RollingWindow

Struct RollingWindow 

Source
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

Source

pub fn new(window_size: usize) -> Self

Create a new rolling window calculator.

§Arguments
  • window_size - Number of periods in the window
Source

pub fn returns(&self, equity: &[Decimal]) -> Result<Vec<Decimal>, MetricsError>

Calculate rolling returns.

Returns the period return for each window.

Source

pub fn volatility( &self, equity: &[Decimal], ) -> Result<Vec<Decimal>, MetricsError>

Calculate rolling volatility (standard deviation of returns).

Source

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 curve
  • risk_free_rate - Annual risk-free rate
  • periods_per_year - Trading periods per year
Source

pub fn max_drawdown( &self, equity: &[Decimal], ) -> Result<Vec<Decimal>, MetricsError>

Calculate rolling maximum drawdown.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.