Back to Community
Exit Position Day Before Earnings Report

I'm trying to create a function to exit all positions held on the day before the stock's next earnings report is released. It looks like I should be able to use the data provided from EventVestor. The built-in BusinessDaysUntilNextEarnings pipeline factor will be equal to 1 when this is the case.

Can you use this factor outside of a pipeline?
- If so, how could I get this factor for the current stocks held. Say this is in a list called "context.current_stocks".
- If not, is there another way to do this? I've looked into adding these factors as output from my pipeline, but apparently you cannot incorporate your current positions in your pipeline (see post).


3 responses

Hi Aaron,

Here is how I do it.

from import EarningsCalendar  
from quantopian.pipeline.factors.eventvestor import (  

def make_pipeline():  
    minprice = USEquityPricing.close.latest > 5  
    not_announced_acq_target = ~IsAnnouncedAcqTarget()  
    pipe = Pipeline(screen=Q1500US() & minprice & not_announced_acq_target)  
    sectors = Sector()  
    pipe.add(sectors, 'sector')  
    pipe.add(BusinessDaysUntilNextEarnings(), 'NE')  
    return pipe

def before_trading_start(context, data):  
    context.screener = pipeline_output("Q1500")  
    context.screener = context.screener[context.screener['NE'] < 2].index

def myfunction(context, data):  
    for sid in context.portfolio.positions:  
        if sid in context.screener:  
            order_target(sid, 0)  

I think Q has an internal earnings calendar which wass mentioned about some time back. Eventvestor free portion is only available for a limited time. Using the internal API we might be able to use this for more recent time periods.

Thanks for the suggestions, Aqua Rooster and Suminda. I'll report back how it goes. It will be a day or two before I get back to it.