How to Set Up and Test a Binary Trade

by Feb 6, 2019All Articles, Education

A binary arbitrage strategy is one where you buy A when condition X is true, and then sell A and buy B when condition X is no longer true.

Let’s take stocks vs bonds, where you want to buy stocks when they are relatively stronger than bonds, and buy bonds when they are relatively stronger than stocks.

This is possible to test in the Optuma back tester, but first we need to determine when one asset is stronger than the other by creating a ‌‌relative strength ratio chart. Here’s an example where we create a ratio chart of the S&P 500 Index ETF ($SPY) divided by the iShares 20+ Year Treasury Bond ETF ($TLT), and also its 50-period moving average (in blue):

When the black line is above the moving average then stocks are stronger than bonds, and weaker when below the moving average, so in our backtest we would want to buy SPY when the ratio crosses above the moving average, and then sell SPY and buy TLT when the ratio crosses below, because bonds are now relatively stronger. This is getting there but there is still a bit of whipsaw going on. To smooth the ratio and to prevent choppiness we can use a shorter-term moving average crossover to generate the signal.

Below shows the entry and exit signals when a 10-period moving average in orange crosses the 50-period:

So how do we test this in the Backtester? The first thing we need to do is to create a manual ‌‌Symbol List containing the two ticker symbols used in the test – in this example SPY and TLT, in a list which I’ve called SPY/TLT:

In the backtest setup we select the SPY/TLT symbol list under Back Test on Multiple Codes with the following entry formula. In this formula I am using the ISTICKER() function to select the appropriate symbol for the crossover.

Remember from a logic perspective that we want to buy SPY when the ratio crosses above the average. That condition will be true for both symbols, but the IsTicker() condition means that only the symbol which matches will be the one that is bought:

For the Exit criteria we use the opposite conditions, ie sell SPY when crosses below, and sell TLT when it crosses above. Copy the entry script formula and then change the last lines:

Because the strategy is binary (ie all your capital is either in stocks or bonds) the Equity Percentage should be set to 100%, before executing the test over the timeframe required.

Here’s the results over the last 5 years, starting with the SPY entry on March 6th 2014, showing the 37 trades with annualised returns of 6.8%, and a maximum drawdown of 14%:

But how does that compare with buying and holding stocks over that time? We can add that as a comparison code, and you can see that SPY would have out-performed the strategy over that timeframe (the red line in the equity curve window), with annualised returns of 10.2%, but with increased volatility, and a higher drawdown of 20.5%:

So maybe the signals can be tweaked, eg when the moving averages of the ratio chart are sloping up for the SPY entries, or when SPY is trading below its 50-period MA for the SPY exits. The point of this post is not to give you a trading strategy but to show you how you can set up binary strategies like this for yourself.

Another example is to buy Growth stocks when relatively stronger than Value stocks, and sell Growth and buy Value when vice versa. Gold is strongly negatively correlated to the US Dollar Index (DXY) so that could be another example using the ratio chart set up.

Now we have the setup in the Back Tester it’s just a matter of creating the symbol list for the required symbols, and tweaking the entry and exit formulas.

As always, we love to hear feedback so if you have any questions please comment below or contact us via support, and for scripting formula queries don’t forget to search the ‌‌Scripting Forum if you get stuck, and post a query if you can’t find the answer.

Share Link
Darren Hawkins, MSTA

Darren Hawkins, MSTA

Senior Software Specialist at Optuma

Darren is the senior Software Specialist at Optuma. He joined the company in 2009 after attending an introductory technical analysis course. Darren now instructs users all over the world, from experienced Wall Street traders and professional money managers to individual traders drawing their first trendlines.

Darren grew up in the UK and attended college in the USA where he earned a BA in Economics from St Mary's College of Maryland. He went on to spend a few years working at the Nasdaq Stock Market in Washington DC. Going on to live and work in Australia, the US and currently the UK, Darren has a broad understanding of the individual needs of traders, portfolio managers and investors utilising a wide range of methodologies.

In 2014 Darren passed the UK-based Society of Technical Analysts diploma course, and when not looking at charts he keeps a keen eye on England's cricket team - especially if they are playing against Australia. He lives in the Essex countryside in England, with wife Wendy and their labrador, Gabba.


Submit a Comment

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

Blog Signup

Pin It on Pinterest

Share This

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.