Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Moving Average Algorithm - Basic Questions

Hi Guys,

I am trying to implement a basic moving average algorithm. The gist of the algorithm is

(1) Daily compute the 35 day moving average and a 1 day moving average for a given security. (2) If the value for 1 day moving average is lower than the 35 day moving average then short the security (3) Conversely if the value 1 day moving average is greater than the 35 day moving average then take a long position in the security

I coded up the algorithm and I am showing a 80% loss in capital :( I have a couple of basic questions

  1. Is there a particular kind of security that is more suitable for these kind of algorithms? I chose Apple just on a whim.
  2. What are the best practices for determining how much quantity of stock to buy/ short? Again I chose 100 units on a whim?
  3. For this particular algorithm, how do you decide whats the ideal time to get out of your position?

Lastly how do I link my algorithm/ results to this post?

2 responses

Hello Abhishek,

To add your algorithm and results to this discussion thread, just click the "Add Backtest" in the toolbar immediately above the text editor box. You'll then be able to select an algorithm and a specific backtest of that algorithm.

Regarding the algorithm you describe, it sounds like you are trying to apply a simple model to detect if an individual security is on an upward trend or a downward one, correct? If so (and I'm no expert), it seems your algorithm would be classified as momentum trading. One technique I've used for finding trial securities to run on Quantopian is to do relevant web searches. In your case, perhaps try "momentum stock screener" or similar such keywords.

In actual trading practice, you may want to investigate the differences between odd, round, and mixed lots (e.g. see http://ibkb.interactivebrokers.com/node/1062). For backtesting, I'm not sure that the lot size matters (but perhaps the Quantopian backtester should account for this factor).

Regarding when to get out of your position, you need some way of determining that your model no longer works (i.e. the security is no longer sufficiently "momentumish"). Not sure about that one...I think you'll have to do your homework on how to test for momentum in individual security prices.

Grant

Thanks Grant that helped a lot