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.

Also known as: relative standard deviation.

Coefficient of Variation (CV) in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_coefficient_of_variation as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")

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

Which returns:

Date AMZN TSLA Benchmark
2021 73.121 15.7477 8.3938
2022 -14.1417 -12.7544 -20.4791
2023 8.0356 10.0506 9.1833
2024 10.9398 14.7623 9.1557
2025 49.9543 32.8037 18.0122
2026 31.132 -163.952 11.047

Parameters

The function accepts the following parameters:

  • period (str, optional): The data frequency for returns (weekly, monthly, quarterly, or yearly). Defaults to “quarterly” if the Toolkit is initialized with quarterly=True, otherwise “yearly”.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the CV values over time. Defaults to False.
  • lag (int | list[int], optional): The lag to use for the growth calculation. Defaults to 1.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
Share