Dual Momentum Implementation in Zorro

In the previous article called Dual Momentum Strategy Backtest in R you could see that the backtest results correspond to a large degree with the results published on Antonacci's website. But the code is of little value beside the comparison as we can't use it for trading. So it's time to move on towards the actual deployment.

The conversion of the trading logic into Zorro code is not completely straightforward. One small complication is the usage of monthly bars. Maximum value of BarPeriod is 1440 (one day) and the time base of the history data files has to be equal or less than the bar period (so we can't use for example monthly time base).

There are basically two solutions. We can either approximate the monthly closing prices by using daily closing prices and fixed number of days (e.g. 252) to look back circa one year. Or we can utilize tdm() and tom() functions, store monthly closing prices in an array and use them in the subsequent computations.

I've decided to implement both to see if there is a noticeable difference in performance between these two options. It seems that the results are almost identical. For a backtest starting in June 2008 the annual return is 17% in both cases and Sharpe ratio is 0.63 and 0.65 respectively. So the main advantage of using monthly closing prices is that it's possible to compare the allocations with Antonacci's website.

You can download the code here. Don't forget to add the asset entry to AssetsFix.csv file for all the instruments you wish to use. The rest should be straightforward. If you have any questions or if you find a bug in the code please post a comment in the discussion below.

Schizo Frenetik

Read more posts by this author.

Subscribe to StatsMage — Quant Ideas Worth Sharing

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!