Price consolidation and an application of the Jaccard Index

Yesterday, while working on one of my projects to do with quantifying areas of concentrated liquidity, I arrived at a possibly interesting application of, and use for, the Jaccard Index.

The problem was to construct some sort of normalised measure for the overlap of price bars. I basically defined a consolidation range, and I needed a way to mathematically express how repeated overlap between adjacent candles can be interpreted as evidence that price is repeatedly trading through the same territory rather than moving directionally away from it. And in the context of this wider calculation, the Jaccard Index proved extremely useful.

As an example, consider the following the construction.

For each bar \(t \), define the observed price range by

\( \mathcal R_t=[L_t,H_t],\)

where \(H_t \) is the high price and \(L_t\) is the low price at time \(t \). The overlap length between two adjacent ranges can be found to take the form

\( \ell_t:=\left|\mathcal R_t\cap\mathcal R_{t-1}\right|\)

in terms of interval length. From this, the exact size of the shared price range (i.e., the overlap) between two consecutive trading periods can be written as

\(\ell_t =\max\left\{0,\,\min(H_t,H_{t-1})-\max(L_t,L_{t-1})\right\},\)

in which \( \ell_t \) measures the length and the amount of shared price territory, expressed in price units. But this quantity needs to be normalised in some way, since, more appropriately, what is really needed is the relative overlap. The Jaccard Index, it turns out, provides just such a natural normalisation. By the principle of inclusion-exclusion,

\(\left|\mathcal R_t\cup\mathcal R_{t-1}\right|=(H_t-L_t)+(H_{t-1}-L_{t-1})-\ell_t, \)

it is straightforward to obtain the normalised overlap measure

\(O_t:=\frac{\left|\mathcal R_t\cap\mathcal R_{t-1}\right|}{\left|\mathcal R_t\cup\mathcal R_{t-1}\right|}=\frac{\ell_t}{(H_t-L_t)+(H_{t-1}-L_{t-1})-\ell_t},\)

which is indeed a form of the Jaccard Index. How to interpret this? \(O_t \) produces a dimensionless quantity between zero and one. A value of zero indicates no shared price territory, while a value of one indicates identical ranges.

The useful feature of the Jaccard index in this setting is that it measures precisely the quantity I required: overlap relative to the total territory covered by both bars.

I am not sure whether this is common usage. I am primarily familiar with the Jaccard Index from statistics, and also occasionally it seen in machine learning literature, in which one might use it to measure similarity between sets, binary features, labels, etc. There is some reference of its use in mathematical finance. For instance, I've seen in a few academic papers discussion about the price overlap rate, where one similarly defines price intervals as sets and calculates their Jaccard index. So that is a nice sanity check.

Subscribe to The Stochastic Ledger

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe