The Deflated Sharpe Ratio (DSR) is the Probabilistic Sharpe Ratio corrected for the fact that a reported Sharpe ratio is often the best of many strategy variations, parameter combinations, or lookback windows tried during a backtest (multiple testing / selection bias / “backtest overfitting”). It estimates the Sharpe ratio one would expect to observe purely by chance as the maximum of n_trials independent trials under the null hypothesis of no skill, and uses that expected maximum as the benchmark SR* in the Probabilistic Sharpe Ratio formula instead of a naive benchmark such as 0:

\[\text{SR} \cdot = \sqrt{\text{Var} \left[\text{SR\_trials}\right]} \cdot \left[(1 - \text{γ}) \cdot \operatorname{Phi⁻¹}(1 - 1 / N) + \text{γ} \cdot \operatorname{Phi⁻¹}(1 - 1 / (N \cdot e))\right]\]

In the Finance Toolkit this is get_sharpe_ratio with method="deflated"; the Sharpe Ratio page has the function’s full description.

Deflated Sharpe Ratio (DSR) in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_sharpe_ratio as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["SPY", "TLT", "GLD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
    benchmark_ticker=None,
)

toolkit.performance.get_sharpe_ratio(method="deflated")

Which returns:

Date SPY TLT GLD
2021 0.2165 0.0111 0.0003
2022 0.0001 0.0001 0.0011
2023 0.1043 0.0289 0.013
2024 0.0991 0.003 0.069
2025 0.0156 0.031 0.3167

Parameters

get_sharpe_ratio accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."quarterly"
rollingintThe rolling period to use for the calculation. If you select period = ‘monthly’ and set rolling to 12 you obtain the rolling 12-month Sharpe Ratio.4
methodstrWhich Sharpe ratio to calculate, one of “standard”, “lo”, “adjusted”, “probabilistic” or “deflated”, as described above. Defaults to “standard”."probabilistic"
benchmark_sharpe_ratiofloatThe hypothesized or benchmark Sharpe ratio (SR*) to test the observed Sharpe ratio against. Only used when method=”probabilistic”. Defaults to 0.0, i.e. testing whether the strategy has any skill at all above doing nothing.0.5
trials_windowintThe window size of the auxiliary rolling Sharpe ratio series that approximates Var[SR_trials] and the default n_trials, see above. Only used when method=”deflated”. It counts observations of the returns the Sharpe ratio is computed from: daily (or intraday) observations for the Sharpe ratio per period, and observations of period when rolling is set. Defaults to None, which uses the median number of observations per period (so each trial spans about one period) for the Sharpe ratio per period, and half of the available return history for a rolling Sharpe ratio so that enough overlapping windows exist regardless of period or date range.8
n_trialsintThe number of independent (or effectively independent) strategy variations, parameter combinations, or lookback windows tried before arriving at the reported Sharpe ratio. Only used when method=”deflated”. Defaults to None, which falls back to the number of valid values in the auxiliary rolling Sharpe ratio series described above. Pass this explicitly whenever the actual number of trials is known.20
lagsintThe number of autocorrelation lags in Lo’s η(q). Only used when method=”lo”. Defaults to None, which uses the Newey and West (1994) rule floor(4 * (n / 100)^(2/9)) on the n observations (4 for a year of daily returns), capped at q − 1.2
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the ratios. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
annualizeboolWhether to annualize the Sharpe ratio, multiplying it by the square root of the number of observations in a year: 252 for the daily returns within each period, 252 times the median number of bars per day for the intraday returns within a day (period=”daily” with an intraday_period), or the periods in a year for a rolling Sharpe ratio (e.g. 12 for monthly). Only for method=”standard” and “adjusted”, since the probabilistic and deflated methods return probabilities; method=”lo” is annualized either way. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column
Share