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

Standard Deviations with different Average

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

    Standard Deviations with different Average

    Hello,


    I have developed custom Standard Deviation based on different average like the:

    1. Geometrical average

    2. Harmonic average

    3. Quadratic average


    As shown in the attached pic, i would like to understand why, for the same Period:

    1. The Regular Stdev is almost equal to the Harmonic StdDev
    2. The Geom Stdev is almost equal to the Quadratic StdDev


    It's more like a maths problem but i would be interested to have a feedback...


    Thanks
    Attached Files
    Last edited by cbadr; 06-12-2018, 01:12 AM.

    #2
    Originally posted by cbadr View Post
    Hello,


    I have developed custom Standard Deviation based on different average like the:

    1. Geometrical average

    2. Harmonic average

    3. Quadratic average


    As shown in the attached pic, i would like to understand why, for the same Period:

    1. The Regular Stdev is almost equal to the Harmonic StdDev
    2. The Geom Stdev is almost equal to the Quadratic StdDev


    It's more like a maths problem but i would be interested to have a feedback...


    Thanks
    That would be impossible to tell with certainty without seeing the code. Offhand, it would most likely be because your code refactors to identical code between the matching methods.

    Comment


      #3
      Thanks for the answer.
      Here the code i used for the Geometrical Average:
      But after investigations on google, i realized i couldn't used the same Std calculation once the Mean is calculated.
      I'll have to update the formula accordingly.
      Any thoughts on this?



      Code:
      protected override void OnBarUpdate()
              {
                  if (CurrentBar < 1)
                  {
                      Value.Set(0);
                      sumSeries.Set(Input[0]);
                  }
                  else
                  {
                      sumSeries.Set(Input[0] * sumSeries[1] * (CurrentBar >= Period ? 1/Input[Period]: 1));
                      double avg = Math.Pow(sumSeries[0],1/Math.Min(CurrentBar + 1, Period));
                      double sum = 0;
                      for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack >= 0; barsBack--)
                          sum += (Input[barsBack] - avg) * (Input[barsBack] - avg);
      
                      Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));
                  }
              }

      Comment


        #4
        Originally posted by cbadr View Post
        Thanks for the answer.
        Here the code i used for the Geometrical Average:
        But after investigations on google, i realized i couldn't used the same Std calculation once the Mean is calculated.
        I'll have to update the formula accordingly.
        Any thoughts on this?



        Code:
        protected override void OnBarUpdate()
                {
                    if (CurrentBar < 1)
                    {
                        Value.Set(0);
                        sumSeries.Set(Input[0]);
                    }
                    else
                    {
                        sumSeries.Set(Input[0] * sumSeries[1] * (CurrentBar >= Period ? 1/Input[Period]: 1));
                        double avg = Math.Pow(sumSeries[0],1/Math.Min(CurrentBar + 1, Period));
                        double sum = 0;
                        for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack >= 0; barsBack--)
                            sum += (Input[barsBack] - avg) * (Input[barsBack] - avg);
        
                        Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));
                    }
                }
        Whereas you are using a rather inefficient algorithm, I nonetheless do not quite understand what you are asking. You appear to be calculating a mean, then looping backwards and summing the squares of the deviations from the mean. That is the basic definition of how to determine the variance and hence StdDev. So what is the issue?

        Comment


          #5
          The issue is about understanding the result of the StdDev from a Geometric VS Harmonic VS Squared Mean.


          From wikipedia i found that the formula to get the Geometric Std is mention there:





          Thats a first thing i have to update on the script.


          Then really i am wondering if the Std formala is the same for the other Mean?

          Comment


            #6
            Originally posted by cbadr View Post
            The issue is about understanding the result of the StdDev from a Geometric VS Harmonic VS Squared Mean.


            From wikipedia i found that the formula to get the Geometric Std is mention there:





            Thats a first thing i have to update on the script.


            Then really i am wondering if the Std formala is the same for the other Mean?
            For an unbiased estimator, the standard deviation is always the Root Mean Square Deviation, the square root of the variance, regardless of what mean you are using, albeit the mean used is almost always the arithmetic mean, rather than any other.

            Why do you think that a geometric mean may be more appropriate for what you are trying to do, if I may ask.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by martin70, 03-24-2023, 04:58 AM
            15 responses
            114 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by The_Sec, Today, 02:29 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by jeronymite, 04-12-2024, 04:26 PM
            2 responses
            31 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Mindset, 05-06-2023, 09:03 PM
            10 responses
            265 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by michi08, 10-05-2018, 09:31 AM
            5 responses
            743 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X