Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to alter data series in backtesting/optimization

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

    How to alter data series in backtesting/optimization

    Hello,

    I consider it is interesting to backtest/optimize strategies with -little- random altered historical data series in order to check their robustness against changes.

    The manual procedure would be to import hundreds of altered dataseries in historical data but this is not viable and lacks on randomness.

    I am thinking about using optimize procedure in strategy analyzer, altering a little input OHLC historical values before each iteration starts, so the strategy could execute, make its calculations and the trades using on altered historical data.

    Is it possible to program?

    The only alternative I can guess for now is using this convoluted -but viable- combination of things together:

    -Create custom DataSeries for Open, High, Low and Close, inside a custom indicator which alters historical data and store bar by bar, so I will have alternative OHLC series to make calculations.
    -Create a custom Fill Type which get orders opened using altered series values and not over original historical data.
    -Create a custom Optimizer which manage all the process between iterations, associating random alterations to each iteration.

    Is it available a simpler and viable approach? I have studied carefully custom Bar Types but I don't understand them as a solution as the calculations and trades still will be referred to original historical data.

    Regards

    #2
    Hello joseluisgilgil,

    Thank you for the post.

    In regard to what you want to do, the options you have laid out would potentially work for various purposes but I can see some problems you may run into.

    You have the option to import data that is slightly different as different symbols and could run various tests over those instruments. This would only be as random as you make it and would likely be tedious to do. You also would need to run a basket test over many instruments instead of using one instrument. The alternative is to use one instrument, import data and then test and repeat.

    You could also make an indicator which is used for the price data rather than the price series, this gives you finer control over the values or randomness needed but this ultimately does not play into fills directly, this would be more of how your overall logic works. The fill engine will still use the bar data to fill the orders, so the fills would not likely line up with what your indicator produces.

    The fill type is not a type in NT8 NinjaScript so this could either be the standard or high historical fill logic used in a backtest.

    A BarsType could be used and would contribute to fills as that is the actual bar price data being used with the fill engine, but this would likely be harder to make as this is strictly building bars based on the existing data. You also cannot access indicator values here, so this would need to be some kind of math that makes the bars as you wish here and adds randomness. If you are able to create a BarsType that produces the bars needed, that would likely be the best solution as this would allow for the fill engine to use that data as well. I don't believe this would work in an optimization specifically as you are not reloading the data over and over, but individual backtests should be able to randomize the data when reloading the bar data.

    You could create an optimizer as well if you see a need for that, this would really be up to your design. In any case, what you are wanting to do is not a default option in the platform so you would likely need to create this in the way you best feel you are able to.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your quick response.

      So I assume that there is no way to chage historical data series by code just in the loading moment in the backtest, isn't it?

      I have made a test environment in NT7 and yes, it is possible to transfer info of alternate random series generated in an indicator to the fill type code using an auxiliar class to store the generated random bars of each iteration and associate to it. I also have needed to set up a custom optimizer in order to tell the auxiliar class what iteration it is in.

      Although it works roughly, it is an ugly and cumbersome way, I wonder if in NT8 it could be improved.

      As you mentioned, the Fill type does not exist in NT8? A custom BarsType must be specified to influence in order filling? Do you have some information and development-oriented examples about custom BarsType? I only find this in the documentation and it is not excessively clarifying:



      Comment


        #4
        Hello joseluisgilgil,

        Code:
        So I assume that there is no way to change historical data series by code just in the loading moment in the backtest, isn't it?
        This would be correct, there is nothing like this that I could suggest.


        In regard to the BarsType and fills, you can find more information about how NT8 fill engine works here: https://ninjatrader.com/support/help...ical_fill_.htm
        Likely the Standard fill type would need to be used in this scenario so that the base bars data is used for the fill information. As for educational information, the help guide you linked would be the best resource besides the existing source code for the existing bar types. You can see the code for a majority of the types in the NinjaScript editor and these all display the best practice for creating a type.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X