Я пытаюсь решить эту проблему оптимизации в R:
Чтобы было ясно, вектор — это переменная, которую нужно оптимизировать. а матрица постоянна
Я не знаю, как изменить проблему, чтобы использовать один решатель R, все мои попытки были неудачными...
Это следует из этой статьи о количественных финансах:
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2673124
Спасибо за помощь,
Артур
Это то, что я пробовал, используя R и пакет nloptr.
#Compute the covariance matrix with asset returns
Cov<-cov(Asset)
#fonction to optimize
D <- function(P) {
-sum(log(abs(P)))
}
#gradient of the objective function
D_g <- function(P) {
-1/P
}
#inequality function with the Jacobian
ineq <- function(P) {
cont<-rep(0,length(P))
for(i in 1: length(P)){
cont[i]<-sum(P[-i]*Cov[i,-i])
}
return(list(
"constraints" = sqrt(t(P) %*% Cov %*% P) - target,
"jacobian" = (P * diag(Cov)+cont) / sqrt(t(P) %*% Cov %*% P)
))
}
# Optimisation under constraints
# Poids is the initial weight: 1/vol
# D is the function to optimize
# D_g is the gradient of this function
# ineq is a function with constraint and jacobian of it
Poids=Pos*1/sqrt(diag(Cov))/sum(1/sqrt(diag(Cov)))
par0 <-
nloptr(
Poids,
D,
eval_grad_f = D_g,
lb = NULL,
ub = NULL,
eval_g_ineq = ineq,
opts = list("algorithm" = "NLOPT_LD_LBFGS",
"xtol_rel" = 1.0e-8)
)
NLOPT_LD_LBFGS
не может использовать ограничения (это классический неограниченный решатель, поддерживающий только границы), что, очевидно, было бы проблемой здесь! - person sascha   schedule 27.10.2017