Dual Momentum – Stocks and Bonds

Here is a link to a version of a Dual Momentum system I drafted a while ago in Python/Pandas, using a Jupyter Notebook:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
view raw dual_momentum.ipynb hosted with ❤ by GitHub

And here are the data files I used:

For my stock data I used the Wilshire 5000 Total Market Index which I obtained from the Federal Reserve here.

For Bonds, I concatenated US Long Bond futures (if I recall correctly) and for cash I applied the 3 Month US T Bill rate to create a cash time series.

I have not revisited this code in a while but it does demonstrate a number of useful things. Although no slippage or commission is included, the back test demonstrates how effective such a system can be in generating a risk adjusted return higher than simple buy and hold index investing.

If stocks are in a downtrend, you reinvest the portfolio in bonds. If both stocks and bonds are in a downtrend, you go to cash. Clearly it is not always going to work – markets have a habit of catching you out. 1987 was a classic example of an almost instantaneous crash where few (if any) trend indicators would have saved your bacon.

Nonetheless, for believers in momentum trading, this example might provide some amusement.

The other reason I posted this system, was in view of my recent frustration with OPS – “Other People’s Software”. Or more precisely Online IDEs such as Quantopian and Quantconnect.

As anyone who has ever made the attempt will be able to attest, learning someone else’s back testing engine is a frustrating and time consuming task.

Having got thoroughly pissed off with both Quantconnect and Quantopian for differing reasons, I was tempted to take a look at Backtrader. I was planning to download it and use its connection to the Interactive Broker API. Then NINFI struck (No Idea and No F*****g Interest).

After weeks of learning Quantconnect (which ended in a frustrating dead end for me) I just could not face yet another back testing engine. Even one I could download and use on my own data.

The point is this – if you have a passing knowledge of Python, it is probably quicker and certainly far less frustrating just to draft your own ideas from scratch. Unless you want something all singing, all dancing; the Universal Computer of the trading world.

You have vast resources to rely on with Python – not the least being StackExchange. Somebody somewhere will have encountered just your problem before and will have written the matter up for you.

By contrast, with online IDEs and OPS, you will be relying on a much smaller group of users who will have asked and answered a much smaller selection of questions. What you don’t understand won’t be covered. With a massive and general purpose software infrastructure like Python and its common dependents, someone, somewhere will have exactly the answer to what you want to know.

Your hard earned knowledge of Geekconnect or Nerdtopian will be of relatively little benefit once you have to shift somewhere else. With Python etc, yes the language is constantly developing but in general your knowledge will be far more transportable.

Anyway those are my thoughts, and I will stick with them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s