Bonds or Stocks? Trading Markets based on Momentum

Imagine you would like to design a trading strategy that either invests in the stock market or invests in bonds. This blog will show you how it is done using a momentum indicator. I use a flexible formula language with one piece of code for trading more than one instrument. To have an easy to program example, I created a strategy which invests in an S&P 500 ETF or an 10-20y bond ETF.

A simple momentum indicator will be the main signal:

  • If stocks momentum is higher than bonds momentum the strategy will invest in the stock ETF.
  • Otherwise the money will be allocated in the bond ETF.

Have a look at the screenshot and you will see how the final strategy will look like:

Systematic Momentum Trading for switching between Bonds and Stocks

Data1 and Data2

As momentum will decide in which market the strategy wants to invest, we first have to calculate the momentum of stocks and bonds. We will use a similar syntax as we did in the multiple time frame example, using close of … to specify which data should be used.

equilla_code-for-trading-two-instruments-based-on-momentum

Two Indicators in one Go

I intentionally made this the “two things” blog. We trade 2 markets, and we have the possibility to select two indicators. You will be able to chose if you want to use momentum or rate of change. The input rocmom(roc, mom) will give you a drop down menu on the strategies properties page and you will be able to select one of them.

For the calculation of the indicators we will simply use close and close of data2 to differ between stocks and bonds. When you drag and drop the strategy on your chart, containing two data series, a menu will open and you will be able to select which is the stock and which is the bond data.

Two Periods per Momentum Indicator

To keep up with the two things idea, I also used a double momentum. This type of indicator is the sum of a momentum indicator with a long long and short setting and it can give you the best of both worlds. Go with the long-term trend, but also show the short-term fluctuations.

For displaying the indicator in a sub chart, and not on the chart (as you would want an average to be displayed), I used the meta property at the beginning of the chart.

Trading Data1 and Data2

The main takeaway of this blog is the syntax of the buy and sell commands in line 27 and 28. As you can see, the buy/sell command is bound to a specific data set. If you just write “buy on close”, then data1 will be traded. In case you want to trade a different data set, you have to reference it (trading data2) and also reference the right price (close of data2). If you got a more complex strategy, then you could also use data3, data4, data5…

Optimizing a Multiple Instrument Strategy

Optimize Momentum Strategy to invest in Bonds or Stocks

Optimizing a multiple instruments strategy basically works the same way as the optimization of a single instrument strategy. Open the optimizer, select the parameters you would like to optimize and start the optimization. There is only one important difference when it comes to displaying the results: Instead of just showing the profit of the stock ETF or the bond ETF, you want to show the total profit of the strategy. Therefore you will have to select the global statistics. On the screenshot above I have selected the metric “global account size required” to find the set of parameters which would give me the minimum drawdown.

Keep researching,
Philipp

***

Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Thomson Reuters Eikon.

One thought on “Bonds or Stocks? Trading Markets based on Momentum

  1. I remember a phrase from years ago. ‘Follow the Money’. Cant remember the film but your post is a good reminder and a key identifier to where the money is going.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to this Blog