Variance Ratio Test
Calculate the Lo-MacKinlay Variance Ratio test for the random walk hypothesis.
The test compares the Variance of q-period (overlapping) compounded returns to q times the Variance of single-period returns. Under the random walk hypothesis these should be equal, giving a Variance Ratio of 1. A Variance Ratio above 1 with a significant (low) p-value indicates positive autocorrelation (momentum/trending behavior), while a Variance Ratio below 1 with a significant p-value indicates negative autocorrelation (mean-reversion).
For more information about the method, see the following paper:
- Lo, A.W., & MacKinlay, A.C. (1988). “Stock Market Prices Do Not Follow Random Walks: Evidence from a Simple Specification Test.” Review of Financial Studies, 1(1), 41-66.
Also known as: Lo-MacKinlay test, VR test.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Variance Ratio Test for you. Just ask in plain English.
Calculate the Variance Ratio Test in Python
The Variance Ratio Test is available in the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_variance_ratio_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.econometrics.get_variance_ratio_test(period="quarterly", within_period=False)
Which returns:
| AMZN | TSLA | |
|---|---|---|
| Variance Ratio | 0.8526 | 0.7523 |
| Variance Ratio Statistic | -0.6757 | -1.1353 |
| P-Value | 0.4993 | 0.2563 |
Parameters
get_variance_ratio_test accepts the following parameters:
- period (str, optional): The data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- within_period (bool, optional): Whether to calculate the test within the specified period or for the entire period. Thus whether to look at the test within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False.
- q (int, optional): The number of periods to compound returns over. Defaults to 2.
- include_benchmark (bool, optional): Whether to include “Benchmark” among the assets tested. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Related Unit Root & Stationarity
The Econometrics module page introduces the module, and the sidebar lists all of its functions.