SnowblindTrade

Pair Trade Methodology for Tech Stocks

NASDAQ:GOOG   Alphabet Inc (Google) Class C
Hello everyone,
this is my (last minute) submission for the pair trade competition
Table of Contents:

1. Intro
2. Correlation Matrix
3. Outcome Permutation
4. Fractals & Price Deviation Phases
5. Levels & Open Space
6. Further Hedging & Strategies
7. Final Setup
8. Scripts & References


I quickly scraped this together (and actually ran out of time), so this is far from being a thorough analysis, but I extensively draw out the methodology. For my base assumption I take the SPX and as a point of reference the end of March/start of April, when the market had its last peak and turned downwards afterwards. I'll focus mostly on tech stocks.

Since this is a pair trade competition, it is of key importance that we do find highly correlated assets first. We further select assets that make good candidates for long or short trades and talk a little bit about how we can actually hedge our trades while positioning us for good returns.


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Correlation Matrix
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Correlation itself is probably a topic for a whole thesis so I keep it short, yet there are a few important points to consider:

  • Timeframe/Granularity (5m, 1h, 4h, 1d, 1W, etc.)
  • Window length (10, 20, 50, 100, 200, or whatever value)
  • Series (close, hlc3, ohlc4, etc.)

Your results will vary (and sometimes even completely flip) depending on those parameters.
I had chosen to go with series hlc3, timeframe 4h and window 130 (2 * 5 * 13; 2x 4h-candle * 5 days week * 13 weeks (1 quarter)).
I made the selection for the following symbols: SHOP , META , GOOG , TSLA , and this was the resulting correlation matrix (shoutout to Ricardo Santos for his initial script implementation).


As you can see, they are highly correlated (> 0.8) and very highly correlated (> 0.9). This actually satisfies the correlation necessity for a pair trade.

Now this essentially makes up our basket for a good mix of short and long positions by further reducing the risk by spreading across multiple assets (this is mostly exemplary).


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Outcome Permutation
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Now, there are essentially 6 different outcomes. Let's define our long symbol as 'WINNER' and our short symbol as 'LOOSER':

  • Both Uptrend; WINNER > LOOSER: Profit (Hedged by both symbols moving in the same direction with our long being more effective)
  • Both Uptrend; LOOSER > WINNER: Loss
  • One Uptrend/One Downtrend; WINNER > LOOSER: Profit (This is what we hope for)
  • One Uptrend/One Downtrend; WINNER > LOOSER: Loss (worst case)
  • Both Downtrend; WINNER > LOOSER: Profit (Hedged by both symbols moving in the same direction with our short being more effective)
  • Both Uptrend; LOOSER > WINNER: Loss

The important takeaway is that there are three scenarios where we take a profit. Two scenarios where we could get unlucky by betting on the wrong symbol in the trend. And one scenario where we would set on completely opposing trends for both symbols. Ignoring any other hedging strategies, the goal is to make a decent analysis that shifts the probability dramatically in your favor.


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Fractals & Price Deviation Phases
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The lower the timeframe, the better you'll be able to model the stochastic process (for the given TF). Why? Simply speaking, you have more information at hand. Take EMAs for example. You can start at the monthly, take your EMAs (50, 100, 200, etc.), drop down to the weekly, take your EMAs there and repeat the process (down to the 1s if you like). The further down you go the more information you accumulate (depending on the timeframe some information is more relevant than other), the more precise your modeling approach can be. This works extremely well for 5m/15m and is still very valid for 1h/4h. The higher the timeframe, the more you loose in precision (accuracy quite often stays pretty good though). Since the competition asked for 1week + "ideas", I'll be using the 4h timeframe as my highest resolution (as in most information available) and scale into higher timeframes from there.

This is where fractals and price deviation come into play. Probably the most famous representation for price deviation are Bollinger Bands (essentially being 2stdev over a SMA20), which we'll be using for this. We'll be concerned with 4h, 1D, 1W, 1M version of them and quantify where they are in their respective BBW (Bollinger Bands Width) what I just term 'price deviation phase'. This gives us a heuristic for fast determination what asset might be over/undervalued (over/underperforming).

This picture shows the graphical representation for the SPX (1D, 1W, 1M)


