Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
get event data as pandas dataframe?

Might it be built in to Quantopian that the event data can be easily returned as a pandas dataframe (as they are by the history API)? As an example, for a single minute, I'd like for closing prices:

                         XYZ    PDQ  
2013-09-05 20:59:00     17.0    47.2  

And the same for OHLV.

Is there a straightforward way to do this, or would I have to cobble together the dataframes myself?

Grant

3 responses

Hi Grant,

Try using this notation:

data_df = pd.Dataframe(index=prices.columns, columns=['high', 'low', 'close_price', 'open_price', 'volume'])  
data_df.ix['price', :] = prices.ix[-1, :]  
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hello Alisa,

I don't understand. For example, if I plunk your code into an algo, it doesn't work:

import pandas as pd

def initialize(context):  
    context.stocks = [sid(8554),sid(19920),sid(33652)]

def handle_data(context, data):  
    data_df = pd.Dataframe(index=prices.columns, columns=['high', 'low', 'close_price', 'open_price', 'volume'])  
    data_df.ix['price', :] = prices.ix[-1, :]  

Basically, I'm looking for a helper function that would give me all of the current event data (OHLCV, timestamp) for all securities (or a specified subset) in a pandas dataframe (or datapanel). The batch transform does this, as I understand, but my understanding is that it will be deprecated. Is there an alternative?

Grant

Ah, I see now that you're trying to replicate the same structure as batch transform. It is currently not possible to use history to create a dataframe of the event data for securities. I agree it would be useful to call data.ix['high,:] and reference that in your code. Unfortunately there is no straightforward way to do this, but its a good feature suggestion and I'll add it to our list.