rjdverse / rjd3sts

R access to Structural Time Series algorithms in JDemetra+ version 3.x
https://rjdverse.github.io/rjd3sts/
European Union Public License 1.2
2 stars 6 forks source link

reg_td with user-defined calendar #10

Open AQLT opened 8 months ago

AQLT commented 8 months ago

It could be good to be able to use reg_td() with user-defined calendar. Currently, the trading-days regressors and the covariance structure are built inside Java, however they could be directly provided in R (the covariance structure could for example be built using the generateVar function). I don't think it is possible to do this with the other functions.

palatej commented 4 months ago

Hi Alain,

Internally, the code inside reg_td generates the regression variables and the covariance of the innovations, if the coefficients are variable (multivariate random walk). Generating the regression variables can be easily done with the routines provided in rjd3toolkit, included in the case of calendars with holidays.

See below:

y<-log(rjd3toolkit::retail$BookStores)

model1<-rjd3sts::model()
sarima<-rjd3sts::sarima('arima', 12, orders=c(0,1,1), seasonal=c(0,1,1))
td<-rjd3sts::reg_td('td', 12, start(y), length(y), variance=0, fixed=TRUE)

rjd3sts::add(model1, sarima)
rjd3sts::add(model1, td)

rslt1<-rjd3sts::estimate(model1, y)

print(rjd3toolkit::result(rslt1, 'likelihood.ll'))
model2<-rjd3sts::model()

xtd<-rjd3toolkit::td(12, start(y), length(y))
td<-rjd3sts::reg('td', xtd)

rjd3sts::add(model2, sarima)
rjd3sts::add(model2, td)

rslt2<-rjd3sts::estimate(model2, y)
print(rjd3toolkit::result(rslt2, 'likelihood.ll'))

So, the most flexible solution would be to generate covariance matrices based on different specifications and to use the "reg" method. Of course, a solution hiding all the details can also be provided (a "reg_calendartd" function). Considering that different covariance matrices could be used, I will add both solutions in the next rjd3sts package.