Roy’s Safety-First Ratio
Calculate Roy’s Safety-First Ratio of an investment portfolio or asset’s returns.
Roy (1952) argues that an investor first of all wants to avoid a disaster, a return below a threshold, and so prefers the portfolio with the lowest probability of falling below it. For normally distributed returns that probability is N(-Safety-First Ratio), so the best portfolio is the one with the highest ratio: the number of standard deviations the expected return lies above the threshold.
The formula is as follows:
\[\text{Safety-First Ratio} = \frac{\operatorname{Mean}(\text{Return}) - \text{Threshold per Observation}}{\text{Standard Deviation}(\text{Return})}\] \[\text{Threshold per Observation} = (1 + \text{Threshold})^{\frac{1}{\text{Observations per Year}}} - 1\]The threshold is an annual return, compounded down to the returns the ratio is computed from: by default the daily returns falling inside each period, 252 a year for a ticker that trades on trading days and 365 for one that also trades on weekends (such as a cryptocurrency). With rolling, period instead sets the frequency of the returns and the ratio is computed over a rolling window of rolling such returns, with the threshold compounded to that frequency. The standard deviation is the sample one (ddof=1). With the risk-free rate as the threshold the ratio is the Sharpe Ratio (get_sharpe_ratio); the default threshold of 0 is Roy’s disaster of losing money.
As with the Sharpe Ratio, the result is not annualized: it is a per-observation ratio, so multiply by SQRT(252), SQRT(52), SQRT(12) or SQRT(4) for daily, weekly, monthly or quarterly returns respectively before comparing against published annualized figures.
For more information, see the following paper:
- Roy, A.D. (1952). “Safety First and the Holding of Assets.” Econometrica, 20(3), 431-449.
Also known as: SFRatio, Roy’s safety-first criterion.
Roy’s Safety-First Ratio in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_safety_first_ratio as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["KO", "PEP", "MDLZ"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.performance.get_safety_first_ratio(threshold=0.02)
Or, after setting up the Finance Toolkit MCP, ask:
What was Roy's safety-first ratio of Coca-Cola, PepsiCo and Mondelez against a 2% minimum return in each year from 2021 to 2025?
Which returns:
| Date | KO | PEP | MDLZ |
|---|---|---|---|
| 2021 | 0.0589 | 0.0893 | 0.0602 |
| 2022 | 0.0323 | 0.0211 | 0.0093 |
| 2023 | -0.0264 | -0.0177 | 0.0366 |
| 2024 | 0.0361 | -0.0329 | -0.0637 |
| 2025 | 0.0509 | -0.0036 | -0.0195 |
Parameters
get_safety_first_ratio accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”. | "weekly" |
threshold | float | The minimum acceptable (shortfall) return as an annual decimal return, e.g. 0.02 for 2% a year. Defaults to 0.0. | 0.0 |
rolling | int | None | The rolling window size to use for the calculation. If set, the ratio is calculated over a rolling window of this many periods across the full return history instead of per period. Defaults to None. | 4 |
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 |
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 |