SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Mar 26, 2019 7:22 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GetMoment equation
PostPosted: Fri Jun 10, 2016 3:39 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 222
Hi,

What equation are you using to GetMoment() where k=3 i.e skewness?

Is it based on this : Image

i.e. the sample skewness: Image

Regards


Top
 Profile  
 
 Post subject: Re: GetMoment equation
PostPosted: Fri Jun 10, 2016 3:45 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6811
Hi,

in OQ3

Code:
      public override double GetMoment(int k, int index1, int index2, int row)
      {
         if (Count <= 0)
            throw new ApplicationException("Can not calculate momentum. Series " + fName + " is empty.");

         if (index1 > index2)
            throw new ApplicationException("index1 must be smaller than index2");

         if (index1 < 0 || index1 > Count - 1)
            throw new ApplicationException("index1 is out of range");

         if (index2 < 0 || index2 > Count - 1)
            throw new ApplicationException("index2 is out of range");

         double x;

         if (k == 1)
            x = 0;
         else
            x = GetMean(index1, index2, row);

         int    n        = 0;
         double moment = 0;

         for(int i=index1;i<=index2;i++)
         {
            moment += Math.Pow(this[i, row] - x, k);
            n++;
         }

         if (n == 0)
            return 0;
         else
            return moment / n;
      }

      #endregion

      #region Asymmetry, Excess

      public override double GetAsymmetry(int index1, int index2, int row)
      {
         if (Count <= 0)
            throw new ApplicationException("Can not calculate asymmetry. Series " + fName + " is empty.");

         if (index1 > index2)
            throw new ApplicationException("index1 must be smaller than index2");

         if (index1 < 0 || index1 > Count - 1)
            throw new ApplicationException("index1 is out of range");

         if (index2 < 0 || index2 > Count - 1)
            throw new ApplicationException("index2 is out of range");

         double stdDev = GetStdDev(index1, index2, row);

         if (stdDev == 0)
            return 0;
         else
            return GetMoment(3, index1, index2, row)/Math.Pow(stdDev, 3);
      }

      public override double GetExcess(int index1, int index2, int row)
      {
         if (Count <= 0)
            throw new ApplicationException("Can not calculate excess. Series " + fName + " is empty.");

         if (index1 > index2)
            throw new ApplicationException("index1 must be smaller than index2");

         if (index1 < 0 || index1 > Count - 1)
            throw new ApplicationException("index1 is out of range");

         if (index2 < 0 || index2 > Count - 1)
            throw new ApplicationException("index2 is out of range");

         double stdDev = GetStdDev(index1, index2, row);

         if (stdDev == 0)
            return 0;
         else
            return GetMoment(4, index1, index2, row)/Math.Pow(stdDev, 4);
      }



Regards,
Anton


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group