I would like to perform a quantile regression of a autoregressive integrated moving average (ARIMA) model (p,0,q) of a stock return in R. My question is: how can I include the moving average process in the regression? I read I need to use rq (which is available in "quantreg" package) but I cannot follow the procedure for an ARIMA case. Can anybody help me pls? packages used and code until now:

library(quantmod) #to get the stock prices
library(quantreg) #to get the function for quantile regression
ticker <- c("AAPL")
myenv <- new.env()
symnames <- getSymbols(ticker, env=myenv)
ts <- do.call(merge, eapply(myenv, Ad)[symnames])
rt <- diff(log(ts), lag = 1)
rt_final <- rt[-1:-1,]
fit_rt<-auto.arima(rt_final); summary(fit_rt)
x <- fitted(fit_rt)
y <- cbind(x, lx = lag(x),llx=lag(lag(x))) #include two for now
qregr <- rq(x ~ lx + llx, data = y) #this is where I need to include the MA(2) process, right?
qregr <- rq(x ~ lx + llx, tau = seq(0.05, 0.95, by = 0.05), data = y); summary(qregr)


  • $\begingroup$ What is the rq function, and where did you read about it? $\endgroup$ – Carl Sep 25 '16 at 2:55

From the comments in Generating quantile forecasts in R:

Larry Pohlman: For the quantile forecast question you can use the R "quantile" function or the quantile regression function "rq"

Rob J Hyndman: You can only use the quantile function if you can simulate future sample paths of the time series (unless you want to assume iid data). I'm not sure how you would use "rq()" without assuming a linear regression model which is usually too restrictive for forecasting.

Larry Pohlman: strictly speaking quantile regressions are only linear if the residuals are homoscedastic.Otherwise the quantitle regression generates a family of linear functions for every quantile. Check Roger Koenker's papers / book

Rob J Hyndman: I've read Koenker, and I've used rq. Homoscedasticity will give you parallel lines. I don't want parallel lines, and I don't even want linear functions, or a family of linear functions. Forecast quantiles are almost never linear.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.