0

I have a problem with my code. I want to forecast stock returns with an ARIMA model in R but I can not get my data stationary. Besides transforming the stock prices into returns, I also tried the diff function for differencing my time-series. I always assumed that data becomes stationary by using one of the 2 methods. However, when I run an augmented dickey fuller test (adf.test in R) my p-value shows me that the data remains non-stationary. What am I doing wrong?

enter image description here

Thanks in advance.

  • Be sure to include code in the text rather than in an image. Please see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. – hmhensen Apr 15 '19 at 19:53

1 Answers1

0

You must perform time series decomposition into data, seasonal, trend and residuals:

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

data$moving_average=ma(data$original, order=7)
moving_average = ts(na.omit(data$moving_average), frequency=30)
decomposition = stl(moving_average, s.window="periodic")
stationary <- seasadj(decomposition)
plot(decomposition)

You will get:

ARIMA

razimbres
  • 4,715
  • 5
  • 23
  • 50
  • Firt of all, thank you. But how can it be that the returns that I calculated are stationary, but as soon as I transform them into time-series format they turn non-stationary? It's literally the same data, just in a different format. Or am I missing something? –  Apr 16 '19 at 17:18