Yang-Zhang Volatility is a weighted combination of the overnight (close-to-open) Variance, the open-to-close Variance and the Rogers-Satchell Variance. It is both drift-independent and accounts for overnight jumps, which makes it the most statistically efficient of the range-based estimators implemented here.

The formula is as follows:

\[\text{Yang-Zhang Variance} = \operatorname{Var}(\ln(O / C_{- 1})) + k \cdot \operatorname{Var}(\ln(C / O)) + (1 - k) \cdot \text{Rogers-Satchell Variance}\] \[k = 0.34 / (1.34 + (n + 1) / (n - 1)),\;\; \text{with n the number of days in the period}\]

Source: Yang, D., & Zhang, Q. (2000). “Drift-Independent Volatility Estimation Based on High, Low, Open, and Close Prices.” Journal of Business, 73(3), 477-491.

In the Finance Toolkit this is get_volatility with method="yang_zhang"; the Volatility page has the function’s full description.

Yang-Zhang Volatility in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_volatility as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["EURUSD", "BTCUSD", "^GSPC", "GCUSD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_volatility(method="yang_zhang", period="yearly")

Which returns:

Date EURUSD BTCUSD ^GSPC GCUSD Benchmark
2021 0.0533 0.8192 0.1162 0.1589 0.1332
2022 0.1035 0.5504 0.2073 0.1678 0.2325
2023 0.0736 0.3817 0.1205 0.1477 0.1324
2024 0.0604 0.4691 0.1227 0.1606 0.1315
2025 0.0771 0.3885 0.1737 0.2071 0.1864

Parameters

get_volatility 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"
rollingintThe rolling window size to use for the calculation. If set, Volatility is calculated over a rolling window of this many periods (e.g. period=’monthly’ and rolling=6 gives the rolling 6-month Volatility) instead of one value per period. Only available for method=”close_to_close”. Defaults to None.4
methodstrWhich Volatility estimator to use, one of “close_to_close”, “parkinson”, “garman_klass”, “rogers_satchell” or “yang_zhang”, as described above. Defaults to “close_to_close”."yang_zhang"
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 Volatility 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
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
Share