Stability of Returns
Calculate the stability of the returns of an investment portfolio or asset: how closely its growth follows a straight line on a logarithmic scale, a constant rate of growth.
The formula is as follows:
\[\text{Cumulative Log Return}_{t} = \sum(\operatorname{LN}(1 + \text{Return})) \;\text{up to day}\; t\] \[\text{Stability} = R \;\text{Squared of the regression of Cumulative Log}\; \text{Return}_{t} \;\text{on}\; t\]Where t counts the returns (0, 1, 2, …). A value close to 1 means the asset grew (or fell) at a steady rate; a value close to 0 means its path wandered without a trend. The measure says nothing about the direction: a steady decline is as stable as a steady rise, so read it together with the return.
The measure is defined in empyrical (Quantopian) as stability_of_timeseries and reported in pyfolio’s tear sheets; the Toolkit applies it to the returns of each ticker and period.
Also known as: stability of timeseries, R-squared of the equity curve.
Example · AAPL, MSFT, KO · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_stability_of_returns:
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_stability_of_returns()
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
How steadily did Apple, Microsoft and Coca-Cola grow in each year from 2021 to 2025, measured by the stability of their returns?
Which returns:
| Date | AAPL | MSFT | KO |
|---|---|---|---|
| 2021 | 0.7053 | 0.9381 | 0.7069 |
| 2022 | 0.4067 | 0.7082 | 0.0116 |
| 2023 | 0.6698 | 0.8243 | 0.1864 |
| 2024 | 0.7797 | 0.2793 | 0.5094 |
| 2025 | 0.3558 | 0.6004 | 0.2276 |
5 rows
Parameters
get_stability_of_returns 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”. | "weekly" |
within_period | bool | Whether to calculate the stability from the daily returns within each period or from the period returns of the entirety of all periods, one value per ticker. Defaults to True. | True |
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 |
References
- Library Referenced against empyrical’s stability_of_timeseries
- Library Shares similar logic as pyfolio’s stability_of_timeseries