Navigation: <Root level>

Using an Imported Trade List

 

 

 

 

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.

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.

In either case, the trade list file must be in a standard CSV format, where the field delimiters are commas and decimal points are periods.

To use a trade lists of either kind, you must provide a definition of what is in each column.

See TLFields for details on what columns can be used and how to specify their layout. (The header row of the CSV file is ignored and is not required.)

See TLAdjusted and TLTimeShift for other settings related to trade lists.

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:

 

Symbol Changes

If a file named symchanges.csv is found in the RealTest directory, it is loaded and used to map symbols found in trade lists to what they currently are in your data file.

This file has just two columns: old symbol, new symbol as in this example (it doesn't matter what the columns are called, just that they're in this order):

Using this file saves you from having to edit every individual trade list before importing it.

Note that as of RealTest 2.0.24.2, when using Norgate data with delisted symbols such as those shown in the above example, it is no longer necessary to add these to the symchanges.csv file. RealTest now automatically converts a symbol to its delisted name if the delisted symbol is available in the current data file.

Overlaying Trading Rules

In addition to simply "backtesting" a list of trades to generate stats and graphs or look at 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.

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 the exits from the trade list.

 

Using Hybrid TradeList+Formula Strategies for Tomorrow's Orders

As described in the prior section, any of the standard Strategy Elements can be added to a TradeList strategy to override certain details of the trades in the list.

A special exception to the usual way this works occurs when a test is run in Orders Mode. In this case, the presence of TradeList tells RealTest that you want to use this special hybrid mode designed for live trading.

In this special mode, the trade list is played back "as is", ignoring all other strategy elements, up to and including the last date of the test.

At that point, using the current equity value and open positions from the trade list playback, the strategy formulas are evaluated for the upcoming day. This produces an accurate set of orders and quantities for tomorrow based on your actual trades and current positions.

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 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-2022 Systematic Solutions, LLC