When trading moved into the modern age, with sophisticated trading system development software that gave individual traders the ability to test their ideas on the market without adding a professional programmer to the payroll, certain disciplines were left behind. This wasn’t because these methods lacked merit, but they simply didn’t easily transfer into most popular trading software.
One of those disciplines was spread trading. Spread trading offers a unique mix of low margins, pronounced trends and hidden opportunities that appeal to many traders, but because most programs don’t cleanly handle spreads, on either the testing or the execution side, they have been left out of most individual traders’ toolboxes.
This second of two parts on spreads will look at specific applications in spreads to demonstrate how new technologies are extending the power of computers to these time-tested markets.
ALL CRACKED UP
The crack spread displays the relationship between energy contracts traded by integrated oil companies. Crack spreads provide a natural economic hedge against adverse price movements. Given a target optimal product mix, an independent oil refiner can work to hedge itself against adverse price movements by buying oil futures and selling futures based on its primary refined products, according to the proportions of its optimal mix.
Refiners who wish to hedge their price exposure will use a crack ratio usually expressed as X:Y:Z, where X represents a number of barrels of crude oil, Y represents a number of gallons of gasoline and Z represents a number of barrels of distillate fuel oil. The only constraint is that X = Y + Z. The hedger buys X barrels of crude oil and sells Y gallon of gasoline and Z barrels of distillate in the futures market. Widely used crack spread ratios include 3:2:1, 5:3:2 and 2:1:1. The 3:2:1 crack spread is the most popular of these, and widely quoted crack spread benchmarks are the “Gulf Coast 3:2:1” and the “Chicago 3:2:1.”
Different numbers of contracts must be traded for each component of the spread. For this reason, calculating the minimum move value so results can be converted to dollars is not always easy. This situation also can come up with spreads that do not have fixed ratios and they are based on market volatility in dollars. This often happens with equity indexes or individual stocks.
In a perfect world, a backtesting platform would correctly account for these complex issues. In addition, the platform would need to be available to backtest over a large number of years using individual contracts and still provide consolidated results.
BACKTESTING SPREADS
The approach we’ll cover requires portfolio analysis, intermarket analysis and the ability to handle individual contracts, testing our strategies on them only when they are active. This last point is a significant one, as it allows us to avoid the common pitfalls of back-adjusted price data and to test our strategies on individual contract prices, just as they would have traded through time.
Also critical is the portfolio-level analysis, which allows us to use December corn and December wheat for one intermarket pair and March corn and wheat for the next. This walk-through uses TradersStudio (software developed by Ruggiero Associates) because it has features that address all of these concerns.
To review, intermarket spread trading requires the trader to buy one market while selling another. The contracts are in the same position and must have some economic relationship to be considered a true spread. The transaction does not have to occur at the same time; it is possible to leg into and out of spread positions.
One way to accomplish this is to use a “Trade Plan,” which can trade multiple systems across a portfolio on the same account. In this case, we could have created two systems to trade corn and wheat. If we had a three-way spread such as the crack spread the Trade Plan feature would have been a better solution, but for the two-way grain spread, it’s better to tackle this at the session level and rely on the inter-market analysis and portfolio level trading capabilities of the software.
CONTRACT SELECTION
Before we get to the actual trader, we need to cover some basic logistical concerns. The first step is to create a function that returns when a given contract is the actively traded market. We will use the following format C_1976U.CSV. The contract symbol is the first two letters, the year is the next four and the contract month symbol is the last digit (see “Contract months, below) followed by the file extension. This will be compared to the current date and will be used to filter the system so it only trades a particular contract month while the contract is active.

We are using Pinnacle Deep historic price data and will use a fixed expiration date of the 22nd of the month prior to the contract expiration month. This means that the last trading date for corn and wheat for each contract is Feb. 22, April 22, June 22, Aug. 22 and Nov. 22.
The code in “Which contract for corn?” (below) puts this logic into a function. It disables a contract month when it is not the active month, but it lets the indicators still calculate.

