Strategy Risk
Calculate the strategy risk of López de Prado for an investment portfolio or asset: its returns read as bets that either win the average gain or lose the average loss, the Sharpe ratio such a strategy has, the precision (share of winning bets) and the number of bets a year it needs to reach a target Sharpe ratio, and the probability that its true precision falls short of the one needed, the probability of failure. Unlike the volatility, which measures the risk of the asset, this measures the risk that the strategy does not deliver its target: a small drop of the precision can take a strategy with a high target from success to failure.
The formula is as follows:
\[\text{Precision}\; p = \frac{\text{Number of Returns above} \;0}{\text{Number of Returns}}\] \[\text{Average Gain}\; \pi + = \text{Average of the Returns above}\; 0,\;\; \text{Average Loss}\; \pi - = \text{Average of the Returns of 0 or below}\] \[\text{Binomial Sharpe Ratio} = \frac{(\pi + - \pi -) x p + \pi -}{(\pi + - \pi -) \cdot \sqrt{p \cdot (1 - p)}} \cdot \sqrt{n}\] \[\text{Implied Precision} \;p^{*} = \frac{- b + \sqrt{b^{2} - \text{4ac}}}{2a},\;\; \text{with}\;\; a = (n + \theta^{2}) \cdot (\pi + - \pi -)^{2},\;\; b = (2 x n x \pi - - \theta^{2} x (\pi + - \pi -)) \cdot (\pi + - \pi -)\;\;\text{and}\;\; c = n x \pi -^{2}\] \[\text{Implied Frequency} \;n^{*} = \frac{\theta^{2} x (\pi + - \pi -)^{2} x p \cdot (1 - p)}{((\pi + - \pi -) x p + \pi -)^{2}}\] \[\text{Probability of Failure} = N\left(\frac{p^{*} - p}{\sqrt{\frac{p \cdot (1 - p)}{N}}}\right)\]Where n is the number of bets a year (252 daily returns, 365 for a ticker that trades on weekends such as a cryptocurrency, or 52, 12, 4 or 1 for weekly, monthly, quarterly or yearly returns), \(\theta\) the target Sharpe ratio, N the number of returns and N(.) the standard normal distribution function. The Implied Precision is the precision that reaches \(\theta\) at the measured gains, losses and frequency, the Implied Frequency the number of bets a year that reaches \(\theta\) at the measured precision, gains and losses.
Also known as: implied precision, implied betting frequency, binomial Sharpe ratio, probability of strategy failure.
Example · AAPL, MSFT, KO · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_strategy_risk:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "KO"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.performance.get_strategy_risk()
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
Treating a daily position in Apple, Microsoft or Coca-Cola from 2021 to 2025 as a strategy, what were its precision, bet sizes and probability of failure?
Which returns:
| Item | AAPL | MSFT | KO |
|---|---|---|---|
| Precision | 0.5303 | 0.5239 | 0.5279 |
| Average Gain | 0.0125 | 0.0120 | 0.0073 |
| Average Loss | -0.0125 | -0.0115 | -0.0074 |
| Bets per Year | 252.0000 | 252.0000 | 252.0000 |
| Binomial Sharpe Ratio | 0.9746 | 1.0813 | 0.8521 |
| Implied Precision | 0.5622 | 0.5525 | 0.5636 |
| Implied Frequency | 1,061.2600 | 862.0490 | 1,388.4100 |
| Probability of Failure | 0.9881 | 0.9788 | 0.9943 |
8 rows
Parameters
get_strategy_risk accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The period of the returns over the whole history, or with within_period=True the period the daily returns are grouped by. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”, or with within_period=True to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”. | "weekly" |
within_period | bool | Whether to calculate the strategy risk from the daily returns within each period (e.g. each year if period = ‘yearly’) instead of from the returns of period over the whole history. Defaults to False. | True |
target_sharpe_ratio | float | The annualized Sharpe ratio the strategy should reach. Defaults to 2.0, as López de Prado. | |
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 |
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 |
References
- Paper López de Prado, M. (2018). “Advances in Financial Machine Learning.” Wiley, chapter 15 (Snippets 15.1 to 15.5).
- Paper Bailey, D.H. and López de Prado, M. (2014). “The Sharpe Ratio Efficient Frontier.” Journal of Risk, 15(2), 3-44.
- Library Shares similar logic as RiskLabAI’s implied_precision
- Library Shares similar logic as RiskLabAI’s bin_frequency
- Library Shares similar logic as RiskLabAI’s binomial_sharpe_ratio
- Library Shares similar logic as RiskLabAI’s failure_probability