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:

Parameters

get_stability_of_returns accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe 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_periodboolWhether 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
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
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

References

Share