Back to Community
auto pick stocks filter

Guys, I need help!

I have a code but i have selected the 5 individual stocks to trade. But now i want the code to autoselect 5 stocks with a low P/E rato. how can i do that? how can i code it to select e.g. US market or from NYSE stocks only. Is there any filter?

thank you

1 response

Attached is a simple algorithm to get you started. It buys five securities with the highest PE ratios on the NYSE each month (and sells any other positions).

Take a look at the documentation for how to set up pipelines https://www.quantopian.com/tutorials/pipeline

The first step is to define a pipeline to get all the data you need and perhaps filter to a subset of securities based on that data. In this case I used the fundamental data "valuation_ratios.pe_ratio" and "share_class_reference.exchange_id" from Morningstar (see https://www.quantopian.com/data/morningstar/fundamentals the available fields are here https://www.quantopian.com/help/fundamentals )

The second step is to run the pipeline (typically in the "before_trading_start" function) which then gets the data and applies any filters you have defined.

Finally, use that data to place your orders.

Take a look at https://www.quantopian.com/data for all the available data you have at your disposal. Individual fields in those datasets can easily be made into factors to use in your pipeline. Simply use the ".latest" method (see https://www.quantopian.com/help#sample-earnings-risk for an example)

Good luck.

Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5842ebeee7b6b95e72e47148
There was a runtime error.