Skip to content

Commit

Permalink
Bug fixed: argument
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasBoTang authored May 20, 2024
1 parent bfd55c7 commit b363410
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/pyepo/model/grb/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class portfolioModel(optGrbModel):
"""
This class is optimization model for portfolio problem
This class is an optimization model for portfolio problem
Attributes:
_model (GurobiPy model): Gurobi model
num_assets (int): number of assets
cov (numpy.ndarray): covariance matrix of the returns
covariance (numpy.ndarray): covariance matrix of the returns
risk_level (float): risk level
"""

Expand All @@ -30,13 +30,13 @@ def __init__(self, num_assets, covariance, gamma=2.25):
gamma (float): risk level parameter
"""
self.num_assets = num_assets
self.cov = covariance
self.covariance = covariance
self.risk_level = self._getRiskLevel(gamma)
super().__init__()

def _getRiskLevel(self, gamma):
"""
A method to calculate risk level
A method to calculate the risk level
Returns:
float: risk level
Expand All @@ -59,7 +59,7 @@ def _getModel(self):
m.modelSense = GRB.MAXIMIZE
# constraints
m.addConstr(x.sum() == 1, "budget")
m.addConstr(x.T @ self.cov @ x <= self.risk_level, "risk_limit")
m.addConstr(x.T @ self.covariance @ x <= self.risk_level, "risk_limit")
return m, x


Expand All @@ -70,10 +70,10 @@ def _getModel(self):
# random seed
random.seed(42)
# set random cost for test
cov, _, revenue = genData(num_data=100, num_features=4, num_assets=50, deg=2)
covariance, _, revenue = genData(num_data=100, num_features=4, num_assets=50, deg=2)

# solve model
optmodel = portfolioModel(num_assets=50, covariance=cov) # init model
optmodel = portfolioModel(num_assets=50, covariance=covariance) # init model
optmodel = optmodel.copy()
optmodel.setObj(revenue[0]) # set objective function
sol, obj = optmodel.solve() # solve
Expand Down

0 comments on commit b363410

Please sign in to comment.