• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

additional statistical fields in analyzer output

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

    additional statistical fields in analyzer output

    is there a way to get Min/Max/Avg of daily profit/loss in the strategy analyzer running Optimization ?


    #2
    Hello dadarara,

    The Analysis display in the Strategy Analyzer does have a Daily period. This display shows the net profit of that day.

    Can you clarify what you are looking for? Are you looking for the largest loss single trade of each day or greatest gain?

    Are you trying to find a day with the lowest net profit?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea
      thanks for coming back.
      indeed there is a daily data, but it is relevant to a particular strategy "Scenario" (set of parameters)
      But when I run optimization of the same strategy, I get multiple scenarios.
      I am looking to be able to sort different "scenarios' based on their maximum/minimum/average daily profit/loss. (NOT an individual TRADE based , but DAILY based calculation)

      Comment


        #4
        Hello dadarara,

        Are you wanting to create an OptimizationFitness scripts for Max Daily Loss / Min Daily Loss / Average Daily Loss?

        Below are public links to the help guide on OptimizationFitness.
        https://ninjatrader.com/support/help...on_fitness.htm
        https://ninjatrader.com/support/help...ss_metrics.htm

        The average I could understand for this. Would the Max / Min be looking for the result that has the single largest loss single lowest loss for a single day within the backtest iteration?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea

          looks like the OptimizationFitness script is the way to go.
          Indeed I would like to get the value of Daily P&L for the backtest iteration.
          I agree that the average is the more interesting value, but the Max and Min P&L values are important as well. This can tell me the maximum LOSS I should expect within the day (more or less) . this means that the Max P&L is the highest daily WIN and the Min P&L would be the biggest daily Loss.

          I have in my strategy the calculation of daily P&L

          on first bar of the day I calculate the : SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
          and on every bar II calculate the : SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency,Closes[1][0]);

          the difference between the two gives me the current P&L for that moment. including the end of day.

          HOW CAN I Calculate the Daily P&L in the OptimizationFitness script ?

          Comment


            #6
            Hello dadarara,

            Is the script only tested over a single day?
            If not, are you trying to find a specific day within the backtest iteration that has the highest or lowest PnL?

            You can calculate the Pnl using logic after each trade is closed. On new sessions the values can be saved / reset.

            As an example, below is a link to a DailyLossLimit script that demonstrates collecting PnL with logic. This resets at the new session, however, you could easily store this in a list or a custom trade performance collection.

            http://ninjatrader.com/support/forum...325#post490325

            The optimization fitness has the strategy instance (just named strategy). You could calculate these values for each day, store in a public collection, and then retrieve these from the OptimzationFitness script.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The optimization fitness has the strategy instance (just named strategy). You could calculate these values for each day, store in a public collection, and then retrieve these from the OptimzationFitness script."

              by public collection you mean some public dictionary or list i should create in my strategy?
              something like :

              public Dictionary<DateTime, string> myDayPnL = new Dictionary<DateTime, string>();

              and than populate it each new day with the P&L value ?

              but I need to re-create this custom dictionary on each optimization run. so how these values are saved to be used later in the Optimization analysis ?


              than how do I access it in the OptimizationFitness script I create ? I mean how do I calculate the Max.Min/average and present it as one of the optimization parameters ?

              this is a little above my level ... so please be patient with me while I learn. you have some example I can follow?

              BTW Are Custom Performance metrics have anything to do with the above ?
              Last edited by dadarara; 10-23-2018, 07:02 AM.

              Comment


                #8
                Hello dadarara,

                Backtest iterations in an optimization are run in parallel in different threads. This causes difficulty when attempting to combine information from different iterations.

                My suggestion was about getting an optimzation ranking value for individual iterations. I was not giving suggestions for having these persist through different iternations.

                But basically you could have a public List<double> of the daily PnL. Then from the optimization script call the strategy get the <Enumerable>.Max() / .Min() method to return the highest value in the array. That will be the day with the highest PnL in the backtest. This could then be assigned to Value in the optimization fitness script.

                https://docs.microsoft.com/en-us/dot....7.2#overloads

                When looking for loss, you would need some fancy logic to make the highest values the lowest and the lowest values the highest. Possibly multiplying the value by -1 might do the job (not positive on this).


                I don't have examples that are complex this and a lot of what you are doing is not documented.
                I have only one example of an optimization fitness script I can provide that is not related to what you are doing but I've attached it. This example shows how to call a custom performance metric from an optimization fitness script.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I think we went to a wrong direction.
                  I dont think I am asking for a complex thing.
                  I am looking for the average daily net profit over ONE iteration. nothing to do with other iterations running parallel. and in principle it can be negative or positive number.
                  no need for any fancy logic.

                  every day the strategy runs it make a few trades. at the end of the day there is a daily P&L value. it can be a loss or a profit.
                  I am running a strategy analyzer and would like to see among all the usual statistics also the average daily P&L (it should be positive otherwise whats the point )
                  We do have the average TRADE win or loss, the minimum and the maximum as well. WHY NOT Daily?
                  Indeed I can present a graph with the daily total Net profit. VERY NICE. So how about providing the average of the daily bars ? (and maybe the MIN and MAX) ? the program doesnt provide it.

                  When I run the strategy Optimizer , and there are 500 iterations of the strategy over the same data set. I would like to compare the different iterations not only by the maximum net profit or Max Drawdown, but by the Average Daily Net Profit.

                  There are two FANCY terms with the NT:
                  optimization fitness
                  Custom Performance metrics

                  Can we accomplish the above using one of these ?

                  Comment


                    #10
                    Hello dadarara,

                    With the comment:
                    'Backtest iterations in an optimization are run in parallel in different threads. This causes difficulty when attempting to combine information from different iterations.'

                    I was responding to your note:
                    "but I need to re-create this custom dictionary on each optimization run. so how these values are saved to be used later in the Optimization analysis ?"

                    Trying access the values later in the optimization analysis sounds like you are trying to access all of the backtest iterations when the optimization is complete. This may (or may not) be possible using static methods but I think would be difficult to achieve due to threading.


                    The graph of Daily profit in the Strategy Analyzer is showing multiple days meaning multiple values. This is not showing a single day.
                    However, if you have the logic in mind, you may be able to accomplish it. I personally just don't understand how you would turn multiple values for multiple days in to 1 value that can be used to rank the backtest unless you are averaging the daily values. So average I get because you just average the values into a single value. But max / min daily profit / loss I don't get because each day would have its own value.

                    The OptimizationFitness lets you rank backtest iterations by a value for that iteration. The PerformanceMetric creates a statistic that is shown in the summary results.
                    Likely you are wanting a custom OptimizationFitness.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      actually I would start with the more simpler thing ( I hope) : the Performance Metric.
                      I mean I would like to see in the Summary screen in the Analyzer, just bellow the "Largest losing trade" a NEW statistic by the name " Largest losing DAY" .
                      this would show the biggest losing daily amount (e,g profit, P&L)

                      a note: this is not exactly a sum of all trades during the day, as some trades might not close on the same day
                      This should be calculation of the running P&L for the day and its the value it has on the end of day.

                      So am I right to follow the path of Performance Metric ?

                      there is an example of SampleCumProfit that I am trying to learn how to adapt to my purpose of calculating the daily P&L.
                      but I am confused as to how to calculate the sum of trades per each day
                      would you mind advising on what should be the right command to calculate the daily P&L ?
                      Last edited by dadarara; 10-24-2018, 01:33 AM.

                      Comment


                        #12
                        Hello dadarara,

                        If you are trying to SUM the trades of all days, you can loop through the trade performance collection.

                        foreach(NinjaTrader.Cbi.Trade trade in strategy.SystemPerformance.AllTrades)
                        {
                        }
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by brucerobinson, Today, 02:43 AM
                        5 responses
                        26 views
                        0 likes
                        Last Post brucerobinson  
                        Started by 2Look4me, Today, 09:33 AM
                        6 responses
                        39 views
                        0 likes
                        Last Post NinjaTrader_PatrickH  
                        Started by calebsandfort, Today, 02:11 PM
                        2 responses
                        8 views
                        0 likes
                        Last Post calebsandfort  
                        Started by traderpards, Today, 02:16 PM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Jim  
                        Started by otislauwaert, Today, 12:59 PM
                        1 response
                        16 views
                        0 likes
                        Last Post NinjaTrader_Jim  
                        Working...
                        X