I am interested in studying the behavior of exchange rates. I would like to use R as a software. Can anyone please explain the algorithm that I should follow in order to fit a regime switch model? Do we need to know the number of regimes when fitting a RSM or is it possible for the model to identify the number of regimes?