[英]Missing Date values in time series modeling using `R`
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: 由于博客中使用的数据集不可访问,因此我改用了GOOG
代码, quantmod
和tseries
库:
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. 日期中好像有NA
值,但我不知道这些是周末还是其他间隔。 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
. 实际价格中没有NA
值: sum(is.na(GOOG$GOOG.Adjusted)) [1] 0
或日期中: 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
. 仅排除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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.