Expr<- sapply(asret,mean) #Calculating the expected return (Just the mean of the each of the assets) sdh<- sapply(asret,sd) #Calculating the Standard deviation. varh<-sapply(asret,var) covmat<-cov(asret) cormat<-cor(asret) ncol(asret) library(PerformanceAnalytics) library(tseries) library(quadprog) #Portfolio analysis. library("devtools") install_github("dengyishuo/fPortfolio") library(fPortfolio) #Hedge portfolio# wa<-rep(1,ncol(asret))/ncol(asret) Return.portfolio(as.timeSeries(asret),weights=wa) #hedge returns.
FrontierH <- portfolioFrontier(as.timeSeries(asret)) #Frontier #Kospi200 portfolio# k200pert<-mean(k200rt[,2]) #Kospi200 portfolio return k200pert FrontierK2<- portfolioFrontier(as.timeSeries(k200pert)) #CHECK THIS
#Unhedge portfolio#
unhert<- mean(unhedgert[,2]) #unhedge Expected return unhert FrontierUn<-portfolioFrontier(as.timeSeries(unhedgert[2,])) #CHECK THIS class(unhedgert) plot(Frontier)
#analysis per year class(asret$date) xd <- as.Date(asret$date, format="%d-%b-%Y") class(xd) head(dperyear)
dperyear<- subset(asret) dperyear<- split(asret,xd, f="year")
class(dperyear$date)
bb<- subset(dperyear,dperyear$date) split(dperyear, cut(strptime(paste(asret$date), format="%m%d%y"),"byyear")) head(asret) #BOOTSTRAPPING library(boot) data00<- unhedgert[1:53,] head(data00);tail(data00) n<-dim(data00)[1] colnames(data00) wa<-rep(1,(ncol(data00) -1))/(ncol(data00)-1) n<-length(data00[,1]) sampleboot<- 10000 #Number of simulations stmu<- rep(0,sampleboot) #creating an estimated mean for (i in 1:sampleboot) { boot.data= sample(data00,n, replace=TRUE) stmu[i]= mean(boot.data)
}