Back To Top
Experience the Future of Intelligent Investing Today
Finding consistent alpha in the market is hard. Traders could rely on intuition, but this might not offer a systematic and clear edge.
The key is identifying repeatable and testable patterns — factors — that are correlated with future returns.
In this article, we will walk through a quantitative framework for evaluating the performance of alpha factors.
Using a simple mean-reversion strategy, we’ll compute Z-score factors across multiple stocks to identify key price deviations.
Factors will be analyzed in a cross-sectional manner using Alphalens. Stocks are then ranked into quantiles based on the strength of the factors
Market efficiency isn’t static. Price behavior changes — sometimes dramatically — depending on liquidity, volatility, and investor behavior.
In early 2021, GameStop showed explosive momentum. Traders riding the trend made outsized gains. But those who applied mean-reversion strategies got steamrolled.
Months later, the pattern reversed — mean-reversion returned as the stock cooled off. Same asset, different regime.
During the COVID crash in March 2020, momentum strategies underperformed as markets whipsawed violently.
But in the recovery that followed, trend-following delivered consistent returns — until it didn’t. These shifts happen all the time. What works in one regime fails in the next.
Traditional models assume price changes are random. But real markets often show pockets of structure — short windows of momentum or reversion that can be measured, tracked, and exploited.
The challenge isn’t building a strategy. It’s knowing when it has an edge. That’s why traders need a way to detect shifts in price dynamics before the damage is done.
Variance ratios and autocorrelation analyses offer a statistical way to detect when strategies have an edge — and when that edge disappears.
The variance ratio test was first formalized by Andrew Lo and A. Craig MacKinlay in their landmark 1988 paper, “Stock Market Prices Do Not Follow Random Walks”.
The central idea is simple. If returns follow a random walk, then the variance of q-period returns should be q times the variance of 1-period returns.
Mathematically, under the random walk hypothesis, returns over time are independent and identically distributed (i.i.d.). That means:
In words: the variance of returns over q periods should be exactly q times the variance of daily (or 1-period) returns.
The variance ratio simply compares the actual variance of q-period returns to what we’d expect under a random walk:
This leads to the variance ratio:
Under the null hypothesis of a random walk, VR should be 0. Deviations from this would mean that:
We now translate theory into code. The goal: compute rolling variance ratios across different holding periods and visualize how they evolve over time.
We’ll use yfinance
to pull historical price data for GameStop and apply a rolling window to calculate the variance ratio and its statistical significance.
Key Parameters:
q
: the holding period (e.g., 2, 5, 10, 20, 60 days)T
: the rolling window size (here, 252 trading days)The parameter q defines the holding period to test for predictability. A significant variance ratio at q=10 suggests that momentum or mean-reversion effects may persist over a 10-day horizon.
In the code below, we plot the results for different qqq values to see how predictability changes across short- and medium-term horizons — and when certain holding periods start to show an edge.
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.patches as mpatches
from matplotlib import gridspec
from scipy.stats import norm
Newsletter