Reference: Regime-Switching Factor Investing with Hidden Markov Models  by Matthew Wang  , Yi-Hong Lin  and Ilya Mikhelson /


hello everyone dear,
I am attaching a very interesting paper discussing the use of HMM for market regime identification and the subsequent choice of which factorial model to select stocks to choose.
Also in the first link you will find the code published by the Author of the Paper who used quantconnect as his Backtest platform.

1) Algorithm takes a long time to run due to the complexity and amount of data to process so I leave the running to you

2) Next step, interesting in my opinion is to repurpose the regime change model published by the author, not to then choose which type of portfolio chosen from a factorial model to take, but to simplify it by choosing different ETFs, following somewhat along the lines of the Asset ''SAFE'' (or even more than one) as it was intended in IN&OUT.

Translated with (free version)