Lo Annualized Sharpe Ratio
The Sharpe ratio is calculated as the difference between the expected return of the asset or portfolio and the risk-free rate of return, divided by the standard deviation of the asset or portfolio’s excess return. It quantifies the amount of return generated for each unit of risk assumed, providing insights into the investment’s performance relative to the risk taken.
The annualized Sharpe ratio of Lo (2002) corrects the annualization for serially correlated returns. SQRT(q) * SR assumes independent returns; with autocorrelated returns (smoothed prices of illiquid assets, hedge funds, momentum or mean reversion) the variance of a yearly return is no longer q times the variance of one return, and the yearly Sharpe ratio becomes:
\[\operatorname{SR}(q) = \eta(q) \cdot \text{SR},\;\; \eta(q) = \frac{q}{\sqrt{q + 2 \cdot \sum_{k=1}^{q-1}(q - k) \cdot \rho_{k}}}\]Where q is the number of observations in a year and \(\rho_{k}\) the sample autocorrelation of the excess returns at lag k. Positive autocorrelation lowers the annualized ratio below SQRT(q) * SR, negative autocorrelation raises it. Sample autocorrelations at lags close to the sample size rest on a handful of pairs, so the sum runs over lags lags and takes the autocorrelations beyond them as 0. Each \(\rho_{k}\) is corrected for its small-sample bias −(n − k) / (n · (n − 1)) (Moran, 1948), which the (q − k) weights would otherwise turn into an overstated ratio on short samples, and fewer than 30 observations give NaN: a week or a month of daily returns, or a rolling window below 30, so use quarterly or yearly periods or a longer window. The result is always annualized.
In the Finance Toolkit this is get_sharpe_ratio with method="lo", the same function as Sharpe Ratio.
Example · SPY, TLT, GLD, BTCUSD · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_sharpe_ratio:
from financetoolkit import Toolkit
toolkit = Toolkit(
["SPY", "TLT", "GLD", "BTCUSD"],
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="lo")
Which returns:
| Date | SPY | TLT | GLD | BTCUSD |
|---|---|---|---|---|
| 2021 | 2.5624 | -0.4458 | -0.5225 | 0.9326 |
| 2022 | -0.9054 | -2.2717 | -0.1534 | -1.3831 |
| 2023 | 1.5743 | 0.0316 | 0.6227 | 1.9402 |
| 2024 | 1.5828 | -0.8154 | 1.4043 | 1.6421 |
| 2025 | 1.0755 | 0.067 | 3.0685 | -0.0553 |
Parameters
get_sharpe_ratio accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The period to use for the calculation. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”. | "quarterly" |
rolling | int | The 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. At least 2. Defaults to None, which calculates the Sharpe ratio within each period. | 4 |
method | str | Which Sharpe ratio to calculate, as described above. Options are: “standard” (the Sharpe ratio), “smart” (the Smart Sharpe ratio), “lo” (the annualized Sharpe ratio of Lo), “adjusted” (the Adjusted Sharpe Ratio), “probabilistic” (the Probabilistic Sharpe Ratio), “deflated” (the Deflated Sharpe Ratio). Defaults to “standard”. | "probabilistic" |
benchmark_sharpe_ratio | float | The hypothesized or benchmark Sharpe ratio (SR*) to test the observed Sharpe ratio against. Only used when method=”probabilistic”. It is a per-observation Sharpe ratio, or an annualized one when annualize=True. Defaults to 0.0, i.e. testing whether the strategy has any skill at all above doing nothing. | 0.5 |
trials_window | int | The 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, per ticker, the median number of its observations in a period (so each trial spans about one period) for the Sharpe ratio per period, and half of its return history for a rolling Sharpe ratio so that enough overlapping windows exist regardless of period or date range. | 8 |
n_trials | int | The 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 non-overlapping windows of trials_window observations the returns hold (at least 1), since the overlapping windows of the auxiliary rolling Sharpe ratio series are not independent trials. Pass this explicitly whenever the actual number of trials is known. | 20 |
lags | int | The number of autocorrelation lags in Lo’s \(\eta (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 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the ratios. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
annualize | bool | Whether 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 (365 for a ticker that trades on weekends, such as a cryptocurrency), those days 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, and the daily observations per year of each ticker for daily). This applies to method=”standard”, “smart” and “adjusted”; method=”lo” is annualized either way. The probabilistic and deflated methods return probabilities, which do not depend on the time scale as long as the observed and the benchmark Sharpe ratio share it (Bailey and López de Prado, 2012), so annualize=True returns the same probability; for method=”probabilistic” it reads benchmark_sharpe_ratio as an annualized Sharpe ratio. Defaults to False. | True |
show_columns | str | list[str] | None | The 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 |