When trading single contracts, we want the system to buy, sell, exit long and exit short positions. The next step is to create functions for order placement. Remember, if the contract is no longer the active one, positions in that market must be exited.
This is the buy entry code:
SubBuySingleContract(Signal
Name,Size,Price,OrderType,Order
Time)
If IsActiveCornContract () Then
Buy(SignalName,Size, Price, OrderType,OrderTime)
Else
ExitAllTrades
End If
End Sub
The sell routine for spreads is as follows:
Sub
SellSingleContract(SignalName,
Size, Price, OrderType, OrderTime)
If IsActiveCornContract() Then
Sell(SignalName,Size,Price,
OrderType,OrderTime)
Else
ExitAllTrades
End If
End Sub
From here, we can use these functions to create a simple system:
Sub CornWheatSpread(SLen)
Dim MKSym As String
Dim CleanSymbol As String
Dim Spread As BarArray
Spread = Close - Close Of independent1
If Spread = Highest(Spread,
SLen,0) Then
BuySingleContract(thismarket.
Symbol(0)&”BuySide”,1,0,Market,
Day)
End If
If Spread = Lowest(Spread,Slen,0) Then
sellsinglecontract(thismarket.Symbol(0)&”SellSide”,1,0,Market,Day)
End If
End Sub
These simple rules instruct the system to buy if the spread reaches a new high and sell if it reaches a new low. Using TradersStudio, we are able to use individual contracts for both corn and wheat and set the inter-market spread to the sister contract in the other market.
One logical approach would be to pair the May 2007 corn contract with the May 2007 wheat contract and the May 2003 wheat contract with the 2003 May corn contract.
“In and out” (below) shows how these contracts are paired in TradersStudio.

Even though the ratio is one-to-one in this spread, wheat is more volatile on a dollar basis. So, most of the profits can be expected to come from the wheat side of the spread whether it be buying or selling. The example test period ran from July 7, 2001, to April 9, 2007, and the system did not perform well. It averaged about $35 per trade. This is not important because our goal was to show how to develop code for backtesting spreads and not to develop a spread system.
NO SO EASY
In our system, we do not look at the current symbol because our logic is the mirror image. When the corn/wheat spread hits new highs, the wheat/corn spread hits new lows.
If a system is not designed to be a mirror image (for example, the Relative Strength Index of the spread was used and the buy signal was at 20 and the sell signal was at 90), we will not have the trades paired and we will have times when the positions are not hedged. If we want to develop more complex spreading systems, additional code is needed to address these issues.
In TradersStudio, the thismarket.Symbol(SeriesNo) can extract the symbol for the traded market by using a SeriesNo of ‘0’ and also for the child series by using a SeriesNo of 1,2 etc. This allows us to write more complex spread logic, which could perform analysis on the energy crack spread, for example.
In the energy crack spread, crude is traded with unleaded gasoline and distillate oil. In the spread analysis based on the symbol, we can size the number of contracts to trade.
If we use the Trade Plan capabilities, we can create three different systems and combine them using a Trade Plan to analyze and trade the crack spread. This would be the simplest way to implement a system for trading this spread.
In the early to mid-1980s, simple trend-following methods worked quite well. But as more people started using trading systems based on these techniques, it made developing profitable systems with large returns a more difficult proposition. Now, with the ability to backtest spread strategies this frontier might re-present itself.
Consider the charts in “A new day” (below). In the first chart, corn is shown in the top panel, wheat is in the middle and the spread appears in the bottom. Clearly, the spread is much smoother than the actual market data. The second charts show another period when corn and wheat were not trading so much. Here, the corn market was choppy but the spread shows a big uptrend followed by a big downtrend.

With new technology, these markets can be backtested just as individual contracts have been for more than a decade. This approach to spread trading is an exciting area of research that could give relief to system traders frustrated with the futility of classic systems in modern individual markets.
Murray A. Ruggiero Jr. is a consultant in East Haven, Conn. His firm, Ruggiero Associates develops market-timing systems. He is editor-in-chief of Inside Advantage Gold Club (www.iagoldclub.com) and author of Cybernetic Trading Strategies (John Wiley & Sons). E-mail him at ruggieroassoc@aol.com.
