pub struct PerformanceCalculator;Expand description
Stateless calculator for portfolio performance metrics.
Implementations§
Source§impl PerformanceCalculator
impl PerformanceCalculator
Sourcepub fn sharpe_ratio(returns: &[f64], risk_free_rate: f64) -> f64
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.
Sourcepub fn sortino_ratio(returns: &[f64], risk_free_rate: f64, target: f64) -> f64
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.
Sourcepub fn calmar_ratio(returns: &[f64]) -> f64
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.
Sourcepub fn omega_ratio(returns: &[f64], threshold: f64) -> f64
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.
Sourcepub fn information_ratio(returns: &[f64], benchmark_returns: &[f64]) -> f64
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.
Sourcepub fn max_drawdown(returns: &[f64]) -> f64
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.
Sourcepub fn cagr(returns: &[f64], periods_per_year: f64) -> f64
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.
Sourcepub fn compute_all(
returns: &[f64],
benchmark: Option<&[f64]>,
risk_free_rate: f64,
) -> PerformanceMetrics
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.