Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
GLD & GDX algorithm

This is a work in process, but I figured I'd present it to the worldwide masses for feedback anyway. In a nutshell, it trades GLD & GDX, using the the difference in the dollar volume z-scores as an indicator, going long-short or short-long, respectively, depending on the difference in the z-scores. I can add more comments to the code, if there is interest, but it is pretty straightforward.

I welcome critiques (e.g. why this is a really bad idea) or improvements (e.g. clone and modify the code and post it).

Grant

8 responses

Here's an update, with less volatility. I replaced the two globals

upper_threshold = 1  
lower_threshold = -1  

with one

threshold = 1.5 # z-score difference threshold  

Grant

Here's an example with SPY & SH. The only other change to the algorithm posted immediately above was to lower the threshold for trading to:

threshold = 0.5 # z-score difference threshold  

--Grant

Not sure if it was intended but this ends up going long/short many multiples the amount of starting cash and does so quite rapidly. This leads to a some what misleading cumulative performance chart.

I guess the next step is to try a 2D parameter study by varying the entry/exit thresholds across a range and re-calculating RiskMetrics? If you have a smooth parameter surface, you should be able to optimise the strategy this way (of course, with all the usual curve-fitting caveats!).

Thanks Brent,

Regarding the long-short positions, with a positive cash balance, any idea what the limits would be with a broker (e.g. Interactive Brokers)? Also, I'm wondering how a broker would treat an inverse ETF like SH. For example, if I'm short SPY and long SH, I would have two positions that would both profit by a downturn in SPY and both would result in a loss if there is an uptick in SPY.

Note that the cost of shorting is not included (see https://www.quantopian.com/posts/cost-of-borrowing-on-margin).

Grant

Thanks Michael,

I've played around with the thresholds and backtest periods, but have not done a full parameter study, as you suggest. I think the first step is to make sure that the approach is realistic...I suspect that I've missed one or more important considerations.

Grant

It's good to know that the GLD/GDX pair is still a potentially viable strategy, especially after being so widely publicised by Ernie Chan!

@Grant, for retail trading I'm assuming 50% margin (2:1). e.g. the ability to invest twice your starting cash.

If your position drops to 25% margin (4:1) then a margin call would force you to close some positions.

These margin requirements are pretty standard. There are some exceptions for hedge situations where you can prove your risk is small because of opposing positions.