In order to make this comparable this needs to be standardized between +1 (Upper level), 0 (Base Level) and -1 (Lower Level). For SPX from the image above those values are: 1D: -0.32 | 1W: -0.79 | 1M: -0.64

For the selected symbols those are the extracted values (1st July 2022 2pm CET):

| SYMBOL | 1D | 1W | 1M |
--------------------------------
| GOOG | -0.45 | -0.62 | -0.32 |
| TSLA | -0.41 | -0.62 | -0.39 |
| SHOP | -0.60 | -0.63 | -1.01 |
| META | -0.40 | -0.97 | -1.04 |

As you can see, all of the are performing somewhat the same on the 1D and 1W, but GOOG and TSLA performing significantly better for the 1M than SHOP and META. This translates to our assumption that they will perform better in the future.

# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Levels & Open Space
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Levels (aka Liquidity zones, pivots, what not) essentially being those historic price levels that hold statistical value (and significance). In the same spirit as previously, timeframes are hugely important. The higher the timeframe (amongst many parameters), the more important the level on a macro/global scale. The lower the timeframe, the more important it is in a local context, but looses meaning the further you zoom out. 4h levels have meaning in the 4h timeframe (while 1M levels only have some general direction), but loose all resemblance at the 1M where they just go up in the 1M candle so to say.

Open spaces are the space between significant levels. This quite often is the area where price "jumps". Not to get into to much detail, but there is just nothing in between. This is a pretty good showcase for the SPX now (having had it's ATH recently). On the way up to its ATH, "it" crossed regions it was never in before. So now on its way down it crosses an area where it only ever has price levels that where created very recently. So there aren't much levels that hold statistical significance, just dynamically computed values. So, the keep it short, the proposition is that price moves from significant level (whether historic or dynamic) to significant level. The less such levels exist in that area (or have been "invalidated" by some metric), the more room price has to jump.

And this is what we want to identify. This is part of the analysis of whether an asset is strong candidate (doesn't matter short or long). The criteria are:

Long: Uptrend has big open spaces and few levels while downtrend has small open spaces and a lot of levels.
Short: Uptrend has small open spaces and a lot of levels. while downtrend has big open spaces and few levels.


Just to quickly make the point (not considering dynamic levels): SPX has the quite some space upwards once it breaks its latest high ~3945 to two levels, once with ~3.5% and the other time with ~5.5%. Downwards the next level comes at roughly -2.5% after breaking the last low at ~3630.

(I'll probably make a follow up post with some detailed charts which I just hadn't had the time to include here. Sorry folks!)


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Further Hedging & Strategies
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Since everything is always based on some conditions, we could improve all of this by actually entering (or not entering) any trade given a specific set of conditions. For example, SHOP didn't (aka won't) drop far enough, so we simply won't go short on it and completely ignore it. In short, we're not entering all trades at the same time, but when it makes sense given the "DNA" (aka all kinds of statistical properties) of each symbol and it's current situation/behaviour.

The same goes for exiting any open positions. It very much depends on the probability distribution at any given point in time. So for example, if we made quite a profit with an asset (by it "jumping" through an empty zone), instead of risking not being able to push through the next level (and risking a bounce/sell-off), we simply take our profit and call it a day. Now, since we're a taking apples out of our basket with this, the more and more we do this with any asset, the less we are actually hedged in our still open positions. So you should have some strategy to exit those positions (or rebalance) them as well.

And of course it does make sense to use stop loss exits at ~major levels. This is for the "loss scenarios" described in the outcome permutation at the start.


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Final Setup
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

| SYMBOL | Price | Target Level | TYPE |
--------------------------------
| GOOG | 2187.45 | 2500 (~15%) | LONG |
| TSLA | 673.42 | 800 (~20%) | LONG |
| SHOP | 31.24 | 21 (~30%) | SHORT |
| META | 161.25 | 140 (~12%) | SHORT |


# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Scripts & References
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

* Correlation Matrix (by RicardoSantos)
* ZigZag & Levels (by me; uses dynamic ATR compression instead of lookback and fixed thresholds)
* MTF Price Deviation (by me)

Probably gonna release my scripts once they are finished (and I find more time).


Thanks for reading and a big thanks to the team at TradingView for providing this stellar piece of software!
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.