Realized Variance

Calculate the Realized Variance of every day from its intraday returns: how much the price moved within the day, split into the upside and downside semivariance and into the continuous part and the jumps.

The realized variance sums the squared intraday returns of a day and converges to its integrated variance plus its squared jumps as the bars get shorter (Andersen, Bollerslev, Diebold and Labys, 2003). It measures each day’s volatility on its own, where the close-to-close Volatility (see get_volatility) needs many days.

  • Realized Variance and Realized Volatility: the sum of the squared intraday returns and its square root.
  • Positive and Negative Semivariance: the part of the realized variance from the rises and from the falls (Barndorff-Nielsen, Kinnebrock and Shephard, 2010). The downside semivariance tells most about the volatility to come.
  • Bipower Variation: the integrated variance without the jumps, from the products of neighbouring absolute returns, as a single jump only enters next to an ordinary return (Barndorff-Nielsen and Shephard, 2004).
  • Jump Variation: the part of the realized variance the bipower variation leaves out. See get_jump_test for whether it is significant.

The formula is as follows, with \(r_{j}\) the M intraday log returns of a day:

\[r_{1} = \ln\left(\frac{\text{Close}_{1}}{\text{Open}_{1}}\right)\;\;\text{and}\;\; r_{j} = \ln\left(\frac{\text{Close}_{j}}{\text{Close}_{j-1}}\right) \;\text{for the later bars},\;\; \text{so the overnight return is left out}\] \[\text{Realized Variance} = \sum(r_{j}^{2})\;\;\text{and}\;\; \text{Realized Volatility} = \sqrt{\text{Realized Variance}}\] \[\text{Positive Semivariance} = \sum(r_{j}^{2} \cdot 1(r_{j} > 0))\;\;\text{and}\;\; \text{Negative Semivariance} = \sum(r_{j}^{2} \cdot 1(r_{j} < 0))\] \[\text{Bipower Variation} = \mu_{1}^{-2} \cdot \frac{M}{M - 1} \cdot \sum_{j=2}^{M}(\left|r_{j}\right| \cdot \left|r_{j-1}\right|)\] \[\text{Jump Variation} = \max(\text{Realized Variance} - \text{Bipower Variation},\; 0)\]

Where \(\mu_{1}\) = SQRT(2 / pi) is the mean absolute value of a standard normal and M / (M - 1) the small-sample factor of Huang and Tauchen (2005), which matters for hourly bars with \(M = 7\).

Also known as: realized variance, realized volatility, realised variance, realized semivariance, good and bad volatility, bipower variation, jump variation, intraday volatility.

Example · AAPL, MSFT · 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2025-12-22",
    end_date="2025-12-31",
    intraday_period="5min",
)

toolkit.risk.get_realized_variance()["Realized Volatility"]

Which returns:

Parameters

get_realized_variance accepts the following parameters.

ParameterTypeDescriptionExample
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
transformstr | list[str] | NoneTime series steps applied to the result in order, such as “sma:12” (moving average), “ema:12”, “std:12”, “zscore:60”, “percentile:120”, “yoy”, “pct_change:3,annualize:3”, “log”, “diff”, “cumsum” or “hp_trend” and “hp_cycle” (Hodrick-Prescott), along the dates of each series. A window needs that many periods of the result, so its first periods are empty. Defaults to None.None
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 Andersen, T.G., Bollerslev, T., Diebold, F.X. and Labys, P. (2003). “Modeling and Forecasting Realized Volatility.” Econometrica, 71(2), 579-625.
  • Paper Barndorff-Nielsen, O.E. and Shephard, N. (2004). “Power and Bipower Variation with Stochastic Volatility and Jumps.” Journal of Financial Econometrics, 2(1), 1-37.
  • Paper Barndorff-Nielsen, O.E., Kinnebrock, S. and Shephard, N. (2010). “Measuring Downside Risk: Realised Semivariance.” In Volatility and Time Series Econometrics: Essays in Honor of Robert F. Engle, Oxford University Press, 117-136.
  • Paper Huang, X. and Tauchen, G. (2005). “The Relative Contribution of Jumps to Total Price Variance.” Journal of Financial Econometrics, 3(4), 456-499.
Share