Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Asset weight constraints can be applied to ensure that the portfolio adheres to
## Example

Usage of the library is straightforward. You can create a portfolio object, define your assets, and then use the optimizers to find the optimal asset weights based on your constraints and objectives.
The first step is to create a `Portfolio` object with your assets, their expected returns, and covariances. The last item in the list of assets should be the liability, which is treated differently from the other assets in the optimization process. The optimizaters always set the liability weight to -1 and require the other asset weights to be between 0 and 1 and sum to 1.
The first step is to create a `Portfolio` object with your assets, their expected returns, and covariances. The last item in the list of assets should be the liability, which is treated differently ,from the other assets in the optimization process. The optimizaters always set the liability weight to -1 and require the other asset weights to be between 0 and 1 and sum to 1.

The user can then define additional constraints on the asset weights, such as requiring a minimum or maximum weight for certain assets or limiting the weight of one or more assets to be less than another.

Expand Down
10 changes: 5 additions & 5 deletions docs/Example_US_Asset_Classes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "b5c5d005",
"metadata": {},
"outputs": [],
Expand All @@ -54,7 +54,7 @@
"from penfolioop.optimizers import (\n",
" efficient_frontier,\n",
" max_surplus_return_optimizer,\n",
" max_surplus_sharp_ratio_optimizer,\n",
" max_surplus_sharpe_ratio_optimizer,\n",
" min_surplus_variance_optimizer,\n",
" surplus_mean_variance_optimizer,\n",
")\n",
Expand Down Expand Up @@ -1411,13 +1411,13 @@
"\n",
"- `min_surplus_variance_optimizer`,\n",
"- `max_surplus_return_optimizer`,\n",
"- `max_surplus_sharp_ratio_optimizer`,\n",
"- `max_surplus_sharpe_ratio_optimizer`,\n",
"- `efficient_frontier`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "5b2ddc16",
"metadata": {},
"outputs": [],
Expand All @@ -1431,7 +1431,7 @@
"max_return = portfolio.surplus_return(max_return_weights)\n",
"max_return_vol = portfolio.surplus_variance(max_return_weights)**.5\n",
"\n",
"max_sharpe_weights = max_surplus_sharp_ratio_optimizer(portfolio, asset_constraints=constraints)\n",
"max_sharpe_weights = max_surplus_sharpe_ratio_optimizer(portfolio, asset_constraints=constraints)\n",
"max_sharpe_return = portfolio.surplus_return(max_sharpe_weights)\n",
"max_sharpe_vol = portfolio.surplus_variance(max_sharpe_weights)**.5\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions penfolioop/optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This module provides various objective functions for pension fund portfolio optimization, including:

- `max_surplus_sharp_ratio_optimizer`:
- `max_surplus_sharpe_ratio_optimizer`:

This function Maximizes the surplus portfolio return to surplus portfolio risk.

Expand Down Expand Up @@ -166,7 +166,7 @@ def wrapper(*args, **kwargs): # noqa: ANN002, ANN003, ANN202
return wrapper


def _negative_surplus_sharp_ratio_objective(
def _negative_surplus_sharpe_ratio_objective(
weights: np.ndarray, expected_returns: np.ndarray, covariance_matrix: np.ndarray,
) -> float:
"""Construct an objective function to maximize the Sharpe ratio of the portfolio surplus.
Expand Down Expand Up @@ -195,7 +195,7 @@ def _negative_surplus_sharp_ratio_objective(


@clean_up_weight_decorator
def max_surplus_sharp_ratio_optimizer(
def max_surplus_sharpe_ratio_optimizer(
portfolio: Portfolio, asset_constraints: list[dict[str, Any]] | None = None,
) -> np.ndarray:
r"""Optimize the asset weights to achieve a target excess return over the expected liabilities return.
Expand Down Expand Up @@ -280,7 +280,7 @@ def max_surplus_sharp_ratio_optimizer(

# Solve the optimization problem
result = minimize(
_negative_surplus_sharp_ratio_objective,
_negative_surplus_sharpe_ratio_objective,
initial_weights,
args=(portfolio.expected_returns, portfolio.covariance_matrix),
method="SLSQP",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
min_surplus_variance_optimizer,
surplus_mean_variance_optimizer,
max_surplus_return_optimizer,
max_surplus_sharp_ratio_optimizer,
max_surplus_sharpe_ratio_optimizer,
efficient_frontier
)

Expand Down Expand Up @@ -104,7 +104,7 @@ def generic_weight_requirements(weights: np.ndarray, expected_length: int):
min_surplus_variance_optimizer,
surplus_mean_variance_optimizer,
max_surplus_return_optimizer,
max_surplus_sharp_ratio_optimizer])
max_surplus_sharpe_ratio_optimizer])
def test_optimizer(portfolio, optimizer, asset_constraints1, asset_constraints2, invalid_asset_constraints):

# Test with asset constraints 1
Expand Down
Loading