Skip to content

Add Rachev Ratio indicator - #9847

Open
Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:feature-7648-rachev-ratio
Open

Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:feature-7648-rachev-ratio

Conversation

@Amadeus-22

@Amadeus-22 Amadeus-22 commented Sep 29, 2026 •

Copy link
Copy Markdown

Description

Adds the RachevRatio indicator and the RACHEV helper in QCAlgorithm.Indicators.cs.

The Rachev ratio (Biglova, Ortobelli, Rachev and Stoyanov, 2004) is the expected tail return of the best outcomes divided by the expected tail loss of the worst outcomes, over a rolling window of one-period returns:

RR = ETL_alpha(Rf - R) / ETL_beta(R - Rf)

Parameters: period (number of returns), alpha (right-tail probability, default 0.05), beta (left-tail probability, default 0.05), riskFreeRate (per period, default 0). The tail expectations use the historical estimator with fractional weighting of the boundary observation (Acerbi and Tasche, 2002), so tails such as 0.05 * 252 = 12.6 observations are handled exactly. The indicator is ready after period + 1 data points and returns 0 when the tail loss is zero.

Related Issue

Closes #7648

Motivation and Context

Adds a reward-to-risk ratio for non-Gaussian returns, complementing SharpeRatio and SortinoRatio.

Requires Documentation Change

Yes, add the indicator to the list of supported indicators.

How Has This Been Tested?

  • dotnet test Tests/QuantConnect.Tests.csproj --filter "FullyQualifiedName~RachevRatio": 24 passed, 2 skipped (period 1 is rejected by the constructor in the reset contract fixture). AlgorithmIndicatorsTests and DocumentationAttributeTest also pass. I did not run the full suite locally.
  • RachevRatioTests inherits CommonIndicatorTests<IndicatorDataPoint> and compares against Tests/TestData/spy_rachev_ratio.csv for three parameter sets (default, alpha 0.1 / beta 0.05, risk-free rate 0.0001) within 1e-6, plus a hand-computed case, the zero tail loss case and parameter validation.
  • Reference values were generated with skfolio 1.4.9 (skfolio.measures.cvar) on the SPY daily prices already in Tests/TestData/spy_valueatrisk.csv, over a rolling 252-return window:
Test data generator
"""
Reference values for the RachevRatio indicator (QuantConnect/Lean#7648).

Rachev ratio (Biglova, Ortobelli, Rachev, Stoyanov, 2004):
    RR = CVaR_(1-alpha)(rf - r) / CVaR_(1-beta)(r - rf)
The tail expectations are computed with skfolio.measures.cvar, the historical
CVaR estimator with fractional weighting of the boundary observation
(Acerbi & Tasche, 2002). Prices are LEAN's daily SPY data, taken from
Tests/TestData/spy_valueatrisk.csv, and returns are simple one-period returns.
"""
import sys
import numpy as np
import pandas as pd
from skfolio.measures import cvar

PERIOD = 252

def rachev(window, alpha, beta, rf):
    excess = window - rf
    return cvar(-excess, beta=1 - alpha) / cvar(excess, beta=1 - beta)

source, target = sys.argv[1], sys.argv[2]
data = pd.read_csv(source, usecols=["date", "open", "high", "low", "close", "volume"])
data["returns"] = data["close"].pct_change()
returns = data["returns"].to_numpy()

cases = {
    "rachev_ratio": (0.05, 0.05, 0.0),
    "rachev_ratio_alpha_0.1_beta_0.05": (0.1, 0.05, 0.0),
    "rachev_ratio_rf_0.0001": (0.05, 0.05, 0.0001),
}
for column, (alpha, beta, rf) in cases.items():
    values = np.full(len(data), np.nan)
    for i in range(PERIOD, len(data)):
        values[i] = rachev(returns[i - PERIOD + 1:i + 1], alpha, beta, rf)
    data[column] = values

data.to_csv(target, index=False, float_format="%.10g")

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. (new tests and the helper/documentation fixtures pass; full suite not run locally)
  • My branch follows the naming convention feature-<issue#>-<description>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rachev Ratio Indicator

1 participant