从cvxpy中的求解方法接收到“无”

问题描述 投票:0回答:1

我正在尝试使用cvxpy软件包优化问题,但未获得任何返回值,而且我不确定自己在做什么错。我正在运行以下代码:

weights = cp.Variable(6)
risk = cp.quad_form(weights,cov)

allocation_objective = cp.Minimize(risk)

allocation_constraints = [
    cp.sum(weights) == 1,
    (e_r.T @ weights)[0] == 0.3
]

weight_bounds = (0,1)
allocation_constraints.extend(
    [
        weights >= weight_bounds[0],
        weights <= min(weight_bounds[1], 1)
    ]
)

problem = cp.Problem(
    objective=allocation_objective, 
    constraints=allocation_constraints
)
problem.solve()

其中cov指资产收益的6x6协方差矩阵。运行此代码时,weights.value等于None,而problem.solve()行返回“ inf”。

我想知道是否有人可以看到问题出在哪里,为什么我的weights.value返回None。

编辑:添加的错误跟踪:

ValueError                                Traceback (most recent call last)
<ipython-input-64-638c59b13788> in <module>
      3 print(mean_returns)
      4 print(6)
----> 5 mvo.plot_efficient_frontier(covariance=cov, expected_asset_returns=mean_returns, num_assets=6)

/anaconda3/lib/python3.7/site-packages/mlfinlab/portfolio_optimization/mean_variance.py in plot_efficient_frontier(self, covariance, expected_asset_returns, num_assets, min_return, max_return, risk_free_rate)
    321                                                    expected_returns=expected_returns,
    322                                                    target_return=portfolio_return,
--> 323                                                    num_assets=num_assets)
    324             volatilities.append(risk)
    325             returns.append(portfolio_return)

/anaconda3/lib/python3.7/site-packages/mlfinlab/portfolio_optimization/mean_variance.py in _min_volatility_for_target_return(self, covariance, expected_returns, target_return, num_assets)
    291         problem.solve()
    292         if weights.value is None:
--> 293             raise ValueError('No optimal set of weights found.')
    294         return weights.value, risk.value ** 0.5, target_return
    295 

ValueError: No optimal set of weights found.
python finance cvxpy convex-optimization
1个回答
0
投票

我没有足够的声誉来发表评论,所以我将其添加为答案。

尝试使用:

    problem.solve(solver=SCS)
© www.soinside.com 2019 - 2024. All rights reserved.