I'm using the package fMarkovSwitching
in R to do what I was trying to do here: Fitting Markov Switching Models to data in R.
However, I get another weird error message. I'm trying to replicate the example at page 12 (using my time series of log returns) of this paper: http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1714016
Here is the code I'm using:
library(tseries)
#Prices
ftse <- get.hist.quote(instrument="^FTSE", start="1984-01-03", end="2014-01-01", quote="AdjClose", compression="m")
#Log-returns
ftse.ret <- diff(log(ftse))
ftse.ret1 <- as.numeric(ftse.ret)
library(fMarkovSwitching)
dep <- ftse.ret1
constVec <- matrix(1,nrow=length(dep),ncol=1)
indep <- constVec
k <- 2
S <- c(1,1)
myModel<-MS_Regress_Fit(dep=dep,indep=indep,S=S,k=k,distIn = "Normal")
The error message I get is the following:
Error in MS_Regress_Fit(dep = dep, indep = indep, S = S, k = k, distIn = "Normal") : The number of columns at indep should match the number of columns at S
The code I wrote is just a "translation" of the MATLAB example in the paper. If I modify S
to have a match for the number of columns I still get the same error message, whereas if I modify indep
the output I get is wrong.
Edit: The package can be installed in R using the following command: install.packages("fMarkovSwitching", repos="http://R-Forge.R-project.org")