Brian,

Here is a quick test script for comparing coskewness between 10 assets.  
The matrix coskew I generate holds the coskewness measures.  I also show 
how to adjust the diagonal elements of coskew to get them equal to the 
actual skewness measures.

#Equity coskewness cokurt tests
#Joe W. Byers
#written: 2/15/2007


#set up enviroment and libraries
library(date); 
library(car);library(tseries);library(Hmisc);library(fBasics);
library(R2HTML);
library(partsm);library(tseries);library(pear);
library(fBasics);library(fSeries);library(zoo);
library(fPortfolio);
#load brian's functions
source('D:/Projects/3083/comomentsfuncs.R')

# set company ticker vector (last ticker is index)and initial weights
co<-c('FRE','FNM','MO','PFE','EDS','EP','MMC','TYC','KFT','AXP', '^GSPC')
w<-c(.154,.112,.11,.11,.104,.097,.084 ,.08 ,.076 ,.073 )

#init date variables
start=format(Sys.time(),"%Y-%m-%d")
end=format(Sys.time(), "%Y-%m-%d")
start <- as.POSIXct(start,tz="GMT")   # store date as POSIXct
start<-start-3*365*3600*24
end <- as.POSIXct(end,tz="GMT")
#load company historical prices and index from yahoo finance
for (i in 1:length(co)) {
  t1<-get.hist.quote(co[i],start= as.character(start),quote='AdjClose')
  dimnames(t1)[2]<-co[i]
  if (i==1) {
    qts<-t1 }
    else {
    qts<-merge(qts,t1) }
}
#get the returns
returns<-diff(log(qts))
#calculate the covariance matrix
bigsigma<-var(returns)
#means<-apply(returns,2,FUN=mean)
#calculate some summary stats
stat<-data.frame(Mean=apply(returns,2,mean),
    STD=apply(returns,2,sd),
    Min=apply(returns,2,min),
    Max=apply(returns,2,max),
    Median=apply(returns,2,median),
    Skewness=apply(returns,2,skewness),
    Kurtosis=apply(returns,2,kurtosis));

#lets test coskewness
coskew<-matrix(NA,10,10)
for (i in 1:10) {
   for (j in 1:10) {
    coskew[i,j]<-CoSkewness(returns[,i],returns[,j])
    #mean((returns[,i]-mean(returns[,i]))*(returns[,j]-mean(returns[,j]))^2)
   }
}

#coskew of i with i should be skew
coskew[10,10]
#adjustment to get coskew asset i with i to equal skewness of asset i
coskew[10,10]/(stat$STD[10]^2)^(3/2)
#or for the entire coskew matrix now the diagonal elements equal the
#individual assets skewness measure
coskew/(bigsigma[1:10,1:10])^(3/2)

Joe


brian@braverock.com wrote:
> On Thursday 15 February 2007 06:49, Joe W. Byers wrote:
>   
>>> Hope it helps.
>>>       
>> This helps a bunch and is what I was thinking about doing to modify
>> this function.  I was also trying to be tactful about the assetsStat
>> functions is clearly wrong and all the risk stats that use these two
>> variables are incorrect.
>>     
>
> I also think the modifiedVaR calculation is wrong there, and doesn't take 
> the higher moments   Our functions have a Modified Cornish-Fisher VaR 
> calc that I think is more complete/correct.
>
>   
>>> We're working on packing all our previously released functions now,
>>> but writing .Rd files, standardizing parameter names and ordering,
>>> and collecting sample data, examples, and tests is taking time.
>>>       
>> Do you want some help? I might be able to help with docs, data (I have
>> a lot of energy data), and examples ( teach so I have some good ones ).
>>     
>
> I'll do a little more cleanup by Saturday morning at the latest, and post 
> the code and package tarball for you to take a look at.  In additiona to 
> all the analytics functions, have quite a few chart and (text) table 
> functions that collect performance statistics into groupings that we find 
> useful.
>
> I am wondering whether you've ever done any thinking about co-skewness or 
> co-kurtosis.  I had previously implemented and released functions for 
> these, but I'm now pretty much convinced that they are incorrect (which 
> also makes the standardized systematic functions that rely on them 
> incorrect).  Help sorting that out would be greatly appreciated.
>
> Regards,
>
>   - Brian
>
>   


	[[alternative HTML version deleted]]

