Profile Picture

Futures backtesting against non-backadjusted contracts

Posted By Omega1 5 Years Ago
Posted Monday June 18 2012

I need to do some testing against futures data that isn't distorted by backadjustment. That presents me with some problems as futures data is split across separate, overlapping contracts with different expiry dates.

I realise that I need to do the following:

1. Contract Selection: Of the available contracts devise a mechnism to define contracts as tradeable or not.

2. Maintain a continuous set of results: My assumption is that, by default, 10 contracts would result in 10 backtests with 10 results. How to maintain a single simulation while rolling between contracts isn't clear at all.

3. Edge effects: Proper handing of edge effects when rolling between contracts.

4. Realism: The mechanics used for backtest should also work with live data. I presume that the way Rightedge works will protect me from having to worry too much about this.

As it stands RE doesn't seem to offer any infrastrucure that can give users a headstart in tackling continuous backtests of futures contracts. Also, how data is managed during a simulation doesn't appear to be well documented either, ie. in understanding the objects involved in managing/proceessing data for a backtest I can then formulate a way to manage the data for a realistic simulation. I'm assuming that easily manageable tweaks of what's already there will work of course - I really don't know.

If anyone out there has been able to implement the kind of backtest I'm alluding to I'd really appreciate it if you could explain how to go about it so that I can look at doing this myself. Unfortunately, my inexperience with RE and the lack of depth in the documentation means I'm in rather a murky place as I contemplate this right now...



Posted Tuesday June 19 2012
Practically everything I do is related to futures, here's what I do:

I do not use ANY RE indicators, only UserSeries to display a strategy's internal state.

I run a separate backtest (or optimisation) for each contract in order of expiry date.
At the end of a contract's backtest I write all required data to be "rolled" to the next contract to file.
On the next expiring contract run, I read the file and (and possibly adjust for the premium or discount between it and the previous contract) continue from there.

I use the contract expiry date and a "number of contract tail days" (i.e 7 days for currencies, 30 days for Crude Oill, 10 days for Corn) to determine when not to process bars from a contract that is about to expire and when to start processing bars from the next incoming contract.

If June EUR.GLOBEX expires on 20th then do not use bars after 20-7 = 13th and start using bars of the Sep contract after 13th.

I have written a "RightEdge Controller" which automatically starts RE from the commandline with arguments defining which contract to run, sequencing each contract in order of expiry. To do this I organised my data in watchlist folders for each year and month and placed symbols in their appropriate folders (a painful task)


Folders are


then in each folder I have for example:

CCY-2007.03 <= AUD032007, CAD032007, EUR032007, CHF032007
CCY-2007.06 <= AUD062007, CAD062007, EUR062007, CHF062007

so when RE is started by the REController the folder name is passed in the W: param.

If I only want to back test say EUR, I pass another param to RE to ignore bars from all symbols except the one specified (because RE will select all symbols in a watchlist folder)

I have to keep a list of "tradable contracts" to be able to work out the symbol of the next and previous tradable contracts. e.g. for a given commodity, there might be contracts listed for every month but I only want to trade the liquid ones.

   Trading Months for Gold = {2,4,6,8,10,12};
   Trading Months for Silver = {1,3,5,7,9,12};

The REController has to know the tradable months too.

In live trading, when one contract is nearing expiry I have to run the next contract in parallel and the strategy then only trades in the one allowed (as defined by the contract tail days)

To aggregate my backtest results, (e.g. 10 years x 4 quaterlies = 40 contracts) I write to disk all positions and import them into another home-grown trade analysis tool (RE can't aggregate the BT results as far as I am aware)

All of this works (but has been a lot of work to get right) because I don't use and RE indicators.

I have no idea how you would say take 10 days of bars from the previous contract and use that in an indicator of the current contract....then, on every new bar in the current contract remove one bar of data from the indicator that came from the previous contract.

Hope this helps

Posted Tuesday June 19 2012
I think smersh's system could be simplified somewhat by including all of the contracts in a single simulation, and moving the "RightEdge Controller" logic into the system itself. Then you wouldn't have to worry about stitching together multiple simulation results. I show a very simple example of code to do something like this here.

If you need to set up a bunch of different futures contracts, it may be cumbersome to do it manually. Here is a post with code to programmatically edit the watch list.

Posted Wednesday June 20 2012
Daniel, granted it looks like this method of combining symbols should work and I should be able to hand my internal data between contracts as I currently do.

However I don't see a way of handing-over built-in indicators from one contract to another without re implementing them somehow to be able to use bars from two contracts...

As you have indicated, one hopes that the bars preceding the roll date/time have enough liquidity to be meaningful and the problem goes away


Posted Wednesday June 20 2012
Hi Smersh,

You're right, there's no simple way to move an indicator from one contract to another. You could keep the same UserSeries calculations you have, but instead of saving the data to a file and reading it again when you roll to the next contract, you could just copy the information from one symbol to another in code.

Since you have a working system you may want to just leave it as it is. Smile

Posted Wednesday June 20 2012
dplaisted (6/19/2012)
I think smersh's system could be simplified somewhat by including all of the contracts in a single simulation, and moving the "RightEdge Controller" logic into the system itself.


I have done this before on a different platform and implemented it in the system logic as you describe. That platform was very slow which is one of the reasons I no longer use it. I think I'll create some new types for handling futures contracts and indicators starting with the examples you so kindly provided. That should give me a starting point for finding and dealing with the issues as they arise and which I may well raise further quesions about here.



Similar Topics

Reading This Topic

2005-2017 © RightEdge Systems