How to set parameters' sum to 1 in constrained optimization

后端 未结 2 1000
臣服心动
臣服心动 2020-12-30 14:51

Here\'s the code (I\'m sorry if it\'s so long, but it was the first example I had); I\'m using the CVaR example from CreditMetrics package by A. Wittmann and

2条回答
  •  长情又很酷
    2020-12-30 15:13

    I think you should add a penalty for any deviation from one. Add to your minimizing problem the term +(sum(weights) - 1)^2 * 1e10. You should see that this huge penalty will force the weights to sum to 1!

提交回复
热议问题