Testing whether volatility fluctuates
To first order in the holding time, a fast-switching chain enters an option price through one number per switched parameter, the Green–Kubo constant
plus the memory term of the starting regime. Here \(f = \sigma^2\). A constant volatility is \(K = 0\), so the hypothesis that volatility does not fluctuate is one restriction, \(H_0: K = 0\), whatever the number of regimes. This page states the restriction’s effect on prices, builds a test of it from returns, and checks the test’s size and power on simulated paths. It is an example, not part of the library: the library prices, and estimating \(K\) from data is left to the user.
What K does to a price
For Black–Scholes with a switching volatility, the averaged model is Black–Scholes at \(\bar\sigma^2 = \pi\cdot \sigma^2\), and the first-order correction is
with \(V\) the total variance. For two regimes with rates \(\lambda_{01}, \lambda_{10}\) and \(\lambda = \lambda_{01} + \lambda_{10}\), \(K = \pi_0\pi_1(\sigma_0^2 - \sigma_1^2)^2/\lambda\). Both statements against the library:
import math
from scipy.stats import norm
from regimelib.firstorder import green_kubo
chain = rl.RegimeChain.twoState(30.0, 20.0)
sigma = np.array([0.30, 0.15]); f = sigma ** 2
pi = chain.stationaryDistribution(); lam = 50.0
S0, r, T, strike = 100.0, 0.02, 1.0, 100.0
def black(V):
F = S0 * math.exp(r * T); sd = math.sqrt(V)
d1 = (math.log(F / strike) + V / 2) / sd
return math.exp(-r * T) * (F * norm.cdf(d1) - strike * norm.cdf(d1 - sd))
K = green_kubo(chain, [f])[0][0, 0]
V, h = float(pi @ f) * T, 1e-4
curvature = (black(V + h) - 2 * black(V) + black(V - h)) / h ** 2
engine = rl.FirstOrderFDEngine(rl.SwitchingBlackScholesProcess(chain, S0, r, 0.0, list(sigma)), regime=0, n=1601)
option = rl.VanillaOption(("call", strike), maturity=T); option.setPricingEngine(engine); option.NPV()
print(f"K from green_kubo {K:.6e}")
print(f"pi0 pi1 (f0-f1)^2/lam {pi[0] * pi[1] * (f[0] - f[1]) ** 2 / lam:.6e}")
print(f"correction (engine) {engine.correction:.5f}")
print(f"K T d2C/dV2 {K * T * curvature:.5f}")
K from green_kubo 2.187000e-05
pi0 pi1 (f0-f1)^2/lam 2.187000e-05
correction (engine) -0.01949
K T d2C/dV2 -0.01949
K from returns
The integrated variance over an interval of length \(h\) has
so \(K\) is half the long-run variance \(\int_{-\infty}^\infty C(s)\,ds\) of \(\sigma^2\). For two regimes \(C(s) = \pi_0\pi_1(f_0 - f_1)^2e^{-\lambda s}\) and the variance is exactly \(2K\,[h - (1 - e^{-\lambda h})/\lambda]\).
Take returns \(r_j\) at spacing \(\Delta\), in \(B\) blocks of \(n\), so a block has length \(h = n\Delta\), and let \(RV_b = \sum_{j\in b} r_j^2\). If the returns were independent, the variance of a block’s \(RV_b\) would be \(n\) times the variance of one \(r_j^2\). A fluctuating \(\sigma^2\) makes squared returns serially dependent and adds \(\operatorname{Var}\int_h\sigma^2\). The estimate and the statistic are
with \(s^2(RV)\) the sample variance of the block sums and \(\overline{s^2_b(r^2)}\) the average within-block sample variance of the squared returns. Under \(H_0\) with independent, identically distributed returns of any law, the returns are exchangeable, so permuting them gives the exact null law of \(R\). The test then makes no assumption about tails: independent jumps and fat-tailed returns leave its size at the nominal level. Using the Gaussian fourth moment instead (\(\tfrac23\sum r^4\) for \(n\) times the variance of \(r^2\)) gives a test that rejects most of the time under fat tails with no fluctuation at all.
With blocks of length \(h\), \(\hat K\) estimates \(K[1 - (1 - e^{-\lambda h})/(\lambda h)]\), less what fluctuates within a block, since the within-block term absorbs it. One path of ten years of daily returns, monthly blocks, regimes of 30% and 15% volatility that last about a week, and one path with a constant volatility and Student-t tails:
rng = np.random.default_rng(1)
dt, days, n = 1 / 252, 2520, 21
def integrated_variance(f, l01, l10, rng):
"""The integrated variance over each day for a two-state chain started from its stationary law, exactly."""
rates = (l01, l10); state = int(rng.random() >= l10 / (l01 + l10)); t = 0.0
jump = rng.exponential(1 / rates[state]); out = np.empty(days)
for d in range(days):
end, acc = (d + 1) * dt, 0.0
while jump < end:
acc += f[state] * (jump - t); t = jump; state = 1 - state
jump = t + rng.exponential(1 / rates[state])
out[d] = acc + f[state] * (end - t); t = end
return out
def statistic(r):
s = r[: len(r) // n * n].reshape(-1, n) ** 2
between, within = s.sum(1).var(ddof=1), n * s.var(1, ddof=1).mean()
return between / within, (between - within) / (2 * n * dt)
def pvalue(r, permutations=199):
R = statistic(r)[0]
return (1 + sum(statistic(rng.permutation(r))[0] >= R for _ in range(permutations))) / (1 + permutations)
f, lam = (0.09, 0.0225), 50.0
switching = np.sqrt(integrated_variance(f, lam / 2, lam / 2, rng)) * rng.standard_normal(days)
constant = 0.2 * math.sqrt(dt / 2) * rng.standard_t(4, days)
h = n * dt; K = 0.25 * (f[0] - f[1]) ** 2 / lam
print(f"switching Khat {statistic(switching)[1]:.2e} K over a block {K * (1 - (1 - math.exp(-lam * h)) / (lam * h)):.2e} p {pvalue(switching):.3f}")
print(f"constant Khat {statistic(constant)[1]:+.2e} p {pvalue(constant):.3f}")
switching Khat 1.37e-05 K over a block 1.74e-05 p 0.005
constant Khat -2.71e-06 p 0.555
Size and power
Repeating that 200 times for each case, with 99 permutations, and rejecting at 5% (the rates for a constant volatility are within the sampling error of 5%, about 1.5 points at 200 paths):
def rejection(make, reps=200):
return np.mean([pvalue(make(), 99) <= 0.05 for _ in range(reps)])
cases = [("constant, normal", lambda: 0.2 * math.sqrt(dt) * rng.standard_normal(days)),
("constant, t4 tails", lambda: 0.2 * math.sqrt(dt / 2) * rng.standard_t(4, days)),
("constant, iid jumps", lambda: 0.15 * math.sqrt(dt) * rng.standard_normal(days)
+ rng.poisson(10 * dt, days) * rng.normal(0.0, 0.03, days))]
for lam in (50.0, 250.0, 1000.0):
cases.append((f"switching, lam {lam:g}",
lambda lam=lam: np.sqrt(integrated_variance(f, lam / 2, lam / 2, rng)) * rng.standard_normal(days)))
for name, make in cases:
print(f"{name:22s} rejects {100 * rejection(make):5.1f}%")
constant, normal rejects 4.0%
constant, t4 tails rejects 5.5%
constant, iid jumps rejects 5.5%
switching, lam 50 rejects 100.0%
switching, lam 250 rejects 33.5%
switching, lam 1000 rejects 7.5%
Regimes that last a week or more are found with certainty in ten years of daily data. At \(\lambda = 250\) (a regime lasts about two trading days) power is low, and the price correction on a one-year at-the-money call is then about 0.04% of the price; at \(\lambda = 1000\) both are negligible. The test loses power where the fluctuation stops mattering for the price.
What the test does not do
It tests a fluctuating volatility against a constant one, not regimes against a diffusive stochastic volatility: both enter prices to first order through a constant of the same kind, and both make squared returns serially dependent.
It needs returns that are independent under the null. Independent jumps are allowed; a jump intensity that itself varies is a fluctuation the test detects.
\(\hat K\) is biased low when the regimes switch within a block. Shorter blocks reduce that bias and the power with it.