Tag: quant

Index pair-wise Correlation

Sometimes, it feels like all stocks in an index are moving in the same direction. Very rarely is there full “chaos.” Sometimes, even when there is some dispersion, it is overshadowed by larger moves in a few index heavy-weights. To get some intuition around this, we calculated the pair-wise correlation of the NIFTY 50 constituents since 2015 across different lookbacks, bucketed the median daily correlations into quintiles and plotted them.

If you do an rle, you’ll get an idea about the number of consecutive days spent in each quintile. It looks like quintile 5, representing a highly correlated state, is sort of sticky.

For example, if you zoom into the 20-day lookback distribution, notice how quintile 5 stands out.

It appears that low-correlation environments are actually not that sticky. So, if you see a quintile 5 form, bet on it lasting a few days.

Mahalanobis Distance with Trend

Previously, we constructed a portfolio that switches between equities and bonds based on the Mahalanobis distance between them. Here, keeping everything else the same, we add a trend filter to the same set of indices.

The composite regime-switching model ends up with superior Sharpe Ratios. However, if you don’t switch to bonds (and stay in cash, earning zero), then you maybe better off with a simple trend model.

The alpha seems to be in earning the risk-free rate when things are “bad” and getting long equities only when things are “favorable.”

Code and charts are on github.

Mahalanobis Distance

We are big fans on using distance measures while prospecting for investment strategies. Previously:

Recently, we came across an interesting paper, Skulls, Financial Turbulence, and Risk Management, Mark Kritzman, CFA, and Yuanzhen Li, that uses the Mahalanobis distance to construct a turbulence index. The basic idea is that the more asset returns break from the past, the more “significant” a market event.

We took the basic intuition behind this and constructed a portfolio that switches between equities and bonds based on the Mahalanobis distance between them.

The out-of-sample results, factoring in transaction costs, look promising but doesn’t really stand out compared to other, more dumber, strategies that avoid steep drawdowns. However, two points over the Midcap buy & hold cannot be dismissed outright.

The code, charts and paper are on github.

Adventures in Pattern Matching, Part I

Hypothesis: If a price segment is similar to a set of historical segments, then there should be a correlation between historical and future returns.

Setup: Take 60-minute segments of 1-minute bars. Match them with 200 of the most recent days’ with times aligned. Take the top 40 days with the closest match and calculate their median next 30-minute returns. Plot the median vs. actual.


  1. Non-overlapping segments. Its can be argued that patterns don’t start and stop and perfectly aligned boundaries.
  2. Most-recent 200 day look-back period. What if that’s not enough? Or too much?
  3. 30-minute prediction. Too short? Too long?

Verdict: There is no discernable relationship.

Code: github

Related: Euclidean Distance for Pattern Matching

Volume Clock, Candles

Our previous post showed how a chrono-clock frequency can be translated into a volume-clock frequency. The aggregated High-Low price data looks very similar to a candle-stick chart.

The difference between the high and the low on each “candle” of the longest living contract doesn’t vary a lot between the two clocks.

The distribution is based on a month’s worth of streaming data. As we accumulate more data points, it is likely that the divergence between the Chrono-Clock and the Volume-Clock increases.