I am doing the following in my algorithm and following all guidelines but it still fails the criteria. Why?
def make_pipeline():
minprice = USEquityPricing.close.latest > 10
pipe = Pipeline(screen=QTradableStocksUS() & minprice)
sectors = Sector()
pipe.add(sectors, 'sector')
return pipe
def trade_sectors(context, data):
todays_universe = context.stocks
alphas = pd.Series(context.alphas, index=todays_universe)
alphas = alphas.fillna(0.)
objective = opt.MaximizeAlpha(alphas)
constraints = []
constraints.append(opt.MaxGrossExposure(1.0))
constraints.append(opt.DollarNeutral(0.01))
constraints.append(opt.NetGroupExposure(context.labels, context.minw, context.maxw))
constraint_sector_style_risk = opt.experimental.RiskModelExposure(
context.risk_loading_pipeline,
version=opt.Newest,
)
constraints.append(constraint_sector_style_risk)
constraints.append(
opt.PositionConcentration.with_equal_bounds(
min=-1. / (context.label * 5),
max=1. / (context.label * 5)))
constraints.append(opt.MaxTurnover(0.6))
try:
algo.order_optimal_portfolio(objective=objective, constraints=constraints)
record(e=0)
except:
record(e=1)
It fails on the following:
Checking leverage limits...
FAIL: Minimum leverage of 0.63x is below 0.7x
Checking style exposure limits...
FAIL: 98th percentile short_term_reversal exposure of 0.525 (absolute value) is greater than 0.40.
Checking investment in tradable universe...
FAIL: Investment in QTradableStocksUS (2nd percentile) of 92.42% is < 95.0%.