Hidden API for changing solver

This commit is contained in:
robertmartin8
2020-06-07 13:22:16 +08:00
parent 481b43b546
commit 8d991da378
4 changed files with 41 additions and 5 deletions

View File

@@ -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":