Skip to content

Commit

Permalink
Merge pull request #2 from tamilselvanarjun/tamil/optimizationstatus
Browse files Browse the repository at this point in the history
updated the code to check the optimization status
  • Loading branch information
tamilselvanarjun authored Mar 17, 2024
2 parents a7c9663 + 484c7c2 commit 6bc7846
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions build/lib/finmodels/portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# financial_models/portfolio_optimization.py
import numpy as np
import cvxpy as cp

Expand All @@ -11,7 +10,7 @@ def optimize_portfolio(expected_returns, covariance_matrix):
- covariance_matrix: Covariance matrix of asset returns
Returns:
- Optimal portfolio weights
- Optimal portfolio weights if successful, None otherwise
"""
num_assets = len(expected_returns)

Expand All @@ -30,4 +29,8 @@ def optimize_portfolio(expected_returns, covariance_matrix):
problem = cp.Problem(objective, constraints)
problem.solve()

return weights.value
if problem.status == 'optimal':
return weights.value
else:
print("Optimization problem could not be solved.")
return None
Binary file removed dist/finmodels-2.0.0-py3-none-any.whl
Binary file not shown.
Binary file removed dist/finmodels-2.0.0.tar.gz
Binary file not shown.
Binary file added dist/finmodels-2.0.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/finmodels-2.0.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion finmodels.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: finmodels
Version: 2.0.0
Version: 2.0.1
Summary: finmodels is a Python package that provides various financial models for analysis and optimization.
Home-page: https://github.com/arjunlimat/finmodels
Author: Tamilselvan_Arjunan
Expand Down
9 changes: 6 additions & 3 deletions finmodels/portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# financial_models/portfolio_optimization.py
import numpy as np
import cvxpy as cp

Expand All @@ -11,7 +10,7 @@ def optimize_portfolio(expected_returns, covariance_matrix):
- covariance_matrix: Covariance matrix of asset returns
Returns:
- Optimal portfolio weights
- Optimal portfolio weights if successful, None otherwise
"""
num_assets = len(expected_returns)

Expand All @@ -30,4 +29,8 @@ def optimize_portfolio(expected_returns, covariance_matrix):
problem = cp.Problem(objective, constraints)
problem.solve()

return weights.value
if problem.status == 'optimal':
return weights.value
else:
print("Optimization problem could not be solved.")
return None
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='finmodels',
version='2.0.0',
version='2.0.1',
packages=find_packages(),
install_requires=[
'numpy',
Expand Down

0 comments on commit 6bc7846

Please sign in to comment.