I am not clear with data in handle_data(context, data), what information data have?
Below is an example, in sample Fundamental Data Algorithm. Full code: https://www.quantopian.com/help#sample-fundamentals
Here context.fundamental_df are securities we want to buy. And before that we want to clear our position. The argument "data" is same as "data" in handle_data.
def rebalance(context, data):
# Exit all positions before starting new ones
for stock in context.portfolio.positions:
if stock not in context.fundamental_df and stock in data:
order_target_percent(stock, 0)
... ...
My question is in this line: if stock not in context.fundamental_df and stock in data:
Since if stock is in position, then it must also have been in our universe, then it is in data. So why we need to judge whether stock in data?
Thank you for your help!