Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sharp Ratio Calculation

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

    Sharp Ratio Calculation

    In the docs (https://ninjatrader.com/de/support/h...efinitions.htm), the Sharp Ratio is defined as:
    (Profit per Month – risk free Rate of Return) / standard deviation of monthly profits

    So my first question would be what if my range of data is smaller than a month? It seems like I still get a sharp value even though the standard deviation could only get 1 data point, in which case it couldn't be calculated.

    My second question is regarding the calculation. I wanted to try it myself and I used the data which the Example Moving Average Strategy that is built in provides.
    when using the "Net Profit"-values of each Month and and the Profit per Month result I get

    (using python):
    -1082.57 / np.std([1475.46, 3855.48, 1337.71, 3464.98, -10528.74, -6064.82]) = -0.20247716864741613

    the Sharp Ratio which the Strategy Analyzer prints is -0.40. Why are they not the same, I used the calculation from the docs?
    What am I missing here?

    Screenshot with all the results + calculation:
    Click image for larger version

Name:	nt1.png
Views:	561
Size:	1.18 MB
ID:	1178419

    #2
    Hello berndhart,

    While I cannot provide the direct code, I will work on creating output from prints to help you track this, similar to the post linked below.
    I'm trying to calculate Ulcer Index by hand using the equations provided on the Statistics Definition page (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?statistics_definitions.htm), but I'm not getting the same values. The trade performance summary is showing an ulcer of 0.01, but calculated by


    In the meantime, you can retrieve this value from the SystemPerformance.AllTrades.TradesPerformance.Shar pRatio and print this after each position close or change to watch the progression.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello berndhart,

      I've gotten that script together to provide you some output to help you track how the SharpeRatio is calculated.

      Last trade:
      totalDays: 16, monthsNum: 0.524590163934426
      (1.0 + percentCumProfit: -0.0193012326463206): 0.980698767353679 * (1.0 + profitPercent: -0.00111660551922157): 0.998883394480778 = -0.0203962863026415 + 1 = -0.0193012326463206
      (|percentCumProfit: -0.0193012326463206 + 1| = 0.980698767353679 ^ 1.0 / monthsNum: 0.963529007002894 = -0.0364709929971057) - 1
      (percentProfitPerMonth: -0.0364709929971057 - riskFreeReturn: 0): -0.0364709929971057 / monthlyStdDev: 0.0640149466792037 = -0.56972621065939
      Attached Files
      Last edited by NinjaTrader_Jim; 11-18-2021, 10:47 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you for the answer,
        I tried to understand your calculation, that is what I understood that far:
        from the docs (https://ninjatrader.com/de/support/h...efinitions.htm) you used:

        In the first line:
        HTML Code:
        (1.0 + percentCumProfit: -0.0743994238517707): 0.925600576148229 * (1.0 + profitPercent: 0): 1 = -0.0743994238517707 + 1 = -0.0743994238517707
        you are calculating:
        SUM((1 + Current Profit in Percent) * (1 + Profit in Percent) - 1) for all trades
        but for one trade only hence "Profit in Percent" = 0, since there weren't any trades before that point in time.

        The in the next line:
        HTML Code:
        (|percentCumProfit: -0.0743994238517707 + 1| = 0.925600576148229 ^ 1.0 / monthsNum: 0.952061506373716 = -0.0479384936262837) - 1
        you are calculating:
        (1 + cumulative profit)(1 * (30.5 / # days)) - 1
        which gives us the Profit per Month in percent: -0.0479384936262837.

        Now we get to the Sharpe Ratio, this is where I can't follow you, definition from docs:
        HTML Code:
        (Profit per Month – risk free Rate of Return) / standard deviation of monthly profits
        your calculation:
        HTML Code:
        (currencyProfitPerMonth: -10635.2864583333 - riskFreeReturn: 0): -10635.2864583333 / monthlyStdDev: 0.0547242922537766 = -0.876000248737348
        With the "currency profit per Month" being calculated as a ES contract * "Profit per Month in percent".
        The "monthlyStdDev" is where I am still not understanding how it is calculated. Since the StdDev always needs more than 1 value to be calculated I don't understand how we can get a value from it with only 1 trade done to that point in time, also why is it 0.0547242922537766?



        Comment


          #5
          Hello berndhart,

          Thanks for pointing out. Our test script was printing Currency parts of the calculation. I made corrections so it prints Percent information for the Percentage calculation.

          I changed the information from post #3 to reflect the percentage calculation with fewer trades.

          Comment


            #6
            •NinjaTrader hard sets "risk-free Rate of Return" to a value of zero
            Don't know why you guys did this but this leads to misleading results. It's not real Sortino or Sharpe ratios.

            Comment


              #7
              Hello Leeroy_Jenkins,

              There wasn't a good way to get accurate data for RiskFreeReturn for all setups, which is why we have a RiskFreeReturn property for TradesPerformance where it can be overridden.

              https://ninjatrader.com/support/help...freereturn.htm

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              64 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              139 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              75 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              45 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              50 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X