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

Understanding Ulcer Index

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

    Understanding Ulcer Index

    I'm trying to calculate Ulcer Index by hand using the equations provided on the Statistics Definition page, but I'm not getting the same values.
    The trade performance summary is showing an ulcer of 0.01, but calculated by hand using the equation I'm getting 3775.

    Click image for larger version

Name:	scree.PNG
Views:	63
Size:	67.8 KB
ID:	1175135
    Click image for larger version

Name:	scree.PNG
Views:	58
Size:	49.8 KB
ID:	1175136

    #2
    Hello nnwakaihe,

    Thanks for your note about this.

    Let me do some research and I will follow up. I appreciate your patience.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello nnwakaihe,

      SQRT(Summation((cumulative currency profit - maximum realized currency profit) ^2 ) / Total # of trades)

      May I see the math work you are doing to calculate this by hand?

      Jim has a similar script demonstrating calculating the R2.
      https://ninjatrader.com/support/foru...953#post806953
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Chelsea B,

        I am doing the math with excel. Maybe I am mixing up what each variable means.

        Please correct me if I am wrong:
        cumulative currency profit is the cumulative profit after each trade
        maximum realized currency profit is the max profit realized throughout a given set of trades.

        Comment


          #5
          Hello nnwakaihe,

          This is Jim responding on behalf of Chelsea who is out of the office at this time.

          Cumulative Currency Profit is the cumulative profit in currency after each trade, yes.

          Maximum Realized Currency Profit is the maximum profit in currency seen from all trades.

          Summary Display in the Strategy Analyzer shows this value as a percentage (as that is how it is most meaningful,) regardless if you have Currency, Pips, Ticks, Points, selected in the Strategy Analyzer's Display Selector. If you want to view an overall result for Currency, Pips, Ticks, Points, you may view the Analysis Display, and select a Period of Yearly, and then add Ulcer to the grid by right clicking and selecting Properties. (This assumes the backtest was less than 1 year in length.)

          Cumulative Percent Profit can be calculated as: (1.0 + [Cumulative Percent Profit]) * (1.0 + [Profit as Percent from trade]) - 1;

          Maximum Realized Percent Profit can be calculated as the maximum [Cumulative Percent Profit​​​​​​​]] of all trades.

          This detail should help to follow the Statistics Definitions formula from the Help Guide to get the same result the Strategy Analyzer displays.

          JimNinjaTrader Customer Service

          Comment


            #6
            Jim/Chelsea,

            Attached are the images of my excel results. Am I just horrible at math???

            Click image for larger version

Name:	Capture.PNG
Views:	37
Size:	22.2 KB
ID:	1176737
            Click image for larger version

Name:	Capture.PNG
Views:	36
Size:	21.9 KB
ID:	1176738

            Comment


              #7
              Hello nnwakaihe,

              I don't want you to think I'm ignoring you. I'm just doing the math on each trade in a trade collection for the SampleMACrossover and it's busy work that takes some time. I'm also having to be mindful of response time with other inquiries.

              i.e. i'm at the third trade out of 14.

              (1.0 + [Cumulative Percent Profit]) * (1.0 + [Profit as Percent from trade]) - 1

              Trade number Market pos. Qty Entry price Exit price Entry time Exit time Entry name Exit name Profit Cum. net profit
              1 Short 1 14633.25 14659.50 10/11/2021 9:00:00 PM 10/12/2021 12:00:00 PM Sell short Close position -0.18% -0.18%

              (1.0 + 0) * (1.0 + -.0018) - 1
              1 * .9982 - 1
              cumProfitPercent: -0.0018
              topPercent: -0.0018

              ( (1 + -0.0018) / (1 + -0.0018) - 1) ^ 2
              ( 0.9982 / 0.9982 - 1) ^ 2
              performancePercentUlcer: 0

              (0 / 1) ^ 1/2 (sqr root)
              0


              Trade number Market pos. Qty Entry price Exit price Entry time Exit time Entry name Exit name Profit Cum. net profit
              2 Long 1 14659.50 14597.25 10/12/2021 12:00:00 PM 10/12/2021 3:00:00 PM Buy Exit on session close -0.42% -0.60%

              (1.0 + -0.0018) * (1.0 + -.0042) - 1
              .9982 * .9958 - 1
              cumProfitPercent: -0.00599244
              topPercent: -0.0018

              ( (1 + -0.00599244) / (1 + -0.0018) - 1) ^ 2
              ( 0.99400756 / 0.9982 - 1) ^ 2
              performancePercentUlcer: 0.99161764

              (0.99161764 / 1) ^ 1/2 (sqr root)
              0.9958


              Trade number Market pos. Qty Entry price Exit price Entry time Exit time Entry name Exit name Profit Cum. net profit
              3 Short 1 14608.50 14713.00 10/12/2021 6:00:00 PM 10/13/2021 7:00:00 AM Sell short Close position -0.72% -1.31%

              (1.0 + -0.00599244) * (1.0 + -.0072) - 1
              0.99400756 * 0.9928 - 1
              cumProfitPercent: -0.010167271752
              topPercent: -0.0018

              ( (1 + -0.010167271752) / (1 + -0.0018) - 1) ^ 2
              ( 0.989832728248 / 0.9982 - 1) ^ 2
              performancePercentUlcer: 0.0000702639591696

              (0.0000702639591696 / 1) ^ 1/2 (sqr root)
              0.9958
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello nnwakaihe,

                Thanks for your patience.

                Our lead got some inside help from our development that can provide some output to see these calculations.

                Unfortunately, I cannot provide the code to produce this as it is part of the proprietary NinjaTrader core code, but the output does allow you to track the progression of the values.

                I can say that the trade profit in percent, needed for these calculations, can be retrieved from the SystemPerformance collection.
                SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count-1].ProfitPoints

                https://ninjatrader.com/support/help...erformance.htm
                https://ninjatrader.com/support/help.../nt8/trade.htm

                Attached is the full output saved to a text file.

                The key focus is the last trade:
                Trades: 12
                Cumulative percent profit: -0.0162785218688896 Percent profit from trade: 0.000203685134118827
                (1.0 + Cumulative percent profit) * (1.0 + Percent profit from trade) - 1: -0.016078152427681 (new Cumulative percent profit)
                Maximum realized percent profit : 0.00210536466201661
                (1.0 + Cumulative percent profit) / (1.0 + Maximum realized percent profit) - 1) ^ 2: 0.00179784142525246
                SQRT((1.0 + Cumulative percent profit) / (1.0 + Maximum realized percent profit) - 1) ^ 2 / trades): 0.0122401028905413
                Also attached is a screenshot of the Strategy Analyzer summary. Note that the Ulcer index is rounded in the Analyzer.
                Attached Files
                Last edited by NinjaTrader_ChelseaB; 11-03-2021, 10:20 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fafafdenis, Today, 04:56 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by pjsmith, 07-18-2019, 04:21 AM
                7 responses
                249 views
                0 likes
                Last Post aligator  
                Started by ark321, Today, 05:12 PM
                0 responses
                11 views
                0 likes
                Last Post ark321
                by ark321
                 
                Started by futurenow, Today, 04:49 PM
                0 responses
                9 views
                0 likes
                Last Post futurenow  
                Started by ofer1964spivak, Today, 04:27 PM
                0 responses
                5 views
                0 likes
                Last Post ofer1964spivak  
                Working...
                X