ArtMgn - 1 year ago 88

R Question

I am currently trying to use Simulated Annealing package GenSA in order to minimize the function below :

`efficientFunction <- function(v) {`

t(v) %*% Cov_Mat %*% v

}

Where Cov_Mat is a covariance matrix obtained from 4 assets and v is a weight vector of dimension 4.

I'm trying to solve the Markowitz asset allocation approach this way and I would like to know how I could introduce mathematical constraint such as the sum of all coefficients have to equal 1 :

`sum(v) = 1`

Moreover since I intend to rely on the GenSA function, I would like to use something like this with the constraint :

`v <- c(0.25, 0.25, 0.25, 0.25)`

dimension <- 4

lower <- rep(0, dimension)

upper <- rep(1, dimension)

out <- GenSA(v, lower = lower, upper = upper, fn = efficientFunction)

I have found in this paper : http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.97.6091&rep=rep1&type=pdf

how to handle such constraint within the Simulated Annealing Algorithm but I don't know how I could implement it in R.

I'd be very grateful for any advice. It is my first time using SO so don't hesitate to tell me if I have the wrong approach in the way I ask question.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

A possible approach would be to make use of so-called Lagrange multipliers (cf., http://en.wikipedia.org/wiki/Lagrange_multiplier). For example, set

```
efficientFunction <- function(v) {
lambda <- 100
t(v) %*% Cov_Mat %*% v + lambda * abs( sum(v) - 1 )
}
```

, so that in order to minimize the objective function `efficientFunction`

the resulting parameter also minimize the penalty term `lambda * abs( sum(v) - 1 )`

. The Lagrange multiplier `lambda`

is set to an arbitrary but sufficiently high level.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**