Portfolio Optimization-II (handling “short” position)

Instead of using OptWeights function created in last post, we will use portfolio.optim function which is present in “tseries” library to handle “short” position stocks. Therefore make sure to have “tseries” package installed before running this code:

First, lets check the weights when “short” positioning of stocks are allowed:

It is same to what we have got in our last post.

Now if “shorts = FALSE” means when short positioning is not allowed, what will be the new weights?

Weights got changed but overall sum is still 1.

To create frontier using portfolio.optim, write below function:

frontier2 <- function(return,minRet,maxRet){
rbase <- seq(minRet,maxRet,length=100)
s <- sapply(rbase,function(x){
p2 <- portfolio.optim(as.matrix(returns),pm = x, shorts = TRUE)

plot(s,rbase,xlab=”Variance”,ylab=”Return”, main=”w/Portfolio.Optim”)}

Draw frontier, it will remain same as what we have got in our last post.

Leave a Reply

Your email address will not be published. Required fields are marked *