https://wokybijirat.universityofthephoenix.com/analytical-derivatives-for-markov-switching-models-book-15833mf.php