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

Stdev discrepencies

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

    Stdev discrepencies

    Greetings,

    I've got a series of data in a DataSeries object for the last 17 periods. I want to find the Standard Deviation for the FIRST 9 periods...when I input the values on the statistical calculator (in Windows) the values for SUM and AVERAGE match what I'm getting in my output, however there are small differences in Standard Deviation, I'm at a loss to explain why?

    The data in question:

    the DataSeries is called "MINORS" and the period data is as follows:

    [0] = 24; [1] = 34; [2] = 38; [3] = 37; [4] = 37; [5] = 32; [6] = 30.2;
    [7] = 48.1; [8] = 47;

    the STDEV command: Ds = StdDev(MINORS, 9)[0];

    The Output Window reports the StdDev as "7.2252" however the calculator outputs "7.6635", why the difference?

    #2
    Sorry I don't know. Please see the StdDev sources to see how NT calculates the StdDev.

    Comment


      #3
      Thank you for the reply. So I guess you agree at least that my command line to calculate "Ds" is at least correct?

      As for the discrepency I guess you are also correct there must be some difference in how the calculator and NT are figuring Stdev, however without knowing how the calculator is doing it just looking at the NT source isn't much help. I checked the Help files in the calculator and it simply seems to give instructions on how to calculate Stdev, but not the internal math processes used...

      Comment


        #4
        Syntax looks correct but you can verify in the Help Guide.
        RayNinjaTrader Customer Service

        Comment


          #5
          No Stdev discrepencies with this code

          I use this code to get standard deviation:

          ...

          double sum = 0;
          for ( int i = 1; i <= Periods; i++)
          sum += Math.Pow(Close[i-1]-SMA(Periods)[0],2);

          Value.Set(Math.Sqrt(sum/(Periods-1)));

          ...

          Difference between Ninjatrader and other charting applications (or Excel) is division by N (Periods) or N -1 (both is "correct" but division by N-1 is more common).

          Comment


            #6
            Thank you for that helpful information!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            22 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            20 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            230 views
            0 likes
            Last Post TradingLoss  
            Working...
            X