How to put mathematical constraints using the GenSA function in R

I'm currently trying to use the GenSA Simulated Annealing package to minimize the function below:

efficientFunction <- function(v) {
  t(v)  %*% Cov_Mat   %*%  v
 }

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

I am trying to solve the Markowitz asset allocation approach this way, and I would like to know how I could introduce a mathematical constraint, such as the sum of all the coefficients should be 1:

sum(v) = 1

Also, since I intend to rely on the GenSA function, I would like to use something like this with a restriction:

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)

: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.97.6091&rep=rep1&type=pdf Simulated Annealing Algorithm, , R.

. , SO, , , .

+3
2

(. http://en.wikipedia.org/wiki/Lagrange_multiplier). ,

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

efficientFunction lambda * abs( sum(v) - 1 ). lambda , .

+4

, , . , , .

efficientFunction <- function(v) {
    v <- v/sum(v)
    t(v) %*% Cov_Mat %*%  v
}

v, 1. , ,

out <- GenSA(v, lower = lower, upper = upper, fn = efficientFunction)
out$par/sum(out$par)
+1

Source: https://habr.com/ru/post/1653551/


All Articles