Navigation: Realtest Script Language > Formula Syntax >

Special Syntax for Individual Futures Contract Testing

 

 

 

 

This category of external item reference is somewhat more specialized.

If you import all of the individual historical contracts for a futures market, you can, of course, refer to any specific contract by symbol, but how can you model something like a realistic roll-over strategy?

To solve this problem, RealTest does some extra processing on futures symbols during import.

To take advantage of this feature your futures symbols, if your data is not from Norgate, must have the same format used by Norgate.

Specifically, the format must be: XX-YYYYM, e.g. ES-2016Z,  GC-2021K, etc.

By using the logic inherent in this naming convention, RealTest is able to construct a "symbol chain" during import, which it can later use to permit REALTIVE external symbol references.

The syntax for a relative reference is Extern(&n, expression), where "n" is a numeric offset in either direction. Positive directions refer to newer contracts (ones that expire farther in the future) and negative directions to older ones (ones that expire sooner).

For example, if your current symbol is ES-2016Z, then Extern(&1, C) would give you today’s close for ES-2017H, and Extern(&-1,C) would give today’s close for ES-2016U.

The simplest application of this syntax is to accurately model "buy and hold" of a futures market using any desired rollover rule. For example, this strategy will hold 1 ES and roll at the open after the first day where the new contract has more volume than the old one:

You can also use this technique to model spread trading, calculate contango/backwardation indicators, or who knows what else.

The script es_compare.rts in the example scripts directory includes the above strategy and runs a comparison study of modeling "buy and hold" ES since its inception using (1) individual contracts with accurate rollover transaction modeling, (2) a single continuous price series without back-adjustment, and (3) a single continuous back-adjusted price series.

When this kind of futures symbol chain exists, RealTest can also calcluate market-specific breadth values such as ranking by volume the active contracts within each market on a given date. See #ByMkt and the futures_calendar_spread.rts and futures_volume_rank.rts example scripts for details.

Besides relative contract lookup, there is one additional variation of this syntax.

If your data file includes the Norgate continuous contract series as well as individual contract symbols, you can reference the corresponding continuous series for the current individual symbol by using either Extern(&cc, formula) if you want the non-back-adjusted one, or Extern(&ccb, formula) if you want the back-adjusted one.

The futures_volume_rank.rts example script shows how this technique can be used to implement a trend-following strategy that trades individual contracts while using a continuous series to generate its signals.

Going the other way, if the current symbol is a Norgate continuous contract symbol, the corresponding individual contract with the nearest upcoming expiration date can be referenced using Extern(&0, formula). The second nearest is Extern(&1, formula), and so on.

Knowing this, it becomes simple to calculate spreads:

The futures_calendar_spread.rts example implements this in a slightly more efficient way, but the result is the same.

 

 

 

 

Copyright © 2020-2024 Systematic Solutions, LLC