3
$\begingroup$

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.NSreturns<-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");
ICICIBANK.NS<-as.data.frame(ICICIBANK.NS)
ICICIBANK.NSreturns<-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 ?

$\endgroup$
3
$\begingroup$

There are a couple of issues with your example. First, for this ticker, there is a problem with the Yahoo price data for the period 2014-11-26 through 2014-12-03 in which the prices drop about 80% and then return to their trend line. This appears to be related to a stock split which Yahoo isn't handling properly and isn't real. Its causing part of your problem with the arima calculations. Also to get the arima results for prices and returns to agree, you need to compare the results with either both log or both not log but not mixed. For the log data, the prices model is (2,1,2) and the returns model is (2,0,2) with the same coefficients which is what you should expect. Finally, you might look at the acf plots for the returns and notice that these don't show any significant autocorrelation so you might not expect too much from the arima results for prediction purposes. If you're looking for changes in the behavior of the stock, you might start with plotting the changes in the mean over a rolling window. Code related to these comments follows:

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) 
ar_prices <- auto.arima(log(ICICIBANK.NS))
ar_returns <- auto.arima(ICICIBANK.NSreturns)
acf(ICICIBANK.NSreturns)
mean_returns <- rollmean(ICICIBANK.NSreturns, k=100)
plot(mean_returns)
$\endgroup$

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.