mirror of
https://github.com/robertmartin8/PyPortfolioOpt.git
synced 2022-11-27 18:02:41 +03:00
misc refactors
This commit is contained in:
@@ -6,7 +6,8 @@ from .black_litterman import (
|
||||
from .cla import CLA
|
||||
from .discrete_allocation import get_latest_prices, DiscreteAllocation
|
||||
from .efficient_frontier import EfficientFrontier
|
||||
from .hierarchical_risk_parity import HRPOpt
|
||||
from .hierarchical_portfolios import HRPOpt
|
||||
from .risk_models import CovarianceShrinkage
|
||||
|
||||
__all__ = [
|
||||
"market_implied_prior_returns",
|
||||
@@ -17,4 +18,5 @@ __all__ = [
|
||||
"DiscreteAllocation",
|
||||
"EfficientFrontier",
|
||||
"HRPOpt",
|
||||
"CovarianceShrinkage",
|
||||
]
|
||||
|
||||
@@ -205,7 +205,7 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
Add a new term into the objective function. This term must be convex,
|
||||
and built from cvxpy atomic functions.
|
||||
|
||||
Example:
|
||||
Example::
|
||||
|
||||
def L1_norm(w, k=1):
|
||||
return k * cp.norm(w, 1)
|
||||
@@ -222,7 +222,7 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
Add a new constraint to the optimisation problem. This constraint must be linear and
|
||||
must be either an equality or simple inequality.
|
||||
|
||||
Examples:
|
||||
Examples::
|
||||
|
||||
ef.add_constraint(lambda x : x[0] == 0.02)
|
||||
ef.add_constraint(lambda x : x >= 0.01)
|
||||
@@ -242,7 +242,7 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
def convex_objective(self, custom_objective, weights_sum_to_one=True, **kwargs):
|
||||
"""
|
||||
Optimise a custom convex objective function. Constraints should be added with
|
||||
``ef.add_constraint()``. Optimiser arguments *must* be passed as keyword-args. Example:
|
||||
``ef.add_constraint()``. Optimiser arguments *must* be passed as keyword-args. Example::
|
||||
|
||||
# Could define as a lambda function instead
|
||||
def logarithmic_barrier(w, cov_matrix, k=0.1):
|
||||
@@ -283,7 +283,7 @@ class BaseConvexOptimizer(BaseOptimizer):
|
||||
"""
|
||||
Optimise some objective function using the scipy backend. This can
|
||||
support nonconvex objectives and nonlinear constraints, but often gets stuck
|
||||
at local minima. This method is not recommended – caveat emptor. Example:
|
||||
at local minima. This method is not recommended – caveat emptor. Example::
|
||||
|
||||
# Market-neutral efficient risk
|
||||
constraints = [
|
||||
|
||||
@@ -87,7 +87,7 @@ class BlackLittermanModel(base_optimizer.BaseOptimizer):
|
||||
|
||||
- Inputs:
|
||||
|
||||
- ``cov_matrix`` - pd.DataFrame
|
||||
- ``cov_matrix`` - np.ndarray
|
||||
- ``n_assets`` - int
|
||||
- ``tickers`` - str list
|
||||
- ``Q`` - np.ndarray
|
||||
@@ -341,9 +341,9 @@ class BlackLittermanModel(base_optimizer.BaseOptimizer):
|
||||
if self.posterior_cov is None:
|
||||
self.posterior_cov = self.bl_cov()
|
||||
return base_optimizer.portfolio_performance(
|
||||
self.weights,
|
||||
self.posterior_rets,
|
||||
self.posterior_cov,
|
||||
self.weights,
|
||||
verbose,
|
||||
risk_free_rate,
|
||||
)
|
||||
|
||||
@@ -21,8 +21,8 @@ class CLA(base_optimizer.BaseOptimizer):
|
||||
- ``n_assets`` - int
|
||||
- ``tickers`` - str list
|
||||
- ``mean`` - np.ndarray
|
||||
- ``cov_matrix`` - pd.DataFrame
|
||||
- ``expected_returns`` - pd.Series
|
||||
- ``cov_matrix`` - np.ndarray
|
||||
- ``expected_returns`` - np.ndarray
|
||||
- ``lb`` - np.ndarray
|
||||
- ``ub`` - np.ndarray
|
||||
|
||||
@@ -447,9 +447,9 @@ class CLA(base_optimizer.BaseOptimizer):
|
||||
:rtype: (float, float, float)
|
||||
"""
|
||||
return base_optimizer.portfolio_performance(
|
||||
self.weights,
|
||||
self.expected_returns,
|
||||
self.cov_matrix,
|
||||
self.weights,
|
||||
verbose,
|
||||
risk_free_rate,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user