Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Using pipeline to make list of stocks

1/3/2016 Update: The original problem still exists, being it is not possible to use a pipeline to select stocks to trade inside of a research notebook. The reason is that, before an algo is run in the research notebook, one must request the stock data for the algo to run on. Limiting you to the stocks you request, making it impossible to programmatically choose stocks to trade inside the algo based on the pipeline.

12/24/2015 Update: I was having a problem creating a pipeline to construct a list of stocks given a filter.
My Solution: Use a random stock to get historical date data, then run the algo w/ that date data, and use pipeline to actually select the stocks to trade. This enables the pipeline to run, but trading is not allowed on any stocks not requested in data = ... before the algo is run

Post:
The problem I'm having is in order to get the candidates I need trading date information. ie What are the 500 largest mkt cap stocks on 1-1-1999...

I can't get trading information for every stock in the universe, so I need the pipeline, but I can't construct the pipeline without the trading date.

I think I'm missing something because the main purpose of the pipeline is to construct a stock universe that updates.

4 responses

Hi Matthew,

I'm not sure that I follow exactly what you're trying to do. My best guess as to a solution to your problem is to run your pipeline over several days (as opposed to just 1 day at a time). This will give you one dataframe with the results for each factor on each date. You can then extract what you need from there. Take a look at the notebook on this thread as an example.

In addition, it looks like you're getting an error on the line now = get_datetime(). The get_datetime() function only works when running a simulation!

Let me know if this helps or if you have any other questions.

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.

Using this method I was able to build a pipeline, but unable to submit orders. It seems that to place an order in the algo, data must be retrieved before the algo is run. I've tried updating data in the algo, but that does not work.

Hi Matthew,

I took a look at the notebook and it seems as though orders are successfully being placed. The '0 filled' message is being output because the status of the order is being checked in the same bar that it was placed. An order is never filled until at least the next bar (next minute in minute mode, next day in daily mode). Is this what you were asking about?

Thanks for keeping up w/ this thread. I updated the notebook to test checking the orders on a later date, here is a sample output.

I did grab data for AAPL and BRK_A as a test before calling the algo and they are the only two stocks that orders are being placed in.

2015-07-24 buying:AAPL
2015-07-24 buying:BRK_A
2015-07-24 buying:MSFT
2015-07-24 buying:GOOG_L
2015-07-24 buying:GOOG

2015-07-28
Order for 1 Equity(24 [AAPL]) has 1 shares filled.
Order for 1 Equity(1091 [BRK_A]) has 1 shares filled.
Order for 1 Equity(5061 [MSFT]) has 0 shares filled.
Order for 1 Equity(26578 [GOOG_L]) has 0 shares filled.
Order for 1 Equity(46631 [GOOG]) has 0 shares filled.