Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Select data of specific security from get_pricing() with a list of securities

Hi,

Here is a dumb question. I tried to use x=get_pricing(['AAPL','SPY'],start_date,end_date,frequency='minute') to get some data. When I used x.loc['price,:,'Equity(24 [AAPL]) '] to select price data for AAPL, however, it returns an error, KeyError: 'the label [Equity(24 [AAPl])] is not in the [columns]'. I am wondering what is the right to slice the data. Thanks!

2 responses

The order for indexing the panel returned by the 'get_pricing' method is first, the columns, then second, is the date, and the third parameter is the security.
So the following will return all columns, all dates, for security aapl

# First get an easy reference to the APPL security object  
aapl = symbols('AAPL')  
# Then use that to get all columns and all dates  
data.loc[:, :, aapl]

One can also get just a single price and date something like this

data.loc['price', '2018-06-15', aapl]

Note that the major axis is the date and the minor axis are the securities. So, other helpful methods are:

data.major_xs('2018-6-15')  
data.minor_xs(aapl)

These will return slices for just that date and that security respectively.

Note that the minor axis (the securities) are security objects and not simply strings.

See attached notebook. Good luck.

Thanks a lot...