mirror of
https://github.com/robertmartin8/PyPortfolioOpt.git
synced 2022-11-27 18:02:41 +03:00
Hidden API for changing solver
This commit is contained in:
@@ -113,6 +113,7 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
- ``n_assets`` - int
|
||||
- ``tickers`` - str list
|
||||
- ``weights`` - np.ndarray
|
||||
- ``solver`` - str
|
||||
|
||||
Public methods:
|
||||
|
||||
@@ -144,6 +145,8 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
self._upper_bounds = None
|
||||
self._map_bounds_to_constraints(weight_bounds)
|
||||
|
||||
self.solver = None
|
||||
|
||||
def _map_bounds_to_constraints(self, test_bounds):
|
||||
"""
|
||||
Process input bounds into a form acceptable by cvxpy and add to the constraints list.
|
||||
@@ -193,7 +196,11 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
"""
|
||||
try:
|
||||
opt = cp.Problem(cp.Minimize(self._objective), self._constraints)
|
||||
opt.solve()
|
||||
|
||||
if self.solver is not None:
|
||||
opt.solve(solver=self.solver, verbose=True)
|
||||
else:
|
||||
opt.solve()
|
||||
except (TypeError, cp.DCPError):
|
||||
raise exceptions.OptimizationError
|
||||
if opt.status != "optimal":
|
||||
|
||||
Reference in New Issue
Block a user