问题描述
- 权重之和等于 1
- 每个权重的界限是 (0.05,0.3)
- 最后一个对我来说很困难的是:所有的权重都应该是 5% 的倍数
我制作了这段代码,但它给了我最初的解决方案“init_guess”:
def minimize_vol(target_return,er,covmat):
n = er.shape[0]
init_guess = np.repeat(1/n,n)
#init_guess = np.array([0.3,0.25,0.1,0.2,0.15])
bounds = ((0.05,0.3),)*n
return_is_target = {
'type' : 'eq','args' : (er,),'fun' : lambda weights,er : target_return - portfolio_return(weights,er)
}
weights_sum_to_1 = {
'type' : 'eq','fun' : lambda weights : np.sum(weights)-1
}
multiplicity = {
'type' : 'eq','fun' : lambda weights : (weights*100)%5
}
results = minimize(portfolio_vol,init_guess,args = (covmat,method = "SLSQP",options= {'disp' : False},constraints = (return_is_target,weights_sum_to_1,multiplicity),bounds = bounds
)
return results.x
感谢您的回答
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)