Skip to content

Commit

Permalink
Merge pull request #531 from andyherfer/master
Browse files Browse the repository at this point in the history
fixed key error when adding multiple sector constraints
  • Loading branch information
88d52bdba0366127fffca9dfa93895 committed Apr 30, 2023
2 parents 6f699fd + 3feb53a commit c687392
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pypfopt/base_optimizer.py
Expand Up @@ -397,10 +397,10 @@ def add_sector_constraints(self, sector_mapper, sector_lower, sector_upper):
"Sector constraints may not produce reasonable results if shorts are allowed."
)
for sector in sector_upper:
is_sector = [sector_mapper[t] == sector for t in self.tickers]
is_sector = [sector_mapper.get(t) == sector for t in self.tickers]
self.add_constraint(lambda w: cp.sum(w[is_sector]) <= sector_upper[sector])
for sector in sector_lower:
is_sector = [sector_mapper[t] == sector for t in self.tickers]
is_sector = [sector_mapper.get(t) == sector for t in self.tickers]
self.add_constraint(lambda w: cp.sum(w[is_sector]) >= sector_lower[sector])

def convex_objective(self, custom_objective, weights_sum_to_one=True, **kwargs):
Expand Down

0 comments on commit c687392

Please sign in to comment.