Backtesting / Machine Learning examples for a basket of stocks?

I have recently got access to several of Quantra's courses. I've noticed, however, that all the strategy codes (e.g. in Python for Trading, ML:Classification & SVM, etc) are for single instruments.   Is there any section from any course which has an example where Backtesting or Machine Learning is done on a basket of stocks , instead of a single instrument? Coming from a Amibroker platform , which is super simple to test a universe of stocks, I'm trying to wrap my head around doing it for multiple stocks. Also, I wonder if the cross-sectional approach is simply not suitable for Machine Learning purposes?  Would appreciate any enlightnment!! Thank you. 

Hello Mandy,



You are correct in pointing out that it is not ideal to approach multiple stocks with the same machine learning model. The primary reason is that any 2 stocks however correlated, will still show the difference in the price action and may have different rates at which they react to, market news. Another problem is if the script base is of a different order, like a 100 dollar share and a 1000 dollar share. 



Hence, we approach each stock individually and train the model, so that the model weights are specific for that particular stock.



Please note that the methodology or process we are not changing for different stocks, but merely changing the data on which the model learns. This will result in different model weights for different stocks.



Giving a hypothetical example, the above statement intuitively means that the ML model you trained for AAPL(Apple stock), may take a long position after the AAPL prices fall 3%. but for GOOG(Google stock), may be the threshold for buying to make profitable trades was 5%. This 3% and 5% values we obtain by training the ML model on different stocks individually.



The basket of stocks approach can be applied when you are using a mathematical approach based purely on technical indicators. In ML scenario, it may be applied, only if you loop through all the stocks and train the model individually.



Hope this helps!

Thank you Gaurav!  Well-understood. That makes sense! 

Hey Mandy,



You can apply the same concepts on a basket of stocks. If you simply want to run it through multiple stocks, a simple for loop which will walk through each stock and give results will help you.



Another approach would be to create a single model which can predict the buy/sell for the multiple stocks. One such illustration can be found here. However, it is difficult to find a one model fit all prediction in financial markets due to low signal to noise ratio.



Thanks

Thank you! The example in the blog was exactly what I was looking for in terms of operationalizing the code in Python for a single model applied to a basket of stocks.   But well-noted on the low signal-to-noise ratio in this case, as opposed to looping for each stock.   Thanks again!!