Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
indilyone opened this issue Apr 3, 2024 · 0 comments
Labels
question Further information is requested

Comments

@indilyone
Copy link

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 indilyone added the question Further information is requested label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant