I'm trying to get an intuitive idea of the use of time series in financial markets by attempting to reproduce this post. Since the dataset used in the blog is not accessible, I have used instead the GOOG
ticker and the quantmod
and tseries
libraries:
library(quantmod)
library(tseries)
getSymbols("GOOG")
str(GOOG) # We start with an xts
The series is not stationary calling for differencing:
GOOG_stationary = 100 * diff(log(GOOG$GOOG.Adjusted)) # Made stationary
Now when I try to run a time series model as called for in the blog, I get an error message as follows:
GOOG_stationary = 100 * diff(log(GOOG$GOOG.Adjusted)) # Made stationary
summary(arma(GOOG_stationary, order = c(2,2)))
Error in summary(arma(GOOG_stationary, order = c(2, 2))) :
error in evaluating the argument 'object' in selecting a method for function 'summary':
Error in arma(GOOG_stationary, order = c(2, 2)) : NAs in x
It seems as though there are NA
values in the dates, but I don't know if these are weekends, or other gaps. There are no NA
values in the actual prices: sum(is.na(GOOG$GOOG.Adjusted)) [1] 0
, or in the dates: sum(is.na(index(GOOG))) [1] 0
.
It is likely to be a problem with weekends and holidays. If this is the case, how can it be handled?
Just exclude the NAs
. In this case just the first.
GOOG_stationary = 100 * diff(log(GOOG$GOOG.Adjusted))[-1]
summary(arma(GOOG_stationary, order = c(2,2)))
Call:
arma(x = GOOG_stationary, order = c(2, 2))
Model:
ARMA(2,2)
Residuals:
Min 1Q Median 3Q Max
-12.41416 -0.86057 -0.02153 0.91053 18.17041
Coefficient(s):
Estimate Std. Error t value Pr(>|t|)
ar1 -0.19963 NA NA NA
ar2 0.04969 0.65183 0.076 0.9392
ma1 0.18210 NA NA NA
ma2 -0.06049 0.66539 -0.091 0.9276
intercept 0.05303 0.02783 1.905 0.0567 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Fit:
sigma^2 estimated as 3.62, Conditional Sum-of-Squares = 8685.37, AIC = 9916.97