From 9ae659cad683dd732e27e4ff156c81012760c110 Mon Sep 17 00:00:00 2001 From: mjvakili Date: Fri, 29 Aug 2025 13:46:51 +0200 Subject: [PATCH 1/2] fixed sharpe ratio typo --- docs/Example_US_Asset_Classes.ipynb | 10 +++++----- penfolioop/optimizers.py | 8 ++++---- tests/test_optimizers.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/Example_US_Asset_Classes.ipynb b/docs/Example_US_Asset_Classes.ipynb index e4ff667..bd9f239 100644 --- a/docs/Example_US_Asset_Classes.ipynb +++ b/docs/Example_US_Asset_Classes.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "b5c5d005", "metadata": {}, "outputs": [], @@ -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", @@ -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": [], @@ -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", diff --git a/penfolioop/optimizers.py b/penfolioop/optimizers.py index 1ce5d74..e661a61 100644 --- a/penfolioop/optimizers.py +++ b/penfolioop/optimizers.py @@ -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. @@ -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. @@ -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. @@ -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", diff --git a/tests/test_optimizers.py b/tests/test_optimizers.py index a2e7b77..b93bdce 100644 --- a/tests/test_optimizers.py +++ b/tests/test_optimizers.py @@ -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 ) @@ -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 From fc9feb061a279e3aebe75d280e8889f6a209a03d Mon Sep 17 00:00:00 2001 From: mjvakili Date: Fri, 29 Aug 2025 13:47:40 +0200 Subject: [PATCH 2/2] fixed sharpe ratio typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc2e8f8..033a3d2 100644 --- a/README.md +++ b/README.md @@ -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.