Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Iterating over the assets in `data` is deprecated.

Hi,
how can I loop through the stocks in a proper way? The documentation for Quantopian 2 didn't clarify it for me. I am using the following code:

def handle_data(context, data):  
    for stock in data:  
        print stock, data.current(stock, 'price')  

But I am still getting this warning:

C:\Program Files\Miniconda2\lib\site-packages\ipykernel_main_.py:15: ZiplineDeprecationWarning: Iterating over the assets in data is deprecated

2 responses

You don't need stock,

def handle_data(context, data):
for stock in data:
price=data.current(stock, 'price')
print(price)

Don't iterate through data though, That's the old way. You got to use pipeline