Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline Help

Hi everyone,
I am new to qunatopian, I have been trying to use pipeline for getting stocks that have highest difference in price between (today open) and (yesterday close). Unfortunately i am keep getting following error "TypeError: zipline.pipeline.pipeline.add() expected a value of type zipline.pipeline.term.Term for argument 'term', but got abc.ABCMeta instead."

Below is my script:

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline.factors import CustomFactor

def initialize(context):  
    pipe = Pipeline()  
    pipe = attach_pipeline(pipe, name='my_pipeline')  
    gap = top_gainers  
    pipe.add(gap, 'gap')  
    schedule_function(rebalance, date_rule=date_rules.every_day(),time_rule=time_rules.market_open())  
class top_gainers(CustomFactor):  
    inputs = [USEquityPricing.open,USEquityPricing.close]  
    window_length = 2  
    def compute(self, today, assets, out, open, close):  
        out[:] = open[-1,:] - close[0,:]  
        return top_gainers()

def rebalance(context, data):  
    results = pipeline_output('my_pipeline')  
    print results.head(5)  

Any help will be useful,
thank you very much in advance =)

8 responses

I would also like to know that, thanks.

I occur this problem too.
USEquityPricing.open might has some problems.
I want to know this answer too.

Thank you.

@Has: Try changing gap = top_gainers to gap = top_gainers(). Remember that you top_gainers needs to be instantiated before it can be added to the pipeline.

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.

@Jamie: Wow thanks, that was very easy to fit=)

If I want to know a difference between close and 2 hours after market open is there any way to do it? I tried to change:

inputs = [USEquityPricing.open,USEquityPricing.close] to inputs = [USEquityPricing.market_open(hours=2),USEquityPricing.close]

which did not work. Would you have any suggestion which direction to go? Thank you very much

I should have included in my last answer that the factor that Has shared is not comparing today's open to yesterday's close. Pipeline only ever uses data up to the close of yesterday. The most recent open value is the open price from the previous day. Pipeline is run before the market opens each day, so there's no way it can know about the open price for the current day. It's on our list to add this feature, but currently it's not possible to do in pipeline. Even if pipeline_output is called outside of before_trading_start, the pipeline is run before the market opens. pipeline_output simply gets the output of pipeline, it doesn't control when it is run.

@Martin: you can see a list of usable data columns here.

Thank you, Jamie

@Jamie: I wanted originally use this script to get daily top gainers (very similar to yahoo). Since pipeline runs before market opens, is there alternative way to get stocks that show high difference between current market_open(lets say minute 2 or 3) and yesterday market_close ?