Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Add price action to Zacks Earnings Surprise pipeline

I'm trying to extend the sample notebook for Zacks Earning Surprise by adding the Open and Close prices following the earning announcement.
The original pipeline (code snippet below) seems to output fine ..

pipe = Pipeline(  
    columns={  
        'EPS mean estimate': EarningsSurprises.eps_mean_est.latest,  
        'asof_date': EarningsSurprises.asof_date.latest,  
        'Zacks adj': EarningsSurprises.eps_act_zacks_adj.latest,  
        'eps_act': EarningsSurprises.eps_act.latest,  
        'act_rpt_code': EarningsSurprises.act_rpt_code.latest,  
        'eps_cnt_est': EarningsSurprises.eps_cnt_est.latest  
    },  
    screen=(top_1000_most_liquid & EarningsSurprises.eps_mean_est.latest.notnan()) # & EarningsSurprises.eps_cnt_est.latest>2.0  
)

.. However, I added these columns to the pipe code after, as shown in code below, but it doesn't seem to display the columns i added.

pea_date = EarningsSurprises.asof_date.latest.timedelta(days=1) if (EarningsSurprises.act_rpt_code.latest=='AMC')  else EarningsSurprises.asof_date.latest

from quantopian.pipeline.data.builtin import USEquityPricing  
pea_close = USEquityPricing.close[pea_date]  
pea_open = USEquityPricing.open[pea_date]

pipe.add(pea_date, 'pea_date')  
pipe.add(pea_close, 'pea_close')  
pipe.add(pea_open, 'pea_open')  

.. However, it doesn't print these added columns to the output.

# run_pipeline will show the output of your pipeline  
pipe_output = run_pipeline(pipe, start_date='2016-03-01', end_date='2016-03-02')  
pipe_output  

I'm a newbie to Python Pandas - please advise how to correct my code, so as to include these fields.

3 responses

Hi Kiran, unfortunately specifying a specific date for a BoundColumn like doing USEquityPricing.close[pea_date] isn't supported. Currently there isn't a good way to get the value of a BoundColumn on a specified date.

If you're just looking to do some analysis in Research you could try just having the Pipeline output as it is, and then add additional columns with the open and close price you can get from get_pricing (docs link) for that specific date.

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.

Thanks, still having 2 issues
1) I tried appending this post-earning-announcement date column to the pipeline, but the pipeline output doesn't show this column. Is there something wrong in my logic or command?

pea_date = EarningsSurprises.asof_date.latest.timedelta(days=1) if (EarningsSurprises.act_rpt_code.latest=='AMC')  else EarningsSurprises.asof_date.latest  

2) How do i get the Close and Open price for a specific Symbol AND pea_date in the pipeline and append as columns to the pipeline?
symbol pea_date close previous_day_close open
e.g. AAPL 01-06-2014 "AAPL_close" "AAPL_close_previous_day" "AAPL_open"
GOOG 02-03-2014 "GOOG_close" "GOOG_close_previous_day" "GOOG_open"
...
Couldn't figure out the pandas query to do so - i got nowhere with this one below ..
pea_close = get_pricing(pipe[index], pipe[pea_date],'daily', 'close_price')

Hi Kiran,

For 1), remember that factors don't actually have numerical values, they're simply the definition of a computation. The numbers get populated when you call run_pipeline. You'll need to use timedeltaon the relevant column of your DataFrame resulting from run_pipeline. I'd recommend taking a look at the Pipeline Tutorial for a better explanation.

For 2), you'll want to create 2 additional factors: a previous_day_close factor and a previous_day_open factor. Lesson 3 of the Pipeline Tutorial has an example of how to make a factor for the previous day's close price. Check it out!

Let me know if this helps.

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.