Navigation: <Root level>

Backtest Engine Details

 

 

 

 

The RealTest Backtest Engine is written to support multi-strategy portfolio-level backtesting as effectively and efficiently as possible.

In most other software, portfolio-based backtesting is implemented by first generating all the entry and exit signals for each symbol for the entire date range, and then running a second pass that models the portfolio for each date using the generated signals.

In contrast to this, RealTest loops through the data by date first, then loops through each strategy, then finally each symbol for that strategy.

This turns out to be no less efficient and much more effective, as it gives strategies full access to their own stats during a backtest.

 

Here is a simplified overview of what goes on "under the hood" when you run a test:

1.Apply the Settings (if present and applicable) to the Settings Panel (where they will persist until next changed)

2.Load the specified Data File if not already in memory

3.Get the current Parameter values (defaults for a single test or next optimization values for multiple tests)

4.Adjust the test date range to match the data date range and/or next optimization interval

5.Recalculate Data Section items (arrays) as needed

6.Loop through the dates in the date range for this test and do the following:

a.initialize daily stats

b.do at-open exits then entries for each strategy (exits first to free capital for positions being entered)

c.do intraday entries then exits for each strategy (entries first to avoid assuming capital can be freed when intraday fill sequence is unknown)

d.do at-close exits then entries for each strategy (exits first to free capital for positions being entered)

e.update daily stats for each strategy

f.recalculate allocation for each strategy

 

The exits in steps b-d above are processed as follows:

1.Loop through all strategy positions and exit each if any of the following are true:

a.ExitRule evaluates to TRUE and ExitTime matches time of day (exit at open or close)

b.ExitLimit or ExitStop price was touched without ambiguity (exit at that price)

c.ExitLimit and/or ExitStop price were touched with ambiguity and Ambiguity setting permits exit anyway

d.this is the last bar of data or last date of the test (exit at close)

 

In legacy mode, the entries in steps b-d above are processed as follows:

For each Strategy in script order:

1.Loop through all stocks and evaluate EntrySetup, making a list of the stocks for which it returned TRUE (setups)

2.Sort this list of setups by SetupScore and truncate the list at MaxSetups (if specified)

3.Sort the setup list by EntryScore and loop through the sorted list, adding new positions when ALL of the following are true:

a.date matches strategy BarSize and time of day matches the strategy EntryTime

b.EntryLimit and/or EntryStop price have been touched or were not specified

c.there's not already a position in this stock for this strategy (unless MaxSameSym is greater than one)

d.MaxPositions or MaxInvested or MaxExposure or MaxEntries has not been reached

e.EntrySkip does not evaluate to TRUE

 

Key points about legacy mode:

all constraints other than MaxSetups are applied at entry time, not at setup selection time

constraints are applied based filled orders rather than setups

this model assumes that execution software would manage the constraints in live trading

 

In top-down mode, the entries in steps b-d above are processed as follows:

1.For each strategy:

a.Loop through all stocks and evaluate EntrySetup, making a list of stocks for which it returned TRUE (setups)

b.Sort this list of entry setups by SetupScore and truncate the list at MaxSetups (if specified)

2.For each setup rank number (highest score gets first rank):

a.For each strategy, evaluate the StrategyScore formula (if not provided then rank by strategy number)

b.For each strategy in StrategyScore sequence:

i.select the setup with the outer loop's rank number

ii.see if that setup would exceed any applicable Max... constraint for the strategy, any StatsGroups it belongs to, or Combined

iii.if no constraints are exceeded then update the strategy, group, and combined constraint values to account for this setup, else skip the setup

3.For each strategy (now that we have the complete setup list for all strategies with constraints accounted for):

a.Sort setups by EntryScore if provided (not necessary in this mode except in rare cases)

b.Evaluate  QtyFinal for each setup to optionally adjust the order quantity now that total setup counts are known

c.Evaluate EntrySkip if provided and skip the entry if true (ditto)

d.Enter the position if EntryLimit and/or EntryStop have been touched or were not specified

 

Key points about top-down mode:

all constraints are applied to the setup list prior to processing any entries

setups for strategies that enter with limit or stop orders count towards all constraints whether or not they are filled

to control the number of orders placed per day without truncating the setup list, use MaxOrders

this model assumes that all orders are placed in advance of the market open each day with no realtime order management (e.g. live cancellation when a capacity is reached)

 

 

 

 

Copyright © 2020-2023 Systematic Solutions, LLC