Back to Community
official API Doc code, doesn't run in Algorithms

Hi,
I am a newbie here. Trying to learn and deploy my investment through Quantopian. I started with some youtube tutorial videos, and now working through the API docs.
In the section of pipeline, I tried to run the sample code in the Algorithms. I just copy and paste the attached 'official' code, but the system returned with the Error message: --- Error InvalidSidCount: 0019 Algorithm must reference 1-500 SIDs. Found 0

So what happened to the code? is it an official documented code? What shall I do?

Thanks in advance for your help, Allan

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 SimpleMovingAverage

def initialize(context):

# Create and attach an empty Pipeline.  
pipe = Pipeline()  
pipe = attach_pipeline(pipe, name='my_pipeline')

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

# Construct a Filter.  
prices_under_5 = (sma_10 < 5)

# Register outputs.  
pipe.add(sma_10, 'sma_10')  
pipe.add(sma_30, 'sma_30')

# Remove unwanted rows from output.  
pipe.set_screen(prices_under_5)

def before_trading_start(context, data):
# Access results using the name passed to attach_pipeline.
results = pipeline_output('my_pipeline')
print results.head(5)

1 response

Hi Allan,

This is an issue with the example in the docs. We have static analysis checks asserting that you call one of sid, symbol, or update_universe somewhere in your code. We didn't add any of those calls in the first example, because we just wanted to show the simplest possible example of how to get a pipeline running, but the fact that the first example can't be run at all is a bug.

I'm working on a couple tweaks to the docs that should be out by the end of the day. In the meantime, there are working examples at the bottom of the API Docs.

Sorry about the broken example.

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.