使用“R”的时间序列建模中缺少日期值
Missing Date values in time series modeling using `R`
我试图通过重现 this post 来直观地了解时间序列在金融市场中的使用。由于无法访问博客中使用的数据集,因此我使用了 GOOG
代码以及 quantmod
和 tseries
库:
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
.
可能是周末和节假日的问题。如果是这样,如何处理?
只需排除 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
我试图通过重现 this post 来直观地了解时间序列在金融市场中的使用。由于无法访问博客中使用的数据集,因此我使用了 GOOG
代码以及 quantmod
和 tseries
库:
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
.
可能是周末和节假日的问题。如果是这样,如何处理?
只需排除 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