Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StdDev - bug or feature

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

    StdDev - bug or feature

    The StdDev indicator uses n rather than n-1 as the denominator. Is this a feature, or a bug, and if a feature, what is the thinking behind it.

    thanks
    Dave

    #2
    Dave, I believe this is because the formula implements the standard deviation of the sample (so without Bessel's correction applied).
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Is this still true? It looks like the StdDev indicator now calculates the standard deviation of a population rather than a sample due to this line of code:

      Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));

      Please advise. Thank you!

      Comment


        #4
        Hello,

        Yes, Bertrand's answer would still hold true, this is a sample being checked over a period and not the entire collection.

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

        Comment


          #5
          You are missing something important

          cb4gusto22, the key here is:
          Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));

          The sample can never be more than the Period.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment


            #6
            Thanks for the responses. I understand that the indicator is calculating the standard deviation of whatever look-back period length the user selects. However, the calculation itself is assuming that it is taking the standard deviation of a population, rather than a sample, correct?

            Compare with the calculations of the indicator in this thread: http://www.ninjatrader.com/support/f...viation+sample

            Here, it really is "period - 1" whereas in the NT version, there is no "- 1". This article also helps clarify what I'm trying to understand/verbalize: https://statistics.laerd.com/statist...-deviation.php

            Thanks again!

            Comment


              #7
              Looking at the thread you referenced it occurs to me you are not understanding the period - 1.

              Say the period is set to 7. The indicator cannot reference more bars than are on the chart so the check is made comparing the period to the current number of bars. Since CurrentBar starts with bar zero, at bar 6 there are 7 bars on the chart and the indicator can work. Bar 6 = Period - 1 (7 - 1 = 6). This is only a start up issue and the indicator should still be using its Period number of bars just as the NT version does.
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              Comment


                #8
                I completely understand what you are saying. Here's an example of the issue I'm trying to understand between calculating the StdDev of sample vs. calculating the StdDev of population:

                Assume stock prices of 1, 2, 3, and 4 from oldest to newest. Assume a period of 2.

                Case A: I believe the NT version of the indicator would assume that "3" and "4" were the entire "population" and calculate the StdDev using the period of 2 as the denominator. The StdDev would thus = 0.5

                Case B: Now, if we assume that "3" and "4" were only a "sample" of the population, the denominator would be "period - 1" which would be 2 - 1 = 1. In this case, the STD would = 0.707107. This yields a different result.

                So, can someone please confirm that the NT indicator is Case A? Thanks!

                Comment


                  #9
                  Looking at the NT version the line:

                  for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack >= 0; barsBack--)
                  sum += (Input[barsBack] - avg) * (Input[barsBack] - avg);

                  is a loop. The barsBack variable is set up for Period - 1. If the Period = 7, barsback would be initially set to 6. This is because the loop starts with Input([barsBack] which = Input[6] and loops forward till you hit Input[0] which is the current bar. That is seven bars worth of Input which is your actual Period.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Originally posted by cb4gusto22 View Post
                    Thanks for the responses. I understand that the indicator is calculating the standard deviation of whatever look-back period length the user selects. However, the calculation itself is assuming that it is taking the standard deviation of a population, rather than a sample, correct?

                    Compare with the calculations of the indicator in this thread: http://www.ninjatrader.com/support/f...viation+sample

                    Here, it really is "period - 1" whereas in the NT version, there is no "- 1". This article also helps clarify what I'm trying to understand/verbalize: https://statistics.laerd.com/statist...-deviation.php

                    Thanks again!
                    Your real question here is whether to calculate the sample StdDev or the population StdDev.

                    It depends on how you choose to think of it. Granted that any lookback period set of values is a sample of all the values on the chart, what you are measuring on any given bar is the StdDev of the exact set that you have chosen, not an estimate of the StdDev for all the entire chart population. Therefore, your measurement sample space is complete in itself, as that is the entire population for which you are then calculating (on that particular bar). So the correct measure of the standard deviation of the last 10 values, say, is the population standard deviation of those 10 values, because the 10 values are the entire population over which you are measuring on that bar.

                    On the other hand, if you wanted to estimate the StdDev of all the values on the chart, using samples, it might make more sense then to use a number of independent samples, without replacement, and the Central Limit Theorem, rather than to use just one small sample.

                    NT is correctly, in my opinion, calculating the population StdDev for the stochastic sample relevant to each bar.

                    Comment


                      #11
                      Your real question here is whether to calculate the sample StdDev or the population StdDev.

                      NT is correctly, in my opinion, calculating the population StdDev for the stochastic sample relevant to each bar.
                      Thank you, Kognan. This is exactly what I was looking for.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by traderqz, Today, 12:06 AM
                      10 responses
                      18 views
                      0 likes
                      Last Post traderqz  
                      Started by algospoke, 04-17-2024, 06:40 PM
                      5 responses
                      46 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by arvidvanstaey, Today, 02:19 PM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Zachary  
                      Started by mmckinnm, Today, 01:34 PM
                      3 responses
                      5 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by f.saeidi, Today, 01:32 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post f.saeidi  
                      Working...
                      X