Calculate the Coefficient of Variation (CV) of an investment portfolio or asset’s returns for a given period based on the daily historical returns.

The Coefficient of Variation is the ratio of the standard deviation to the mean of returns, which normalizes dispersion relative to the average return. This makes it useful for comparing the relative volatility of assets with different average returns, which a raw standard deviation cannot do.

The Coefficient of Variation is only meaningful when the mean return is clearly positive. In a period with an average daily return close to zero it explodes, and in a down period it turns negative, so for returns it is best read over periods with a positive mean, or replaced by a Sharpe ratio, which is its inverse with the risk-free rate subtracted.

The formula is as follows:

\[\text{Coefficient of Variation} = \operatorname{Std}(\text{Daily Returns}) / \operatorname{Mean}(\text{Daily Returns})\]

Where both are taken over the daily returns within each period, with Std the sample standard deviation (ddof=1), without scaling to the period length.

Also known as: relative standard deviation.

Coefficient of Variation (CV) in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_coefficient_of_variation as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["MSFT", "ORCL", "IBM"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2023-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_coefficient_of_variation(period="yearly")

Or, after setting up the Finance Toolkit MCP, ask:

How much volatility did Microsoft, Oracle, IBM and the S&P 500 carry per unit of return in each year from 2023 to 2025?

Which returns:

Date MSFT ORCL IBM Benchmark
2023 8.0237 16.2298 12.0942 8.3745
2024 22.4294 9.8256 10.3503 8.6564
2025 21.9925 28.2432 12.934 16.8499

Parameters

get_coefficient_of_variation accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (weekly, monthly, quarterly, or yearly). Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."quarterly"
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 CV values over time. 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
Share