Efficient Frontier

Portfolio of two assets

\[ \mathbb{E}(R_P)=\omega_1\mathbb{E}(R_1)+\omega_2\mathbb{E}(R_2), \]

Example

\(\omega_X\) 100% 80% 60% 40% 20% 0%
\(\omega_Y\) 0% 20% 40% 60% 80% 100%
—————- ———- ———– ———- ———– ———- ———-
\(\mathbb{E}(R_P)\) 5% 4.8% 4.6% 4.4% 4.2% 4%
\(\sigma_P^2\) 9% 6.96% 5.64% 5.04% 5.16% 6%
—————- ———- ———– ———- ———– ———- ———-

Portfolio of \(N\) assets

\[ \mathbb{E}(R_P)=\omega^T\mu, \] where \(\omega^T=\{\omega_1,\omega_2,...,\omega_N\}\), \(\mu=\{\mu_1,\mu_2,...,\mu_N\}\), \(\mu_i=\mathbb{E}(R_i)\), \(i=1,2...,N\) and

Index_Value<-as.matrix(EuStockMarkets)
r<-diff(log(Index_Value))*100
no.of.portf<-10000
set.seed(1)
sigma<-mu<-rep(NA,no.of.portf)
for(i in 1:no.of.portf){
  w <- sample(1:1000,4,replace=T)
  w <- w/sum(w) ## weight for i-th portfolio
  rp <- r%*%w   ## returns of i-th portfolio
  mu[i] <- mean(rp)  ## mean return of i-th portfolio
  sigma[i] <- sd(rp) ## volatility of i-th portfolio
}

##################################

plot(sigma,mu,xlab = "volatility"
     ,ylab="expected return",col="grey")
abline(h=0.065,col="red",lwd=2)
segments(0.8,0.04,0.8,0.065,col="blue",lwd=2)
segments(0.85,0.04,0.85,0.065,col="green",lwd=2)
arrows(0.775,0.07,0.8,0.065,col="black",lwd=2)
arrows(0.875,0.07,0.85,0.065,col="black",lwd=2)
text(0.77,0.071,"w1")
text(0.88,0.071,"w2")
points(0.779,0.065,col="blue",lwd=2)
text(0.779,0.066,"w")
points(0.81,0.07,col="blue",lwd=2)
text(0.81,0.0715,"v")

### Plot the efficient frontier
Sigma<-cov(r)
library(tseries)

er<-seq(0.045,0.075,0.001)
frontier<-matrix(NA,nrow=length(er),ncol=2)
for(i in 1:length(er)){
  port_optim<-portfolio.optim(r
                ,pm=er[i]
                ,covmat=Sigma)
  frontier[i,]<-c(port_optim$ps,port_optim$pm)
}
lines(frontier,col="red")