The platform sweeps lags from -maxLag to +maxLag and collects correlation at each step:
The result is the Cross-Correlation Function (CCF) chart.
Finding the Lead-Lag Relationship
The dominant lead-lag is the lag k where |correlation| is maximum:
Reading the Result
best.lag
Interpretation
+5
A leads B by 5 ticks
-3
B leads A by 3 ticks
0
Simultaneous — neither leads
Lag Windows
Window
Tick range
1 tick ≈
1m
±20 ticks
~3 seconds
5m
±20 ticks
~15 seconds
15m
±20 ticks
~45 seconds
1h
±20 ticks
~3 minutes
Reading the CCF Chart
The chart plots correlation at every lag from -20 to +20:
Peak position → direction and magnitude of lead-lag
Peak height → strength of the predictive relationship
Flat curve → no lead-lag, assets react independently
Multiple peaks → noisy or unstable relationship
corrAt0 vs corrAtLag
Metric
Description
corrAt0
Standard Pearson at zero lag — same as Matrix
corrAtLag
Correlation at the optimal lag — the predictive signal
If corrAtLag >> corrAt0, the relationship is primarily predictive (one leads the other) rather than simultaneous.
Oracle Timing Note
Pyth Hermes pushes updates per asset independently. A lag of 1–2 ticks may reflect oracle update timing rather than true price discovery. Lags of 3+ ticks are more likely to reflect genuine market microstructure.
function crossCorrFull(ra, rb, maxLag) {
const out = [];
for (let k = -maxLag; k <= maxLag; k++) {
const v = crossCorrAtLag(ra, rb, k);
if (v !== null) out.push({ lag: k, corr: v });
}
return out;
}