How do you avoid the expired assets from optimization universe error?
How do you avoid the expired assets from optimization universe error?
2019-02-04 6:31 WARN Dropping expired assets from optimization universe:
['Equity(51455 [SEND])', 'Equity(41579 [P])', 'Equity(50537 [WRD])', 'Equity(7866 [ESND])']
Were these in the QTradableStocksUS portfolio one day and then dropped out of it?
How can optimize be told to liquefy any no longer in QTU to pass the constraint?
I've tried dropping the expired assets manually using this function:
def drop_ejected_stocks(context):
"""
Drop from context.expected_returns the stocks that
aren't anymore in the QTradableStocksUS universe
"""
expected_returns_stocks = context.expected_returns.index
data_pipe_stocks = context.data_pipe.index
# positions that are in expected_returns_stocks but not data_pipe_stocks
# and therefore must be closed
ejected_stocks = np.setdiff1d(expected_returns_stocks, data_pipe_stocks)
if len(ejected_stocks) > 0:
log.debug("Drop from context.expected_returns these stocks: %s" % ejected_stocks)
context.expected_returns[ejected_stocks] = 0.0
The function is scheduled to be executed daily und expected_returns
is the series that I pass to MaximizeAlpha (I rebalance montly) and data_pipe is DataFrame representing the current univese (it's daily).
Unfortunately the warning still occurs. The QTradableStocksUS is changes really often.