Class VolatilityCurve
java.lang.Object
com.quantfinlib.microstructure.VolatilityCurve
Intraday volatility seasonality — the third leg of the seasonality trio
beside
VolumeCurve and SpreadForecaster: volatility is
U-shaped through an equity day (wild open, quiet lunch, busy close) and
session-humped through an FX day (London open, NY overlap), so "is the
market volatile right now?" is meaningless without "…for this time of
day."
Each session accumulates a per-bucket mean of the observed volatility
(feed SignalEngine.volPerSqrtSecond at whatever cadence you poll
it); rollDay() folds it into a per-bucket baseline with the
day-over-day EWMA, the first session seeding directly.
regime(int, double) is the point of the class: the normalized
volatility-regime signal that execution.BenchmarkExecutor.MarketState
documents as its volatility input — current vol against the
time-of-day baseline, mapped to ~0 (calm for this hour) … 1 (extreme),
so "the open is always wild" doesn't read as an urgency signal but a
genuinely wild lunchtime does. Before any baseline is learned the regime
is 0 (neutral) — the honest default. Cross-asset, zero allocation,
single writer.
-
Constructor Summary
ConstructorsConstructorDescription78 equity buckets, 10% day weight.VolatilityCurve(int buckets, double dayAlpha) -
Method Summary
Modifier and TypeMethodDescriptiondoublebaseline(int bucket) The learned time-of-day baseline vol for a bucket (0 until learned).intbuckets()intvoidonVol(int bucket, double volPerSqrtSecond) An observed volatility reading forbucket(e.g.voidRestores the learned baseline; today's accumulation resets (restore at session start).doubleregime(int bucket, double currentVolPerSqrtSecond) The normalized volatility-regime signal forBenchmarkExecutor.MarketState.volatility: how elevated the current vol is against this hour's baseline,clamp(current/baseline − 1, 0, 1). 0 when calm-for-the-hour, unlearned, or fed a non-finite reading — a bad input reads as neutral, never as urgency.voidrollDay()Closes the session: folds today's per-bucket mean vol into the baseline (buckets without observations keep their learned value).seedBaseline(double[] volPerBucket) Seeds the baseline from a known shape (same units you will feed) — optional.voidwriteState(DataOutput out) Persists the learned baseline (cross-day state) — seepersist.Checkpoint.
-
Constructor Details
-
VolatilityCurve
public VolatilityCurve(int buckets, double dayAlpha) - Parameters:
buckets- time buckets per session (78 equities, 288 for 24h FX)dayAlpha- baseline EWMA weight across days, e.g. 0.1
-
VolatilityCurve
public VolatilityCurve()78 equity buckets, 10% day weight.
-
-
Method Details
-
seedBaseline
Seeds the baseline from a known shape (same units you will feed) — optional. -
onVol
public void onVol(int bucket, double volPerSqrtSecond) An observed volatility reading forbucket(e.g.SignalEngine.volPerSqrtSecond, polled per interval). Non-finite or negative readings are ignored. -
rollDay
public void rollDay()Closes the session: folds today's per-bucket mean vol into the baseline (buckets without observations keep their learned value). Seeding is PER BUCKET — a bucket first observed on day 5 (feed started mid-session on day 1, a half day skipped the afternoon) seeds from its own first observation rather than EWMA-ramping from 0, which would leaveregime(int, double)falsely reading "extreme" at that hour for weeks. -
baseline
public double baseline(int bucket) The learned time-of-day baseline vol for a bucket (0 until learned). -
regime
public double regime(int bucket, double currentVolPerSqrtSecond) The normalized volatility-regime signal forBenchmarkExecutor.MarketState.volatility: how elevated the current vol is against this hour's baseline,clamp(current/baseline − 1, 0, 1). 0 when calm-for-the-hour, unlearned, or fed a non-finite reading — a bad input reads as neutral, never as urgency. -
writeState
Persists the learned baseline (cross-day state) — seepersist.Checkpoint.- Throws:
IOException
-
readState
Restores the learned baseline; today's accumulation resets (restore at session start). Throws on a bucket-count or version mismatch.- Throws:
IOException
-
buckets
public int buckets() -
daysLearned
public int daysLearned()
-