Price consolidation and an application of the Jaccard Index
Yesterday, while working on one of my projects, I arrived at a possibly interesting application of, and use for, the Jaccard Index.
The problem was to construct a normalised measure of internal overlap within a price consolidation. 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. It turns out that, in my much more lengthy mathematical construction, the Jaccard Index proved extremely useful. The basic idea of its application is as follows.
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 so that
\(\ell_t =\max\left\{0,\,\min(H_t,H_{t-1})-\max(L_t,L_{t-1})\right\}.\)
As I show, \(\ell_t \) measures the length, hence, and the amount of shared price territory, expressed in price units. It is therefore not directly comparable across instruments or volatility regimes. The Jaccard Index provides 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.\)
The normalised overlap measure was found to be
\(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 a form of the Jaccard Index. \(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 know of the Jaccard Index from statistics, and also occasionally in machine learning, in which one might use it to measure similarity between sets, binary features, labels, or spatial regions. There is some reference of its use in mathematical finance, albeit not necessarily in the context I required (that I have seen). That said, in the context of my wider calculation, it seems reasonable, and I suppose serves a nice example of a general mathematical idea becoming useful in a setting for which it was not necessarily designed.