mirror of
https://github.com/robertmartin8/PyPortfolioOpt.git
synced 2022-11-27 18:02:41 +03:00
added hidden API for opt_method
This commit is contained in:
@@ -107,6 +107,7 @@ class BaseScipyOptimizer(BaseOptimizer):
|
|||||||
- ``bounds`` - float tuple OR (float tuple) list
|
- ``bounds`` - float tuple OR (float tuple) list
|
||||||
- ``initial_guess`` - np.ndarray
|
- ``initial_guess`` - np.ndarray
|
||||||
- ``constraints`` - dict list
|
- ``constraints`` - dict list
|
||||||
|
- ``opt_method`` - the optimisation algorithm to use. Defaults to SLSQP.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, n_assets, tickers=None, weight_bounds=(0, 1)):
|
def __init__(self, n_assets, tickers=None, weight_bounds=(0, 1)):
|
||||||
@@ -121,6 +122,7 @@ class BaseScipyOptimizer(BaseOptimizer):
|
|||||||
# Optimisation parameters
|
# Optimisation parameters
|
||||||
self.initial_guess = np.array([1 / self.n_assets] * self.n_assets)
|
self.initial_guess = np.array([1 / self.n_assets] * self.n_assets)
|
||||||
self.constraints = [{"type": "eq", "fun": lambda x: np.sum(x) - 1}]
|
self.constraints = [{"type": "eq", "fun": lambda x: np.sum(x) - 1}]
|
||||||
|
self.opt_method = "SLSQP"
|
||||||
|
|
||||||
def _make_valid_bounds(self, test_bounds):
|
def _make_valid_bounds(self, test_bounds):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
|
|
||||||
- ``initial_guess`` - np.ndarray
|
- ``initial_guess`` - np.ndarray
|
||||||
- ``constraints`` - dict list
|
- ``constraints`` - dict list
|
||||||
|
- ``opt_method`` - the optimisation algorithm to use. Defaults to SLSQP.
|
||||||
|
|
||||||
- Output: ``weights`` - np.ndarray
|
- Output: ``weights`` - np.ndarray
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
objective_functions.negative_sharpe,
|
objective_functions.negative_sharpe,
|
||||||
x0=self.initial_guess,
|
x0=self.initial_guess,
|
||||||
args=args,
|
args=args,
|
||||||
method="SLSQP",
|
method=self.opt_method,
|
||||||
bounds=self.bounds,
|
bounds=self.bounds,
|
||||||
constraints=self.constraints,
|
constraints=self.constraints,
|
||||||
)
|
)
|
||||||
@@ -129,7 +130,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
objective_functions.volatility,
|
objective_functions.volatility,
|
||||||
x0=self.initial_guess,
|
x0=self.initial_guess,
|
||||||
args=args,
|
args=args,
|
||||||
method="SLSQP",
|
method=self.opt_method,
|
||||||
bounds=self.bounds,
|
bounds=self.bounds,
|
||||||
constraints=self.constraints,
|
constraints=self.constraints,
|
||||||
)
|
)
|
||||||
@@ -176,7 +177,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
objective_function,
|
objective_function,
|
||||||
x0=self.initial_guess,
|
x0=self.initial_guess,
|
||||||
args=args,
|
args=args,
|
||||||
method="SLSQP",
|
method=self.opt_method,
|
||||||
bounds=self.bounds,
|
bounds=self.bounds,
|
||||||
constraints=self.constraints,
|
constraints=self.constraints,
|
||||||
)
|
)
|
||||||
@@ -235,7 +236,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
objective_functions.negative_sharpe,
|
objective_functions.negative_sharpe,
|
||||||
x0=self.initial_guess,
|
x0=self.initial_guess,
|
||||||
args=args,
|
args=args,
|
||||||
method="SLSQP",
|
method=self.opt_method,
|
||||||
bounds=self.bounds,
|
bounds=self.bounds,
|
||||||
constraints=constraints,
|
constraints=constraints,
|
||||||
)
|
)
|
||||||
@@ -294,7 +295,7 @@ class EfficientFrontier(base_optimizer.BaseScipyOptimizer):
|
|||||||
objective_functions.volatility,
|
objective_functions.volatility,
|
||||||
x0=self.initial_guess,
|
x0=self.initial_guess,
|
||||||
args=args,
|
args=args,
|
||||||
method="SLSQP",
|
method=self.opt_method,
|
||||||
bounds=self.bounds,
|
bounds=self.bounds,
|
||||||
constraints=constraints,
|
constraints=constraints,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user