I have price data for an asset. I want to fit a Markow Switching model (with 2 states). The code I have run is below. Price is configured as numeric and date as a date. Not sure where I'm going wrong.
library(MSwM)
# Loading required package: parallel
library(ggplot2)
nstates <- 6
olsPrice <- lm(PriceUSD~date, Priced)
msmPrice <- msmFit(olsPrice, k = nstates, sw = c(FALSE, TRUE, TRUE))
The error message I get is:
Error in w * matrix(resid(modaux), ncol = k, byrow = T)^2 :
non-conformable arrays