From the course: Practical Python for Algorithmic Trading

Unlock the full course today

Join today to access over 23,800 courses taught by industry experts.

Run the backtest on the strategy

Run the backtest on the strategy - Python Tutorial

From the course: Practical Python for Algorithmic Trading

Run the backtest on the strategy

- [Instructor] So far in the investment strategy, we have these lines of code and we need to add the conditions to sell or buy that we calculated previously in this part of the notebook. So we copy them and we bring it here. I don't need the for loop because this time the next function will do the direction for us. What we call before tomorrow_direction is what we have forecast tomorrow which is the prediction of our machine learning model. And the flag to see if we already bought the stock or not should be accessible through an initial element of the class. By default is false. And we need to access this element from self. In the for loop we were appending the elements to an empty list, but now we need to take action with a function within the class strategy to buy or sell the stock. Here we buy the stock because it will go up. So self.buy, we don't need the list. And instead of having the list -1, we will put…

Contents