Signals from perpetual contracts translated to real trading

Discussions about the testing and simulation of mechanical trading systems using historical data and other methods. Trading Blox Customers should post Trading Blox specific questions in the Customer Support forum.
Post Reply
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Signals from perpetual contracts translated to real trading

Post by CyTrend »

Hello,
I am hoping there is an easy solution to this. I want to use perpetual contacts as defined by CSI to get my entry and exit signals. However I am pondering how then to backtest these signals to get the real trading PnL. So can I get the signal from the Perpetual CL future but then execute my order and basically backtest my PnL on most active contract rolling in to the next if need be, till my perpetual CL contract gives me an exit signal?

Off the top of my head I was thinking of basically having both the most active and the perpetual contracts for the same instrument in my dictionary and somehow inferring a signal from the perpetual in to an action in the most active contract. Is this possible?

Any ideas?

Thanks,
Cy
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

Step 1: System A runs on Portfolio A. Writes buy/sell orders to a file.
Step 2: System B runs on Portfolio B. Reads this file of orders, applies to Portfolio B.

Portfolio A = your Perpetual contracts
Portfolio B = your non-Perpetual contracts

This is easiest if all orders are "Market On Open" and/or "Market On Close" types of orders.

If some orders are Price orders (stop orders, limit orders, stop-limit orders), then you will need to invent a way of translating the Order Price from your Perpetual contracts to your non-Perpetual contracts. Naively, I would imagine that "NNN ticks above/below today's Close" would give acceptable results, but I might be mistaken.
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

sluggo thanks for the above, i have to follow-up questions that might help clear things up:
1) is it possible to elaborate on how u write orders to a file and then use that file to read orders and apply to a second portfolio?Am i suppose to run this in trading blox(using the write and read file commands) or do it manually in another program like Excel? is there an example in any previous threads?

2) I have also been thinking of another way. Let's say i want to test my system on a portfolio of 30 futures. I create instead a portfolio of 60 futures so that for each one i have two instruments i.e OilPerpetual and OilNthNearestFuture. So i run my signals on the perpetual contracts but i define my orders such that they get executed on the NthNearestContract.. What do u think of this method.I guess the question i am asking is can i use the signal generated by one instrument i.e OilPerpetual to only generate an order for a different instrument OilNthNearestFUture.
LeviF
Roundtable Knight
Roundtable Knight
Posts: 1436
Joined: Mon Dec 22, 2003 12:24 pm
Location: Des Moines, IA
Contact:

Post by LeviF »

Why do you want to do this?
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

Hi LeviF, as we said in the initial post backtesting using the perpetual contract does not provide u with the real pnl as that is not what u trade. So u need to have a way to seperate the contract u use to provide u with the entry/exit signal from the contract u actually execute ur real orders on.
LeviF
Roundtable Knight
Roundtable Knight
Posts: 1436
Joined: Mon Dec 22, 2003 12:24 pm
Location: Des Moines, IA
Contact:

Post by LeviF »

Yes I understand this. I guess my question should have been why do you want to use the perpetual contract vs back adjusted?
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

The vast majority of people who use programs like Trading Blox, Wealth-Lab, Tradestation, AmiBroker, Mechanica, TradersStudio, to run mechanical trading systems on futures contracts, do so with backadjusted continuous contracts like the one shown below. The "Sample Data" provided with Trading Blox, for example, uses backadjusted continuous contracts from CSI.

However, if you wish to blaze a new trail using another approach, go right ahead. Keep in mind that, like all pioneers, you will be more or less alone. You'll have to navigate the terrain without a map, relying instead upon your own resourcefulness and problem solving abilities.

The only way to find out whether or not there are prior messages on this Roundtable which discuss a certain idea, is for somebody to do a few Searches and comb through the results (if any). But who would be the best candidate to perform these searches? I guess the person with the greatest motivation, the one who fervently desires the answers most, might be the logical choice.
Attachments
backadjusted_5y_notes.png
backadjusted_5y_notes.png (37.78 KiB) Viewed 8560 times
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

Tx Sluggo and LeviF,

I guess it is a personal choice to use perpetual futures because they are a more static view of the market and I believe form a more powerful signal for trades. You are getting rid of the cost of carry storage etc.

