PyPortfolioOpt icon indicating copy to clipboard operation
PyPortfolioOpt copied to clipboard

OptimizationError: Please check your objectives/constraints or use a different solver.

Open indilyone opened this issue 1 year ago • 0 comments

What are you trying to do? Clear description of the problem you are trying to solve with PyPortfolioOpt

What have you tried?

What data are you using? What asset class, how many assets, how many data points. Preferably provide a sample of the dataset as a csv attachment.

In this excel, the returns are in sheet "sheet1" and covariance matrix is in sheet "cov".

I am trying to do a basic mean variance optimization using ef.min_volatility() but errors

OptimizationError: Please check your objectives/constraints or use a different solver.

I also tried using non-convex optimization in the cookbook example, but the result ended up being the 1/n weights.

target_risk = 0.05 ef = EfficientFrontier(mu, S, weight_bounds=(0, 0.5))

Weights sum to zero

weight_constr = {"type": "eq", "fun": lambda w: np.sum(w)-1}

Portfolio vol less than target vol

risk_constr = { "type": "eq", "fun": lambda w: target_risk ** 2 - np.dot(w.T, np.dot(ef.cov_matrix, w)), } constraints = [weight_constr, risk_constr]

ef.nonconvex_objective( lambda w, mu: -w.T.dot(mu), # min negative return i.e max return objective_args=(ef.expected_returns,), weights_sum_to_one=True, constraints=constraints,

)

weights = ef.clean_weights() weights

COV.xlsx

indilyone avatar Apr 03 '24 09:04 indilyone