Created
May 15, 2012 18:17
-
-
Save timelyportfolio/2703904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(quantmod) | |
require(PerformanceAnalytics) | |
#load my barclays agg file | |
#if you do not have access to Barclays Agg return then you can | |
#use VBMFX as a proxy | |
portfolio <- read.csv("C:\\Users\\Kent.TLEAVELL_NT\\Documents\\old\\R\\barclaysagg.csv",stringsAsFactors=FALSE) | |
portfolio <- portfolio[2:(NROW(portfolio)-1),2:NCOL(portfolio)] | |
portfolio <- portfolio[,c(1,4)] | |
#since export has duplicate colnames we need to remove the .1 added | |
#colnames(portfolio) <- substr(colnames(portfolio),1,nchar(colnames(portfolio))-2) | |
#transform to get in appropriate xts form | |
len <- nchar(portfolio[,1]) | |
xtsdate <- paste(substr(portfolio[,1],len-3,len),"-", | |
ifelse(len==9,"0",""),substr(portfolio[,1],1,len-8),"-01",sep="") | |
portfolio.xts <- xts(data.matrix(portfolio[,2:NCOL(portfolio)]),order.by=as.Date(xtsdate)) | |
portfolio.xts <- portfolio.xts/100 | |
portfolio.xts[1,]<-0 | |
#########start skew analysis################################################ | |
colnames(portfolio.xts) <- "BarclaysAgg" | |
#get rolling skew | |
skew <- apply.rolling(portfolio.xts[,1],FUN=skewness,width=36,by=1) | |
#combine skew with ROC | |
skew.roc <- merge(skew, | |
ROC(apply(portfolio.xts[,1]+1,MARGIN=2,FUN=cumprod),type="discrete",n=36)) | |
colnames(skew.roc)<-c("skew","roc") | |
#plot skew and roc | |
chart.TimeSeries(skew.roc, main="Barclays US Aggregate Skew and ROC (Rolling 36-month)", | |
legend.loc="topright") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment