SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Apr 03, 2020 12:56 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Skew & Kurtosis
PostPosted: Fri Nov 17, 2006 4:55 pm 
Offline

Joined: Sun May 15, 2005 11:13 pm
Posts: 367
Location: Bermuda
Here is some code to calculate Std Dev & RSquared in an incremental fashion. Does anyone know how to do something similar for Skew & Kurtosis?

Code:
   protected void Add( double x, double y ) {
      //Console.WriteLine( "add,{0},{1:#.00},{2:#.000}", dsSlope.Name, val, x );
      SumXX += x * x;
      SumX  += x;
      SumXY += x * y;
      SumY  += y;
      SumYY += y * y;
      Xcnt++;
   }
   
   protected void Remove( double x, double y ) {
      //Console.WriteLine( "rem,{0},{1:#.00},{2:#.000}", dsSlope.Name, val, x );
      SumXX -= x * x;
      SumX  -= x;
      SumXY -= x * y;
      SumY  -= y;
      SumYY -= y * y;
      Xcnt--;
       
      CanCalcSlope = true;
   }

   protected virtual void CalcStats() {
       
      double oldb1 = b1;
       
      Sxx = SumXX - SumX * SumX / Xcnt;
      Sxy = SumXY - SumX * SumY / Xcnt;
      Syy = SumYY - SumY * SumY / Xcnt;

      SST = Syy;
      SSR = Sxy * Sxy / Sxx;
      SSE = SST - SSR;

      RR = SSR / SST;
      R = Sxy / Math.Sqrt(Sxx * Syy);
         
      SD = Math.Sqrt( Syy / ( Xcnt - 1 ) );

      meanY = SumY / Xcnt;
       
      b1 = CanCalcSlope ? Sxy / Sxx : 0;
      b0 = ( 1 / Xcnt ) * ( SumY - b1 * SumX );
      b2 = b1 - oldb1;  // *** do this differently
   }

_________________
http://www.oneunified.net/blog/Trading


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 10:11 pm 
Offline

Joined: Fri May 06, 2005 1:40 am
Posts: 521
A quick lazy answer: you''ll most likely find something of use in this lot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 5:12 pm 
Offline

Joined: Sat Apr 21, 2007 8:30 pm
Posts: 7
Location: Switzerland
it is indede a quick lazy answer :lol: following the hyperlink suggests extracting skewness and kurtosis from the variance, which assumes that your dataset is normally distributed...

i would suspect that if you want to measure the higher moments, you are questionning the normality of the set, so it is absurd to base your calculations on the assumption of normality.

you need the fully fledged calculations, easy to find on the web


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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