This is the second in my series updating Sentdex's Tutorials for Quantopian 2. It covers parts 4-7 of Sentdex's tutorial
This second algorithm is a simple screen for 'value' using fundamental data and again highlights some differences between appropriate structure of algorithms in Quantopian 1 to Quantopian 2.
- Instead of using
stock in datato ensure that a stock is
tradeable, you should usedata.can_trade(stock) - The fundamental data fetching should be done through the pipeline
API, not through the query language. There is suppose to be a
tutorial coming out on the pipeline API shortly. I'm still a little
uncertain on whether or not the fundamental query syntax is fully
deprecated or if it still has use cases. If you know please speak
up! - Lastly, for any daily / weekly / monthly strategy, the trades should
be executed through some sort of scheduledrebalancefunction and
not through ahandle_datacall. You will notice an extreme difference in backtesting speed between the two.
I also put my own order entry syntax that I think is much cleaner than Sentdex's. I hope you agree.
Finally, I'm 95% certain that the stop-order that he uses in his tutorial is not a stop loss order. What his order is doing is "wait until the stock pulls back another 0.5% to enter the position." If you wanted a true stop-loss order you would have to enter one order to buy and a second order to sell if the trade went against you X%. And since open orders are canceled at the end of each day in backtesting, this would have to be re-entered every day. I have not included stop-loss logic in this one, let me know if you really want to see it and I'll add it in.