Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fullfilment of backtest strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Fullfilment of backtest strategy

    I'm running a backtest on a strategy with multiple instruments. Bar period on all instruments is 1 week. Two problems, first is that when I place a market order in the OnBarUpdate() method, I expect the order to be filled immediately at the close price. The correct date appears in the Order window, but the Execution/fill does not occur until two bars later. That's an order that gets filled two weeks later with two weeks worth of price movement after the signal. How can I make this execute immediately for the sake of the simulation?

    Second, I'm trying to run the simulation back to 2001. However, not all the instruments were around in 2001, some were created more recently (say, 2006). However, my strategy can cope with that - I still want the bars for the instruments before 2006. However, the OnBarUpdate() does not get called until 2006 bars, even though I set the 'minimumbarrequirement' to 0.

    Finally, how to get a report of CAGR on the strategy, and is there an equity graph showing the cumulative value of cash and positions marked to market? The charts included are a bit blunt.

    #2
    Originally posted by aomega View Post
    I'm running a backtest on a strategy with multiple instruments. Bar period on all instruments is 1 week. Two problems, first is that when I place a market order in the OnBarUpdate() method, I expect the order to be filled immediately at the close price. The correct date appears in the Order window, but the Execution/fill does not occur until two bars later.
    This is a limitation of the backtesting feature in NT (not uncommon, but still annoying for people running on longer time frames where there a few ticks of occasional drift are not that critical). You can't fill a backtested order on a signal from a bar until the bar closes, and by that time, the market has moved on to the next bar. Last week, I requested a way to simulate market on close orders with daily historical data, so you could place an order on the bar closing and have it filled at the close on that bar, not the next bar. Purists might not like this, but it is much more efficient to test and actually more accurate, since entering on the next bar completely ignores the early/after hours market movements between the day's closing bar and the next official opening bar. I don't know why it took two bars for your orders.

    Some workarounds are to work with day/minute bars rather than week bars, code your strategy to support multiple bar timeframes, or (for daily bars) manually change (export, edit, import) your historical data so the previous day's close gets written to the next day's open price, making the next day "start at the market close" thus include the after hours and pre-market moves in its open price. None of these workarounds are all that nice.

    Originally posted by aomega View Post
    I still want the bars for the instruments before 2006. However, the OnBarUpdate() does not get called until 2006 bars, even though I set the 'minimumbarrequirement' to 0.
    I've not run into this, so I can't comment on this apparent limitation.

    Originally posted by aomega View Post
    Finally, how to get a report of CAGR on the strategy, and is there an equity graph showing the cumulative value of cash and positions marked to market? The charts included are a bit blunt.
    A CAGR calculation would be a nice addition. Sadly, there isn't a built-in equity curve for "unrealized" cumulated profit (I also asked for this feature a few weeks ago). NT does not really have built-in support for cash management with interest, margin, comparison to a buy and hold strategy, or any type of non-trivial position sizing (such as risk/buy x% of current account equity, Kelly, etc.), etc. For possibly better account/portfolio management features, I'd suggest waiting a few months and try a NT7 beta or try out some other similar applications.

    Comment


      #3
      Hello,

      I think Anagoge answered all but this question:

      Originally Posted by aomega
      I still want the bars for the instruments before 2006. However, the OnBarUpdate() does not get called until 2006 bars, even though I set the 'minimumbarrequirement' to 0.


      In the Strategy Analyzer please go to the Chart tab and select the home key to move all the way to the left. What is the time stamp of the first bar? This is the first bar your data supports.
      DenNinjaTrader Customer Service

      Comment


        #4
        Thank you to both of you. Actually, if my strategy entered on the open of the next bar then that would be fine. It does, however, completely skip a bar and enter on the open of the following week.

        Maybe it is caused by entering the order on a different instument's OnBarUpdate()?

        Anyway, unless I can solve this problem my evaluation of NT is pretty much torpedoed. I guess I can track P/L myself in print it in the output window.

        Originally posted by NinjaTrader_Ben View Post
        Hello,

        In the Strategy Analyzer please go to the Chart tab and select the home key to move all the way to the left. What is the time stamp of the first bar? This is the first bar your data supports.
        The chart allows me to go back to the strategy start time, e.g. 2001. However, the OnBarUpdate() does not get called until 2006 on any bar series. Some other instruments in the strategy (added with Add() in Initialize) do not start until 2006.

        Comment


          #5
          Hello,

          Please use TraceOrders to sort out which bar the signal came on. The order should be placed on the bar after the signal. This link shows how to use TraceOrders:




          Regarding the strategy starting in 2006: all instruments are required before the strategy will start calculating. Open a chart for each instrument you are using and determine how far back each instruments hist. data goes back. The strategy will only start when all bar series have data.
          DenNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Ben View Post
            Hello,

            Please use TraceOrders to sort out which bar the signal came on. The order should be placed on the bar after the signal. This link shows how to use TraceOrders:

            Thank you. I tried that and the trace shows the order being placed on the correct bar (say 5th December, as printed with Print(Time[0])). This is shown correctly in the order tab too. However, the execution and trade tabs show the order as having been executed on bar of the 19th December, two bars later, using the open price of that bar (which will correspond to the open price on the 15th December, or 10 days after I placed the market order!).

            Originally posted by NinjaTrader_Ben View Post
            Regarding the strategy starting in 2006: all instruments are required before the strategy will start calculating. Open a chart for each instrument you are using and determine how far back each instruments hist. data goes back. The strategy will only start when all bar series have data.
            Yes, this is what I surmised. It means I cannot backtast my strategy as far as I would like.

            Comment


              #7
              aomega,

              You cannot follow your orders from Print(Time[0]). You need to follow it from the actual TraceOrders outputs. Please provide the exact lines printed out and a screenshot of the chart.

              In terms of data, your code uses all bar series so therefore you need data for them all. There is no way around this.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                aomega,

                You cannot follow your orders from Print(Time[0]). You need to follow it from the actual TraceOrders outputs. Please provide the exact lines printed out and a screenshot of the chart.

                In terms of data, your code uses all bar series so therefore you need data for them all. There is no way around this.
                Here is a screenshot. Actually, two orders are placed on the 25th May. One gets filled on the 1st June, the second on June 8th. I tried this with multiple combinations of 'EntriesPerDirection' and 'OrderHandling'. It is always the same.

                I checked that both series are complete - all bars are there.
                Attached Files

                Comment


                  #9
                  Thanks aomega, the first one executed a weekly bar later seems good, not sure about the other one - please forward us your log and trace files to support at ninjatrader dot com referencing this thread.

                  If you want to add a finer, daily stream to your backtesting, please check this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=6652
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,769 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  943 views
                  0 likes
                  Last Post spwizard  
                  Started by Max238, Today, 01:28 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by rocketman7, Today, 01:00 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post rocketman7  
                  Working...
                  X