Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can someone look at my implementation please?

I am trying to follow the reddit post: http://www.reddit.com/r/investing/comments/1fr0z8/analysis_of_a_trading_strategy_buy_the_10_day_low/

The gist of the algorithm is:

  1. Buy when a stock has reached a new 10 day low and is trading above
    its 50 and 200 day moving average.
  2. Sell when the price reaches a new
    10 day high, drops below the 50 day moving average, or has been open
    for 10 days.

I am trying to figure out where the algorithm is messing up. I start at $5,000 notional and go until it hits $100,000,000 and then cap it there. I highly doubt this algorithm is printing money and I was hoping someone could look at this and help me figure out where I went wrong?

3 responses

Hello Charlie,

This backtest shows your use of cash. At one stage you are borrowing more than $400 Million. This seems to be because you calculate 'notional' at the start of the day and then on some days make a number of large long trades based on that unchanging figure.

P.

Hello Charlie,

I wanted a quick way to control the use of cash so I amended 'notional' with each trade. I'm not saying it's a good solution to the problem. I tested with two SIDs and left that line uncommented in error.

(On a more general point you use a 200-day moving average like many of us. With your start date as it is you miss the worst of 2008. Someone suggested once that these sorts of algo should maybe buy & hold SPY for the 200-days to make a more reasonable comparison with the benchmark. Just a thought. And the upcoming 'history' feature may resolve the problem anyway.)

P.

Peter, thanks for your response. I think you have part slightly mistaken though. I am (probably improperly I now realize) using the term nortional to name all of my assets value. I use context.growing_notional to look at the max amount of money I have. If you look at elif buy_signal you can see at the end I am checking notional < context.growing_notional.

I start my growing_notional at 5000. Every time I sell the stock (at a loss or at a gain) I add that to my growing_notional. As I say this though, I realize what I need to do is get the difference between my buy price and my sell price and add that to my growing_notional rather than the whole sale price. That's why my money grew so fast!

Thanks for looking at it and also thanks for showing me the record method. That one was new to me. Time to fix my algorithm and find out what the next problem will be! haha