Navigation: <Root level>

Using an Imported Trade List

 

 

 

 

Overview

RealTest makes it easy to define a strategy based on a list of specific trades.

Running such a strategy is like playing back those trades and using them to generate results statistics.

Reasons to do this might include:

Analyzing the results from a period of live trading (whether systematic or discretionary)

Seeing if you could have done better using different exit rules, position sizing, entry skip criteria, etc.

Comparing actual vs. backtest results for a strategy or set of strategies

Playing back live trades to correctly establish current positions when generating Tomorrow's Orders.

To play back an imported trade list, create a Strategy that includes a TradeList statement.

 

Trade List Types

RealTest supports two kinds of trade lists: transactions and round-trip trades.

Transaction lists are things like IB Flex Query output, where each row only specifies a single transaction (e.g. BUY 100 MSFT).

RealTest automatically sorts the transaction list by symbol then date and time, and converts it to a round-trip trade list for use in a backtest.

Round-trip trade lists include one row per round-trip trade, with both the entry and exit details included.

 

Trade List Format

For either type, the trade list must be a plain text file in standard US CSV format.

The field delimiters must be commas and the decimal points must be periods.

The CSV file must begin with a header row containing its column names.

If the column names are not the standard names as shown in the example below then you must provide a TLFields definition to tell RealTest what field is in each column.

The DateIn and DateOut columns can use any supported date format.

If your program options date format setting conflicts with the trade list's date format (i.e. m/d/y vs. d/m/y), use TLDateFormat to override the setting while parsing this trade list.

 

Other Trade List Settings

RealTest expects quantities and prices in a trade list to be actual "as-traded" values, i.e., not split-adjusted. If your trade list has been adjusted, use TLAdjusted to let RealTest know this.

If your trade list dates and times are known to be in the wrong time zone (e.g. your local zone rather than the exchange zone), use TLTimeShift to correct this.

If you want trades labeled for a particular strategy to play back in a strategy with a different name, use TLStratName to specify this.

 

Example Script

As an example, see actual_trades.csv in the Examples folder, the first few rows of which look like this in a text editor:

or like this in Excel:

A trade list file can include all of the trades or transactions from any number of strategies.

The example script actual_trades.rts shows how to use this file.

This example includes two strategies, called "Longs" and "Shorts" (the above screen shots happen to only include long trades).

To "run" this trade list as a backtest that produces separate stats for each side plus combined stats, the example defines two strategies:

The Template mechanism was used to avoid having to repeat the file path and field map.

This example script contains sample templates for several known trade and transaction list formats, which can be copied in to your own scripts as needed:

 

Overlaying Strategy Rules

In addition to simply playing back a list of trades to generate stats and graphs or look at trade charts, you can also experiment with adding strategy elements to override the entry or exit rules or position sizes of the trades.

As a simple example, try adding EntrySkip: C > 50 to the strategies in this example script, then re-running it. You'll see that this reduces the trade count by about half, and lowers the expectancy somewhat. (You must use EntrySkip rather than EntrySetup to override a trade list entry. EntrySetup is ignored in overlay mode.)

To override the position sizes in an imported trade list, add both a Side specification and a Quantity formula to each strategy.

To test different exit rules, simply add them to the strategy.

Note that adding any exit formula (ExitRule, ExitLimit or ExitStop) to a TradeList strategy disables all exits from the trade list.

 

Switching from Trades Playback to Strategy Rules

By default any strategy containing both a TradeList statement and some Strategy formulas is played back as described above by overlaying any specified strategy elements on the imported trades.

It is also possible to run a "hybrid" playback where the trade list runs verbatim up to a particular date and then the strategy rules take over entirely after that date. To activate this mode, add TLEndDate to your Strategy definition.

 

Using Hybrid TradeList+Formula Strategies for Tomorrow's Orders

The behavior described in the two prior sections applies when the run mode is Test.

When a strategy with a trade list is run in Orders Mode, it is assumed that the purpose of the trade list is to establish current positions and account value from actual live trades playback prior to generating tomorrow's orders.

Therefore playback is always done in hybrid mode when generating orders.

All strategy element definitions (including TLEndDate if specified) are ignored throughout the entire playback (as when TLEndDate: Latest is specified in Test mode). The strategy definition is only applied at the final order generation step.

To use this feature in your daily live trading, you would need to do the following:

1. Obtain an accurate record of your live trades, in CSV format, since the desired start date. Ideally, your automation software will generate this list automatically. Alternatively, it could be produced by IB using either Flex Query (via the account management website) or by enabling automatic generation of trade logs in TWS and then concatenating them.

2. Add TradeList and (if needed) TLFields statements to your existing strategy definition, referencing the CSV file thus obtained.

3. Import the latest data and run the test in this hybrid mode to produce tomorrow's orders.

Note that when OrderClerk is used to place and manage your orders, all of the above is handled automatically. OrderClerk maintains an accurate round-trip trade list from your live execution reports.

By specifying OrdersMode: OrderClerk and OrderClerkFolder: <path to folder where OrderClerk runs this strategy>, you don't have to add TradeList or TLFields to the strategy and don't need to worry about how to maintain a live trade list.

 

 

 

 

Copyright © 2020-2024 Systematic Solutions, LLC