Back to Community
Setting sector constraints

I read in the documentation about a group constraint that allows you to specify max/min allocations per sector. However, in the example given (below), it looks like we have to manually label each stock in the universe to its sector. How can we do this label mapping automatically for a large universe? Looks like each stock's sector can be found in "Fundamentals" -- just not sure how to go about the syntax of calling a specific attribute like the sector of a stock.

Map from each asset to its sector.

labels = {AAPL: 'TECH', MSFT: 'TECH', TSLA: 'CC', GM: 'CC'}

Maps from each sector to its min/max exposure.

min_exposures = {'TECH': -0.5, 'CC': -0.25}
max_exposures = {'TECH': 0.5, 'CC': 0.5}

constraint = NetGroupExposure(labels, min_exposures, max_exposures)