Skip to main content

PerformanceCalculator

Struct PerformanceCalculator 

Source
pub struct PerformanceCalculator;
Expand description

Stateless calculator for portfolio performance metrics.

Implementations§

Source§

impl PerformanceCalculator

Source

pub fn sharpe_ratio(returns: &[f64], risk_free_rate: f64) -> f64

Compute the annualised Sharpe ratio.

(mean_return - risk_free_rate) / std_return * sqrt(252)

Returns 0.0 if returns has fewer than 2 elements or std dev is zero.

Source

pub fn sortino_ratio(returns: &[f64], risk_free_rate: f64, target: f64) -> f64

Compute the annualised Sortino ratio using downside deviation only.

Downside deviation is computed over returns below target.

Returns 0.0 if returns is empty or downside deviation is zero.

Source

pub fn calmar_ratio(returns: &[f64]) -> f64

Compute the Calmar ratio: annualised return / |max_drawdown|.

Uses 252 periods per year. Returns 0.0 if returns is empty or max drawdown is zero.

Source

pub fn omega_ratio(returns: &[f64], threshold: f64) -> f64

Compute the Omega ratio at the given threshold.

sum(max(r - threshold, 0)) / sum(max(threshold - r, 0))

Returns f64::INFINITY if the loss sum is zero and there are gains, or 0.0 if both sums are zero.

Source

pub fn information_ratio(returns: &[f64], benchmark_returns: &[f64]) -> f64

Compute the Information Ratio: active return / tracking error.

Active return = mean(returns - benchmark_returns). Tracking error = std dev of (returns - benchmark_returns).

Returns 0.0 if lengths differ, fewer than 2 observations, or tracking error is zero.

Source

pub fn max_drawdown(returns: &[f64]) -> f64

Compute the maximum peak-to-trough drawdown on the cumulative return series.

Cumulative returns are computed as product of (1 + r) factors. Returns a positive value representing the magnitude of the worst decline, or 0.0 if returns is empty.

Source

pub fn cagr(returns: &[f64], periods_per_year: f64) -> f64

Compute the Compound Annual Growth Rate.

(product(1 + r))^(periods_per_year / n) - 1

Returns 0.0 if returns is empty.

Source

pub fn compute_all( returns: &[f64], benchmark: Option<&[f64]>, risk_free_rate: f64, ) -> PerformanceMetrics

Compute all performance metrics in one pass.

If benchmark is None the information ratio is set to 0.0. risk_free_rate is a per-period (not annualised) rate, matching the frequency of returns.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.