Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Ivy Portfolio 200-SMA

Assets: VTI, VEU, BND, VNQ, DBC

Buy: when monthly price > 200-day SMA
Sell: when monthly price < 200-day SMA

I would have figured that the performance would have been better...

How can I improve on this algorithm? Should I be accounting for dividends? Should I add some intelligence to how many shares 'n' should be bought/sold instead of using a fixed number?

I am new to a lot of this. Thanks in advance for the feedback.

4 responses

Hi Brian, thanks for sharing your algo.

Your plan to buy when price > 200-day SMA is called a momentum strategy (e.g. buying when the price goes up). The opposite would be a reversion strategy (e.g. buying when the stock is cheap).

I plotted capital used and cash available for your algo and found that you only used half of your starting cash on average. That would limit your gains.

If you are trying to recalculate the SMA every month then perhaps every 21 trading days would be better than 30 (which is six weeks).

The small initial capital ($10k) suggests you would be using this strategy manually. So picking a long interval between trades is smart.

I made some changes to your algo in the attached backtest:

1) changed from momentum to reversion strategy
2) used portfolio rebalancing to engage all starting capital
3) used 200-day SMA as a hint to under-buy overpriced stocks (consistent with reversion strategy)
4) rebalancing once per year (250 trading days)

I made some modifications to the original posted algorithm:

  • Use a fixed percentage position size, instead of fixed dollar amounts
  • Weighted the positions at 20% each

Backtest results attached (although I tested over a longer period).

Here are the results from the original time period vs. the algo in the original post. The main issue with the original implementation was position sizing properly, and the buy/sell signals were correctly implemented (although in the book, it's a 10-month moving average, but a 200 SMA should be close enough).

Total return: 19% vs. -11%.
Beta: 0.23
Sharpe: 0.09
Max drawdown: 18%

In the book he recommends manually checking the 200 day SMA only on the first day of every month. The reason for this is because the index dips just below every now and again just for a small period of time, and most of the time it recovers. If you trade every time it crosses the 200 line, you'll get whipsawed and lose money every time. There is another version of this strategy which entails opening your position when the price first crosses 5% above the 200 day SMA, and closes the position when it dips 5% below. Probably works better for algorithms.