Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Checking for KeyError: Equity

Hi everyone. Total newb here. Getting this:

KeyError: Equity(19917, symbol=u'PCLN', asset_name=u'PRICELINE GROUP
INC/THE', exchange=u'NASDAQ GLOBAL SELECT MARKET',
start_date=Timestamp('1999-03-30 00:00:00+0000', tz='UTC'),
end_date=Timestamp('2016-03-11 00:00:00+0000', tz='UTC'),
first_traded=None, auto_close_date=Timestamp('2016-03-16
00:00:00+0000', tz='UTC')) There was a runtime error on line 153.

Code is

if security in context.portfolio.positions:  
                log.info("Selling %s " % security)  
                order_target_percent(security, 0)  

I understand this can happen if there's no quote or something for this day. How would I get it to just ignore and continue?

-Dan

2 responses
if security in data:  

Should work to check if the security exists for the current (prev?) bar.

Thanks, that did it.