Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Risk Reward

From Leeroopedia
Revision as of 14:33, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Avhz_RustQuant_Risk_Reward.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Mathematics, Statistics
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for computing portfolio risk-reward measures provided by the RustQuant library.

Description

The PortfolioMeasures struct provides a collection of classical risk-adjusted return metrics used in portfolio performance evaluation. The struct holds the key portfolio statistics needed to compute various ratios:

Fields:

  • r_p (f64) -- average return of the portfolio.
  • r (f64) -- risk-free return over the same period.
  • beta_p (f64) -- beta of the portfolio (systematic risk).
  • sigma_p (f64) -- standard deviation of portfolio returns.
  • sigma_down (f64) -- downside standard deviation (semistandard deviation).
  • var (f64) -- Value-at-Risk.
  • r_m (f64) -- expected market return.

Methods:

  • treynors_ratio() -- Treynor (1965) ratio: (r_p - r) / beta_p. Measures excess return per unit of systematic risk.
  • sharpe_ratio() -- Sharpe (1966) ratio: (r_p - r) / sigma_p. Measures excess return per unit of total risk.
  • sortino_ratio() -- Sortino and Price (1994) ratio: (r_p - r) / sigma_down. Measures excess return per unit of downside risk.
  • burke_ratio(drawdowns) -- Burke (1994) ratio: (r_p - r) / sum_of_squared_drawdowns. Takes a slice of drawdown values.
  • return_on_var() -- Return on VaR: r_p / var.
  • jensens_alpha() -- Jensen's Measure: r_p - (r + beta_p * (r_m - r)). Measures the abnormal return above the CAPM prediction.

Usage

Use these measures for portfolio performance evaluation, fund comparison, and risk management. The Sharpe ratio is the most widely used risk-adjusted performance metric. The Sortino ratio is preferred when downside risk is more relevant than total volatility. Jensen's alpha quantifies whether a portfolio manager has added value above the market benchmark.

Code Reference

Source Location

Signature

pub struct PortfolioMeasures {
    r_p: f64,
    r: f64,
    beta_p: f64,
    sigma_p: f64,
    sigma_down: f64,
    var: f64,
    r_m: f64,
}

impl PortfolioMeasures {
    pub fn treynors_ratio(&self) -> f64;
    pub fn sharpe_ratio(&self) -> f64;
    pub fn sortino_ratio(&self) -> f64;
    pub fn burke_ratio(&self, drawdowns: &[f64]) -> f64;
    pub fn return_on_var(&self) -> f64;
    pub fn jensens_alpha(&self) -> f64;
}

Import

use RustQuant::math::PortfolioMeasures;

I/O Contract

Inputs

Name Type Required Description
r_p f64 Yes Average portfolio return.
r f64 Yes Risk-free return over the same period.
beta_p f64 Yes Portfolio beta (systematic risk measure).
sigma_p f64 Yes Standard deviation of portfolio returns.
sigma_down f64 Yes Downside standard deviation (semistandard deviation).
var f64 Yes Value-at-Risk of the portfolio.
r_m f64 Yes Expected market return.
drawdowns &[f64] For burke_ratio() Slice of drawdown values.

Outputs

Name Type Description
treynors_ratio() f64 Excess return per unit of systematic risk.
sharpe_ratio() f64 Excess return per unit of total risk.
sortino_ratio() f64 Excess return per unit of downside risk.
burke_ratio() f64 Excess return per sum of squared drawdowns.
return_on_var() f64 Portfolio return divided by VaR.
jensens_alpha() f64 Abnormal return above CAPM prediction.

Usage Examples

use RustQuant::math::PortfolioMeasures;

let portfolio = PortfolioMeasures {
    r_p: 0.12,        // 12% average return
    r: 0.05,           // 5% risk-free rate
    beta_p: 1.2,       // portfolio beta
    sigma_p: 0.2,      // 20% standard deviation
    sigma_down: 0.1,   // 10% downside deviation
    var: 0.15,         // 15% VaR
    r_m: 0.1,          // 10% expected market return
};

// Risk-adjusted performance ratios
let treynor = portfolio.treynors_ratio();   // (0.12 - 0.05) / 1.2 = 0.0583
let sharpe = portfolio.sharpe_ratio();      // (0.12 - 0.05) / 0.2 = 0.35
let sortino = portfolio.sortino_ratio();    // (0.12 - 0.05) / 0.1 = 0.70
let ret_var = portfolio.return_on_var();    // 0.12 / 0.15 = 0.80
let alpha = portfolio.jensens_alpha();      // 0.12 - (0.05 + 1.2*(0.1-0.05)) = 0.01

// Burke ratio with drawdowns
let drawdowns = vec![0.05, 0.10, 0.20];
let burke = portfolio.burke_ratio(&drawdowns);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment