Monday, October 20, 2014

Portfolio Optimisation - II

The analysis in the previous post created portfolios that had negative weights, or "short" positions. To overcome we search for options to block short positions and arrived at a couple of other websites that demonstrated portfolio optimization with more complex models. Both the Economist at Large site and the Alphaism site give good inputs on how to address this problem and this leads us to the function portfolio.optim available in the {tseries} that addresses this problem.

In the following program, this portfolio.optim function has been used instead of the custom built function shown in the previous post.

setwd("C:/Users/admin/Desktop/Data Analytics/QuantitativeFinance/QFLabs")
India5 <- read.csv("India5.csv")
assets <- India5[,3:7]
returns <- log(tail(assets, -1) / head(assets, -1))


## Create an optimum portfolio with expected means defined and shorts allowed

w2 <- portfolio.optim(as.matrix(returns),pm = 0.005,shorts = TRUE,riskless= FALSE)

## Create an optimum portfolio with expected means defined and shorts NOT ALLOWED

w2 <- portfolio.optim(as.matrix(returns),shorts = FALSE,riskless = FALSE)

# Create a function to create the frontier using portfolio.optim 

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")


We observe that with Short positions allowed ( shorts=true), the portfolio weights are the same as what was obtained in the previous program ( previous post ), and as expected they sum up to 1

> w2$pw
[1]   4.869750   5.651428   3.375111 -10.711613  -2.184675
> sum(w2$pw)
[1] 1

however when shorts are not allowed ( shorts = false ) a different portfolio is created

> w2$pw
[1] 0.22797760 0.19765858 0.03686214 0.16357332 0.37392835
> sum(w2$pw)
[1] 1
> w2$pm
[1] 0.0003971317

and they sum up to 1 as well.

However, when short positions are not allowed, it is not possible to specify the portfolio returns before hand ( as it was, in the shorts allowed case, where pm = 0.005). With this constraint, the portfolio returns has dropped to 0.000397.

The efficient frontier remains the same as before

The program given in Alphaism uses portfolio.optim and then extends it further.

1 comment:

  1. IEEE Project Domain management in software engineering is distinct from traditional project deveopment in that software projects have a unique lifecycle process that requires multiple rounds of testing, updating, and faculty feedback. A IEEE Domain project Final Year Projects for CSE system development life cycle is essentially a phased project model that defines the organizational constraints of a large-scale systems project. The methods used in a IEEE DOmain Project systems development life cycle strategy Project Centers in India provide clearly defined phases of work to plan, design, test, deploy, and maintain information systems.

    This is enough for me. I want to write software that anyone can use, and virtually everyone who has an internet connected device with a screen can use apps written in JavaScript. JavaScript Training in Chennai JavaScript was used for little more than mouse hover animations and little calculations to make static websites feel more interactive. Let’s assume 90% of all websites using JavaScript use it in a trivial way. That still leaves 150 million substantial JavaScript Training in Chennai JavaScript applications.