However I guess our question still is more technical.
1. How do you create the order file and how do you execute it to a different set of data? This is what you suggested above Sluggo. Can this be done within TradingBLox?
2. Can you use signals from one future to imply a price order on another set of futures? In our case for example can we imply a trade from the signal on the perpetual oil contacts to the Nth Nearest contract.

Tx,
Cy
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

1. I have never done this, either in Trading Blox or elsewhere. I suspect it is possible, I think it seems reasonable, but you are the one who has to create an implementation. If you think it can't be done, or if you think this method requires far too much effort, then you will need to invent another approach.

2. I have never done this. I suppose the question is, can you figure out a way to do it? Maybe expressing Order Price as a number-of-ticks-from-the-close is a good starting point, maybe not; it's your decision.

Like all pioneers, you will be more or less alone. You'll have to navigate the terrain without a map, relying instead upon your own resourcefulness and problem solving abilities.
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

Tx Sluggo I will power through!!!
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

Trading Blox has a process that gives it the ability to align external data from another file to the dates of the primary instrument file. For example, if you use Sluggo's suggestion to generate Back-Adjusted contracts, and you also create Perpetual contracts for the same symbols, you will have file pairs that you should be able to blend into an IPV structure using a process in the Before Simulation Script section so the data from both sources are aligned by date.

This means that the primary data will be back adjusted data, but the signal data can be Perpetual data. With that in mind, you would then create your signal process to access the perpetual data variables so you could generate your signals from the perpetual data. With the perpetual data generating the signals, and the Back-Adjusted data handling the trades, the accounting problem will not be different than other system simulations, with the exception that the order signals are not derived from the main trading data stream and the perpetual prices are not appearing in the order signal report.
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

Roger thanks this is exactly what i need to do! Will try to figure out how to do it. Thanks for putting some thought in to how it can be done. I will try and figure out the mechanics of it. Thanks again
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

Begin by loading just the Perpetual file records along side the Back-Adjusted data. To do that record alignment spend time understanding how to use "LoadIPVFromFile". I found the Trading Blox process a simple and an elegant way for dealing with this kind of data-joining need.

Once the data is loaded, understand how the scope setting of the IPV variables can make a difference in how it is handled during stepping. Then begin the process of building your own indicator code, and be sure to understand how to handle indicator priming chores. At this point you should be out of the woods and coding like you would for most systems.
CyTrend
Roundtable Fellow
Roundtable Fellow
Posts: 57
Joined: Mon Oct 25, 2010 5:28 pm

Post by CyTrend »

Roger,
I think i understood how to use "loadFromIPVFile". Now let me see if i understand the method u are proposing correctly. First i created one BPV called portfolioInstrument and i used :
portfolioInstrument.LoadIPVFromFile( externalFileNamePerpetualData, "perpetualOpen", "perpetualHigh","perpetualLow","perpetualClose" ) where i defined the above as IPV variables simulation scope.
Are u saying that in the same ForLoop(i.e for the same instrument ) i need to load the second file which will hold my Back Adjusted Data and use some kind of command like the following:
portfolioInstrument.LoadIPVFromFile( externalFileNameBackAdjustedData, "BackAdjustedOpen", ... ) ? Does that mean that you need to make sure the dates in each of the files are aligned in advance or can TradingBlox deal with date discrepancies. Am i on the right track of what you were saying or have i gone off at a tangent?
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

When you load a file onto a carrier file, or a portfolio instrument file using LoadSymbol, there must be a date in the carrier file that can accept a date record from the parasitic, or attaching file, to keep TB from complaining.

This also includes dates that are earlier than the start date with years of priming action period records loaded. In simple terms, if there is a date in the file that the LoadIPVFromFile function is loading that isn't available in the instrument file you bring into context using LoadSymbol, it is going to cause a crash.

To prevent that from happening, check the early file date you are going to load using LoadIPVFromFile against the Instrument.StartDate before you execute the LoadIPVFromFile function if you want to keep TB calm.

If there are missing record dates in the parasitic file, but not in the carrier file, and the missing dates are at the start or late near the end of the carrier file, TB will load zero values in the IPV series you create where those dates didn't have any data.

I never checked what happens if the missing date is some place in the middle, but my guess is there would be a zero entered in the IPV series at the missing date location

If your experience is different, consider posting it so we both know what you discover.
Post Reply