Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Basic question about get_pricing()

Greetings!

I apologize that this is a basic question but for the life of me, I can't make get_pricing() do what I want in the Research environment. I want to return two columns, "price" and "volume," in the resultant data table. I've tried:

import pandas as pd  
import quantopian.research as qr

ts_start = pd.Timestamp('2018-12-27 09:30:00-05:00')  
ts_end = pd.Timestamp('2018-12-27 10:31:00-05:00')

pricing0 = qr.get_pricing(['AMD'], start_date=ts_start, end_date=ts_end, frequency='minute',  
                       fields=['price', 'volume'])  
pricing0.head(60)  

But I get the below error message. I've also tried: fields='price, volume' but that didn't work either.
I've been using the API guide as reference. Also, the API says that "fields" is optional but I've found that when I omit it, I get the same error message.

Note, when I pass "price" or "volume" individually, that works.

Can someone please help? Thank you!

Error message:
NotImplementedErrorTraceback (most recent call last)
in ()
19 fields=['price', 'volume'])
20
---> 21 pricing0.head(60)
22

/usr/local/lib/python2.7/dist-packages/pandas/core/panel.pyc in head(self, n) 626
627 def head(self, n=5):
--> 628 raise NotImplementedError
629
630 def tail(self, n=5):

NotImplementedError:

2 responses

A couple of things...

When using get_pricing with multiple assets and multiple fields the result will be a pandas panel. Panels don't have a 'head' method. That's the error you are getting. Even though you only have a single asset (AMD) the brackets around the symbol make the method behave as if there is a list of multiple symbols. Remove the brackets around AMD and it should work.

However, another 'fix' is to use the to_frame method which turns a panel into a dataframe. So the following would work too.

pricing_df = pricing0.to_frame()  
pricing_df

see attached notebook. Good luck.

Thanks, Dan! This makes sense. Thanks so much for helping! Happy New Year and best wishes for 2019! If you're an active trader, I hope the new year proves bountiful! : )