我需要调整财务时间序列,并分析错误。 我已将该系列与线性模型拟合。
library("quantmod")
library("zoo")
getSymbols("DJIA", src="FRED")
class(DJIA)
serie = DJIA["2017/2018"]
price = as.numeric(serie)
time = index(serie)
x=1:length(price)
model = lm(price~x)
reg = model$coef[1]+model$coef[2]*x
plot(x=time, y=price, main="Dow Jones", type="l", xlab="Data", ylab="Points")
lines(time, reg, col=2, lwd=2)
我的系列有NA值。在下面,您可以看到第一个值为NA
。
head(serie)
> head(serie)
DJIA
2017-01-02 NA
2017-01-03 19881.76
2017-01-04 19942.16
2017-01-05 19899.29
2017-01-06 19963.80
2017-01-09 19887.38
我尝试使用na.StructTS()
包中的函数zoo
。
serie_out <- na.StructTS(serie, na.rm=TRUE)
# Error in StructTS(y) :
# the first value of the time series must not be missing
编辑。
serie_out <- na.StructTS(serie[-1,], na.rm=TRUE)
# Error in rowSums(tsSmooth(StructTS(y))[, -2]) :
# 'x' must be an array of at least two dimensions
问题。
如何使用财务时间序列中的NA
值?
我可以将开始时间从2017年1月2日移到2017年1月3日,但是该系列有几个NA
。