Garman-Klass Yang-Zhang Volatility

Volatility measures the amount of dispersion or variability in returns. It is the square root of the Variance. A higher Volatility indicates greater variability, while a lower Volatility suggests that returns are closer to the mean.

Garman-Klass Yang-Zhang Volatility is Garman-Klass with the squared overnight (close-to-open) return of Yang and Zhang added, so it accounts for overnight jumps while keeping the Garman-Klass term for the session (still assuming no drift).

The Volatility is the square root of this daily variance, scaled to the period in the same way as the close-to-close Volatility (with 252 trading days a year, or 365 for a ticker that trades every day such as a cryptocurrency), with H, L, O and C the daily High, Low, Open and Close, \(C_{- 1}\) the previous Close and Mean the average over the days in the period:

\[\text{Garman-Klass Yang-Zhang Variance} = \operatorname{Mean}\left(\ln\left(\frac{O}{C_{-1}}\right)^{2} + 0.5 \cdot \ln\left(\frac{H}{L}\right)^{2} - (2 \cdot \ln 2 - 1) \cdot \ln\left(\frac{C}{O}\right)^{2}\right)\]

In the Finance Toolkit this is get_volatility with method="garman_klass_yang_zhang", the same function as Volatility.

Example · EURUSD, BTCUSD, ^GSPC, GCUSD · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_volatility:

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="garman_klass_yang_zhang", period="yearly")

Which returns:

Date EURUSD BTCUSD ^GSPC GCUSD Benchmark
2021 0.0536 0.9747 0.1136 0.158 0.1321
2022 0.1036 0.6604 0.2065 0.1703 0.2329
2023 0.0739 0.4633 0.1208 0.1485 0.1328
2024 0.0612 0.5686 0.1219 0.1624 0.1311
2025 0.077 0.468 0.1743 0.2101 0.1861

Parameters

get_volatility accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns. Options are: “weekly”, “monthly”, “quarterly”, “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”. At least 2. Defaults to None.4
methodstrThe Volatility estimator, as described above. Options are: “close_to_close” (close-to-close), “parkinson” (Parkinson), “garman_klass” (Garman-Klass), “rogers_satchell” (Rogers-Satchell), “yang_zhang” (Yang-Zhang), “garman_klass_yang_zhang” (Garman-Klass Yang-Zhang), “compounded” (compounded). 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

References

  • Paper Garman, M.B., & Klass, M.J. (1980). “On the Estimation of Security Price Volatilities from Historical Data.” Journal of Business, 53(1), 67-78.
  • Paper Yang, D., & Zhang, Q. (2000). “Drift-Independent Volatility Estimation Based on High, Low, Open, and Close Prices.” Journal of Business, 73(3), 477-492.
  • Library Shares similar logic as TTR (R)’s volatility (Parkinson, Garman-Klass, Rogers-Satchell, Yang-Zhang, Garman-Klass Yang-Zhang)
Share