rollapply with Arima model: testing for stability of coefficients

#1
Hi everyone,

I am trying to fit an arima model on a rolling window using rollapply.My aim is to plot a graph of the evolution of the coefficient, plot the error and the standard deviation.
well i encountered the following problems:

1) each window in the roll apply have different set of coeffcients: basically when i plot auto.arima()$coef[1] over time it could be ar1 or ma1 or anything.The reason i am doing this is that plotting the coefficient stability permits to judge the stability of coefficient and assess the accuracy of the model.

> getSymbols("ICICIBANK.NS");
> ICICIBANK.NS<-as.data.frame(ICICIBANK.NS)
> ICICIBANK.NS$returns<-c(NA,diff(log(ICICIBANK.NS$ICICIBANK.NS.Adjusted)))
> z<-ICICIBANK.NS$returns
> z<-na.omit(z)
> y<-rollapply(as.zoo(z),width=100,FUN=function(x) auto.arima(x)$coef[1])

basically i am trying here to have a look at the evolution of the first coefficient.but the model changes from one window to another.

Does anyone have an idea how solve this? or maybe some lead i can work on ?

2) when i do auto.arima to log returns i get an ARIMA(0,0,0) and when i dot it for raw raw prices i get ARIMA(3,1,3):
> getSymbols("ICICIBANK.NS");
[1] "ICICIBANK.NS"
> ICICIBANK.NS<-as.data.frame(ICICIBANK.NS)
> ICICIBANK.NS$returns<-c(NA,diff(log(ICICIBANK.NS$ICICIBANK.NS.Adjusted)))
> auto.arima(ICICIBANK.NS$returns)
Series: ICICIBANK.NS$returns
ARIMA(0,0,0) with zero mean

sigma^2 estimated as 0.003309: log likelihood=3042.76
AIC=-6083.51 AICc=-6083.51 BIC=-6077.86
> auto.arima(ICICIBANK.NS$ICICIBANK.NS.Adjusted)
Series: ICICIBANK.NS$ICICIBANK.NS.Adjusted
ARIMA(3,1,3) with drift

Coefficients:
ar1 ar2 ar3 ma1 ma2 ma3 drift
0.0741 -0.0998 0.5626 -0.0572 0.0662 -0.8633 0.1087
s.e. 0.0306 0.0323 0.0279 0.0192 0.0200 0.0159 0.0606

sigma^2 estimated as 77.62: log likelihood=-7610.48
AIC=15236.96 AICc=15237.02 BIC=15282.22

why would auto.arima() work with prices and not log returns ?
 

noetsi

Fortran must die
#2
If this is a software question, which I would guess, you probably want it in the pertinant software area not here. I am not sure what software you are using.
 

Dason

Ambassador to the humans
#3
basically i am trying here to have a look at the evolution of the first coefficient.but the model changes from one window to another.
Then don't use auto.arima - just use arima to fit the same model every time.

why would auto.arima() work with prices and not log returns ?
Who said auto.arima isn't working? It gave you what it thought was the best model for the data under the constraints that you gave it. Sometimes that ends up being a very very simple model.

If this is a software question, which I would guess, you probably want it in the pertinant software area not here. I am not sure what software you are using.
You should be able to recognize at least some R by now ;)
 

noetsi

Fortran must die
#4
I guessed it was R dason :) but then there are lots of other software like say Matlab it could be and I was reluctant to mislead a poster :p

Well it's ok to mislead spunky...:p

There are many tools designed over the years to analyze ARIMA. I do not know how R uses them, but the OP might want to look at them and find out where R does them [or how I guess].
 
#6
Thanks for your reply,

Well, basically what i am trying to find is if there is a model that is more appropriate on a window of N=50/100/200 days
over time.
I thought maybe by looking at the evolution of the models and coefficients we can come up with more robust model.

When i use all the data the model fitted by auto.arima() is far from the real data as you can see from plotted model versus real data.
I can see that after differencing the data is stationary but still the model ouput by auto arima is not conclusive.

library('tseries')
library(quantmod)
library(forecast)

ICICIBANK.NS <- getSymbols("ICICIBANK.NS", auto.assign=FALSE)[,6]
ICICIBANK.NSreturns <- diff(ICICIBANK.NS, log=TRUE, na.pad=FALSE)
big_ret <- which(abs(ICICIBANK.NSreturns)>.5) # finds erroneously large returns at start and end of period with bad data
bad_rows <- (big_ret[1]+1) : (big_ret[2])
bad_data <- ICICIBANK.NS[bad_rows]
ICICIBANK.NS <- ICICIBANK.NS[-bad_rows,]
ICICIBANK.NSreturns <- diff(ICICIBANK.NS, log=TRUE, na.pad=FALSE)

Box.test(ICICIBANK.NSreturns,lag=20,type="Ljung-Box")
adf.test(ICICIBANK.NSreturns,alternative="stationary")
acf(ICICIBANK.NSreturns)

ar_prices <- auto.arima(log(ICICIBANK.NS))
ar_returns <- auto.arima(ICICIBANK.NSreturns)

plot(ar_returns$x,col="red")
lines(fitted(ar_returns),col="blue")

mean_returns <- rollmean(ICICIBANK.NSreturns, k=100)
plot(mean_returns)

Is there any other model fitting technique than auto.arima that could produce more robust results? any leads?