Precise Backtesting

From MultiCharts
Jump to navigation Jump to search

Understanding Precise Backtesting

Depending on the strategy, Precise Strategy Backtesting can give the user a more realistic emulation during backtesting. To backtest high frequency strategies like statistical arbitrage, the user may need to take into account the historical bid/ask data in addition to the historical trade data.

With Precise Backtesting, the user can load the historical bid data series and the historical ask data series into MultiCharts. MultiCharts will use the ask data series to fill buy market, buy stop and buy limit orders. Similarly, MultiCharts will use the bid data series to fill sell market, sell stop and sell limit orders.

Consider a situation where a market order to buy 1 contract and a market order to sell 1 contract are submitted at the same time at the close of a bar. If the user only uses the trade data series, then there is only one price for the close. The backtest will show that these two orders were filled at the same price, and the profit/loss is zero. In reality, there's a bid/ask spread. If the price quote doesn’t move suddenly, then these two orders will undoubtedly generate an instantaneous loss due to the bid/ask spread. That's why it’s more precise to backtest with a bid data series and an ask data series.

Consider another situation where the trade price doesn't occur on either the bid or the ask. Due to liquidity or other reasons, the historical data series may show that the trade price was either in between or outside the bid/ask. In this situation, the user may want to be conservative and assume fills at the bid/ask instead of at the trade price.

Consider a third situation where there is sufficient liquidity and the trades do occur on the bid/ask. The strategy uses 10 minute bars. The strategy buys 1 contract at 10:00am and exits the position at 11:00am. The PowerLanguage code for such a strategy is as follows:

If Time=1000 Then Buy 1 Contract This Bar on Close; 
If Time=1100 Then Sell 1 Contract This Bar on Close;

If this strategy was backtested on simply a data series of historical trade prices, then the backtest will assume that the trades were filled at the close prices of the bars. However, it's unclear whether the trades would have been filled at the close prices, because the close prices could have been on either the bid or the ask.

If the close price was an ask price and the strategy was buying, then the fill price was realistic. However, if the close price was a bid price and the strategy was buying, then the fill price was unrealistic.

If the close price was a bid price and the strategy was selling, then the fill price was realistic. However, if the close price was an ask price and the strategy was selling, then the fill price was unrealistic.

With Precise Backtesting, users can load two separate data series onto the chart. The first data series is for historical bid prices. The second data series is for historical ask prices. MultiCharts will use these two data series to determine realistic fill prices. The bar's close will have a bid and an ask price associated with it. MultiCharts will use the ask price to fill a buy order and the bid price to fill a sell order.

Using Precise Backtesting

To use Precise Strategy Backtesting:

  1. Make sure the symbol contains historical bid and ask data.
  2. Add the symbol into a chart window.
  3. Designate this chart as the Ask data series:
    1. Open the Format Instrument window.

      To open the Format Instruments window, click the Format Instruments Format Instrument.png icon on the main toolbar;
      if the Format Objects window appears, select the symbol and click the Format button.

      The Format Instruments window can also be opened by one of the following methods:
        - Position the mouse pointer over the symbol's data series; double-click once the Pointer Pointer.png changes into a Hand Hand.png;
        - Position the mouse pointer over the symbol's data series; once the Pointer Pointer.png changes into a Hand Hand.png right-click and then click Format Symbol Name;
        - Right-click on an empty area of the chart and then click Format Instruments; if the Format Objects window appears, select the symbol and click the Format button;
        - Select Format in the main menu and click Instrument; if the Format Objects window appears, select the symbol and click the Format button.

    2. Select the Settings tab.
    3. In the Quote Field drop-down list, select Ask.
    4. Select OK.
  4. Add the same symbol with the same resolution to this chart window. The chart window now has two data series.
  5. Designate this chart (the second chart) as the Bid data series:
    1. Open the Format Instrument window.

      To open the Format Instruments window, click the Format Instruments Format Instrument.png icon on the main toolbar;
      if the Format Objects window appears, select the symbol and click the Format button.

      The Format Instruments window can also be opened by one of the following methods:
        - Position the mouse pointer over the symbol's data series; double-click once the Pointer Pointer.png changes into a Hand Hand.png;
        - Position the mouse pointer over the symbol's data series; once the Pointer Pointer.png changes into a Hand Hand.png right-click and then click Format Symbol Name;
        - Right-click on an empty area of the chart and then click Format Instruments; if the Format Objects window appears, select the symbol and click the Format button;
        - Select Format in the main menu and click Instrument; if the Format Objects window appears, select the symbol and click the Format button.

    2. Select the Settings tab.
    3. In the Resolution field specify the same resolution as for the Ask data series.
    4. In the Quote Field drop-down list, select Bid.
    5. Select OK.
  6. Add a signal to the chart: see "Inserting Studies".
  7. Enable the Extended Backtesting mode:
    1. Open the Strategy Properties window.

      To open the Strategy Properties window:
      1. Open the Format Objects window.

        To open the Format Objects window, right-click on an empty area of the chart and then click Format Signals.

        The Format Objects window can also be opened by one of the following methods:
          - Select Format in the main menu and click Signal.
          - Double-click any one of the signal's labels on the chart.
          - Position the mouse pointer over any one of the signal's labels on the chart; once the Pointer Pointer.png changes into a Hand Hand.png, right-click the label and then click Format Signals.

      2. Select the Signals tab.
      3. Click Properties to open the Strategy Properties window.
    2. Select the Backtesting tab.
    3. Select the Extended. The strategy backtesting engine emulation based on bid & ask series data radio button.
    4. In Use for ask series data, select the ask series data.
    5. In Use for bid series data, select the bid series data.
    6. Click OK.


Advanced Backtesting Settings

  • Realtime-history matching
    This option allows MultiCharts to synchronize the calculation of studies based on several data series. When using several data series calculation on historical data may differ from real-time calculation. Realtime-history matching option makes historical calculation results closer to real-time. More info is here
  • Ignore Tick Cache in Real Time on Additional Data Series
    If this option is enabled, during the calculation of the study on additional data series in real time, only the current state of the bar of the additional data series is taken into account. Tick cache of that bar is ignored.
  • Send intrabar orders immediately
    This option will become available in the next MultiCharts 15 Open Beta version.
    If this option is enabled, orders generated on events specified in the IOG settings will be sent immediately after calculation.
    If disabled, orders will be sent on the next tick after calculation.