Blox for testing entry based on percentage move?

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
Medius
Roundtable Knight
Roundtable Knight
Posts: 107
Joined: Fri May 22, 2009 5:38 am
Location: Berkshire, UK

Blox for testing entry based on percentage move?

Post by Medius »

Is there an entry blox with a pararmeter for % instrument change?

If not can anyone give me some clues on how to program blox to do so?

% change could be from test start date.

TIA
Medius.
rgd
Roundtable Knight
Roundtable Knight
Posts: 396
Joined: Thu Aug 10, 2006 5:21 pm

Post by rgd »

lookback = instrument.currentbar

percent change = (instrument.close/instrument.close[lookback]) - 1
Eventhorizon
Roundtable Knight
Roundtable Knight
Posts: 229
Joined: Thu Jul 08, 2010 2:36 pm
Location: Boulder, CO
Contact:

Post by Eventhorizon »

Remember you would have to use ratio-adjusted contracts or your percentages will be meaningless.
Medius
Roundtable Knight
Roundtable Knight
Posts: 107
Joined: Fri May 22, 2009 5:38 am
Location: Berkshire, UK

Post by Medius »

Thank you rgd, ingenious great start.

Thank you Eventhorizon. I assume you are talking about futures contracts?

I would be grateful if you have time you could give a simple and obvious example. Testing so far has shown some very strange trades which may be my programming or directly related to your thoughtful reminder.
Eventhorizon
Roundtable Knight
Roundtable Knight
Posts: 229
Joined: Thu Jul 08, 2010 2:36 pm
Location: Boulder, CO
Contact:

Post by Eventhorizon »

I am talking about futures contracts.

Simple example, picked at random from the CL (Crude) contract:

Actual closes, with a roll on 2005-01-10 ...

Date: 2005-01-06, 2005-01-07, 2005-01-10, 2005-01-11
Feb 2005 contract: 45.56, 45.43, NA, NA
Mar 2005 contract: NA, 45.67, 45.57, 45.91

=> % changes* -0.2857%, -0.2192%, 0.7433%

* I use Ln(Close today / Close yesterday) i.e. continuous compounding

What did this contract look like when we back-adjusted it in June of this year?

Closes using ratio style contracts:
Date: 2005-01-06, 2005-01-07, 2005-01-10, 2005-01-11
CL20: 154.7798, 154.3382, 154.0002, 155.1492

=> % changes: -0.2857%, -0.2192%, 0.7433%

Which matches what was experienced by traders at the time.

Closes using a Panama (difference) style contract:
Date: 2005-01-06, 2005-01-07, 2005-01-10, 2005-01-11
CL20: 118.8800, 118.7500, 118.6500, 118.9900

=> % changes: -0.1094%, 0.0842%, 0.2861%

Very different from the actual daily percent changes at the time!


Let's delve a little deeper and see how this is a problem that just keeps on giving. What happens when we look at the back-adjusted contract as of today ...

Closes using ratio style contracts:
Date: 2005-01-06, 2005-01-07, 2005-01-10, 2005-01-11
CL20: 156.9943, 156.5463, 156.2035, 157.3690

=> % changes: -0.2858%, -0.2192%, 0.7434%

Which again matches what was experienced by traders at the time. Even though the values are different from when we did the back-test in June, the multiplicative relationships have been preserved.

Closes using a Panama (difference) style contract:
Date: 2005-01-06, 2005-01-07, 2005-01-10, 2005-01-11
CL20: 120.2300, 120.1000, 120.0000, 120.3400

=> % changes: -0.1082%, 0.0833%, 0.2829%

Which still doesn't match what was experienced at the time AND is different from what was detected by your back-test when it was run in June!!!

This means that your back-test run today will give you different trades from what it did when run in June. Combine this with the butterfly effect (even a few pennies different at the beginning of a test can bloom into $m in differences by the end) and you are in back-testing hell.

One final note, I am NOT advocating switching to ratio contracts. I AM saying that you need to decide which contract to use dependent upon the type of calculations you are doing - what relationships do you want to preserve? In some cases (for instance, to calculate the $ variance of your portfolio) you need to use the un-adjusted contracts.

EDIT: typo's
svquant
Roundtable Knight
Roundtable Knight
Posts: 126
Joined: Mon Nov 07, 2005 3:39 am
Location: Silicon Valley, CA
Contact:

Post by svquant »

I had a while back posted a blox in the marketplace that did compute a good estimate of the %-return on a back adjusted contract without the need for ratio adjustment. There are some slight inaccuracies due to data limitations but it may fit your bill. I also recall AFJG doing something with the code to compute an index for each commodity, i.e. create a base price of 100 on the first day of trading.

Thus you can use that series to rank on and create your entry exit signals and still use back adjusted contracts with the correct big point values and $ amounts.
Post Reply