使用`R`在时间序列建模中缺少日期值

时间:2016-07-18 18:06:07

标签: r time-series finance

我试图通过尝试重现this post来直观地了解金融市场中时间序列的使用。由于无法访问博客中使用的数据集,因此我使用了GOOG代码和quantmodtseries库:

library(quantmod)
library(tseries)

getSymbols("GOOG")
str(GOOG) # We start with an xts

该系列并非固定的要求差异化:

GOOG_stationary = 100 * diff(log(GOOG$GOOG.Adjusted)) # Made stationary

现在,当我尝试按照博客中的要求运行时间序列模型时,我收到如下错误消息:

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

似乎日期中有NA个值,但我不知道这些是周末还是其他差距。实际价格中没有NA值:sum(is.na(GOOG$GOOG.Adjusted)) [1] 0或日期:sum(is.na(index(GOOG))) [1] 0

周末和假期可能会出现问题。如果是这种情况,怎么办呢?

1 个答案:

答案 0 :(得分:1)

只需排除NAs即可。在这种情况下只是第一个。

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