Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Does updating universe based on pipeline results ignore the current assets in the porftolio?

Using the code from the help section as an example:


def initialize(context):  
    pipe = Pipeline()  
    pipe = attach_pipeline(pipe, name='my_pipeline')

    sma_10 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10)  
    sma_30 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=30)

    prices_under_5 = (sma_10 < 5)  
    pipe.add(sma_10, 'sma_10')  
    pipe.add(sma_30, 'sma_30')  
    pipe.set_screen(prices_under_5)

def before_trading_start(context, data):  
    results = pipeline_output('my_pipeline')  
    update_universe(results)  

I'm new to Quantopian and how everything fits together still, but correct me if I'm wrong; calling update_universe like this will mean that when I do:

def handle_data(context,data):  
       for stock in data:  
                 print stock  

Each of these stocks will be a result of what was filtered out in the pipeline, yes? So what if I had a portfolio with assets which were excluded from the pipeline screen? Would they not be included in data?

If they are excluded, how would we be able to update_universe() with the pipeline screen and the assets in our portfolio?

Thanks!

2 responses

Hi Alexander,

Even after using the update_universe() function in before_trading_start(), your universe will include stocks in your portfolio that were not explicitly included in the update_universe() call. Check out this short video for an overview of how your universe and the data variable operate.

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 Jamie,

I saw that video, but wasn't sure if the introduction of the pipeline had any change/effect on how the universe was defined.