Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Please give me feedback! Capturing momentum in the difference between the moving averages

The most interesting i think that happened here is that my algo managed to avoid the crash without liquidating my entire portfolio.

5 responses

Daniel,

Looks interesting. Would you mind providing an outline of how the algorithm works? I'd like to read through the code, but it'll be easier to understand if I have a sense of the logic first.

Also, how did you arrive at the particular collection of securities to trade?

Thanks,

Grant

Sure thing. Basically I am taking the difference between a short moving average and a long one and I trade based on the changes of it.
If the difference is bigger than 0 its a buy signal since the shorter one is going up faster and same for the downside. Since
there is a lot of noise i put the level of significance of the difference at .25 of the maximum of the past differences meaning
it wont trade based on small fluctuations. I simply chose random stocks that i thought would be very liquid thats all.

Daniel,

Some feedback:

  • Based on my own tinkering, and looking at others' backtests, my sense is that the "Great Recession" event of 2008-2009 skews results. The question that ends up answered is "Can I write an algorithm that would avoid a prolonged market downturn?" I've attached a backtest using your algorithm, starting in 2012 to illustrate my point. There are some gains in 2012, but then the returns are basically flat after that.
  • I can't tell if you are exceeding margin limits (which would definitely make your result unrealistic). It'd be nice if there were a built-in monitor. You might search the forum for some examples of how to check that you are always conforming.

Grant

Hi Grant,

Thank you for your input. The reason I started backtesting it so early is that I wanted to avoid the bias of a bull market.
Any advice on how to make my algo better? I noticed that just defining notional and context.max/min_notional doesnt
really limit order limit. Iv had many cases where i had notional limit and yet the algo was going haywire.

Daniel,

Here is a discussion regarding staying within margin limits:

https://www.quantopian.com/posts/spy-and-sh-z-score-indicator

I haven't sorted through all of the details provided by Dennis C yet, but perhaps you'll find it useful.

Grant