Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Back testing with asynchronous order placement

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

    Back testing with asynchronous order placement

    We already have a decision making algorithms we built in-house which can be accessed via our API over network. A persistent bi-directional connection is made with the server and logged in. Then there are messages sent and received over the connection.

    - Client sends market data to the server (tick update, onBarClose OHLC data, etc)
    - Server sends order placement message to client
    - Client sends order filled event with filled order details
    - Server monitors the order and triggers order management events there after

    As you can see it is highly event driven system and everything is asynchronous. I am wondering if this would work well with Ninja Trader's back test analytical tools? Does everything have to be synchronous for your back tests to work properly?

    #2
    Hello jiminssy,

    Thank you for your post.

    Backtesting is performed in the Strategy Analyzer in NinjaTrader which uses internal logic for simulation of fills. There is no means to send out and wait for events before processing the next step in the backtest.

    Comment


      #3
      Why can't I send out a blocking call and wait for it in C#? I can't simply use standard blocking rest call for example? I assumed this is something I could do and since this would be a synchronous operation, this would be no different than running your logic internally. I really don't see the difference between synchronous blocking calls and running your internal logics. There shouldn't be any difference and this case should work fine in your strategy analyzer. (again, assuming I can do the standard rest call)

      My question was more about asynchronous calls where the order is placed in a different thread for example. How would this behave in your strategy analyzer? In fact, how would this behave in real production trading?

      Comment


        #4
        Hello jiminssy,

        Thank you for your response.

        You would need a NinjaScript strategy to run in the Strategy Analyzer. So you can in fact build a NinjaScript strategy to call out to and wait for events from your external system. In general this is performed through a custom library.

        In realtime trading you could use the ATI interface (linked below) to submit orders and receive details on those orders, but this will not work for backtesting.

        I recommend reviewing the Help Guide documentation as linked above. Please let us know if you have any questions.

        Comment


          #5
          Sorry. ATI interface is not what I am looking for. ATI interface seems to be like a very primitive signalling from outside to signal NinjaTrader to place orders and that's it.

          Like I mentioned before, we have our back-end developed with our own API implementations. In more detail, we call our APIs via JSON over WebSocket. We are looking to do this using some C# library right in NinjaScript. An example library would be something like this,



          If you look at the example on that page, whenever our backend signals our NinjaScript to place orders, onMessage lambda function would be called when the message arrives. This would be running in a different thread. My question is if I place orders in this thread asynchronously like that, is it safe to do so in production? How would this affect the back-testing?

          Comment


            #6
            Hello jiminssy,

            No options such as what you detail are available in NinjaScript or the ATI. We will check with development and we will follow up with you when we have more details.

            Comment


              #7
              Thank you. Please let me know the feed back from your development team. This will determine how much changes we have to do on our side and whether to go ahead with choosing NinjaTrader as our trading platform.

              Comment


                #8
                Hello jiminssy,

                Thank you for your patience.

                You can do what you are looking for in a NinjaScript strategy. Running in backtest or realtime you will be able to call out to your functions and wait on the callback. Development did provide some insight in that you are looking at a synchronous object running when the NinjaScript object is running. Therefore you would wait with a sync/lock until the process returns with the callback. This would lock whatever instrument thread the strategy is running on and could cause unexpected behavior.

                Comment


                  #9
                  Ok that's the synchronous approach I mentioned earlier which I see no difference between doing that and running my internal NinjaScript code. I knew all along this is something I "can" do.

                  My question wasn't about what I knew I could do. My question was about doing it using Asynchronously (not Synchronously). Since our API is already event driven and relies on asynchronous calls. If I can't do that with NinjaTrader, we would have to develop synchronous APIs on our end and do it that way. So my question again is, would it be problematic if I place orders asynchronously in realtime trading? I would think for backtesting it would create problems for sure.
                  Last edited by jiminssy; 06-27-2016, 02:32 PM.

                  Comment


                    #10
                    Good Afternoon,

                    2 different things here:

                    1) Submitting order to a realtime account or simulation account live.
                    2) Running a backtest

                    Is your question about 1 or 2?

                    Since if 1 then without getting into the details, no problem. Async or synchronous its up to you in the c# code you write and should be no NT blocker and don't forsee problems.

                    If your doing 2 then you would need to have sync calls. Since there is no concept in NT like hold up a back test for an async call to complete and then continue processing a backtest. In fact I imaging such a API requests during backtest would have terrible backtest performance so we typically don't see questions related to doing that. Also in optimizations we actually fire up several backtests in different threads on different cores so there is that to contend with as well. Not sure I would work with a web resource during backtesting and never had anyone give that a go so I don't have any advise as to if you will run into problems there or not.

                    Comment


                      #11
                      Ok, thank you. That clarified everything.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Pattontje, Yesterday, 02:10 PM
                      2 responses
                      14 views
                      0 likes
                      Last Post Pattontje  
                      Started by flybuzz, 04-21-2024, 04:07 PM
                      17 responses
                      229 views
                      0 likes
                      Last Post TradingLoss  
                      Started by agclub, 04-21-2024, 08:57 PM
                      3 responses
                      17 views
                      0 likes
                      Last Post TradingLoss  
                      Started by TradingLoss, 04-21-2024, 04:32 PM
                      4 responses
                      43 views
                      2 likes
                      Last Post TradingLoss  
                      Started by cre8able, 04-17-2024, 04:16 PM
                      6 responses
                      56 views
                      0 likes
                      Last Post cre8able  
                      Working...
                      X