R 时间序列数据预测
我有一个数据集,包含股票利率VIX的截止日期。我的练习是从上一个日期开始预测300个点,并将其与实际历史数据进行比较。1826年对我的数据进行的观察的一个片段R 时间序列数据预测,r,date,R,Date,我有一个数据集,包含股票利率VIX的截止日期。我的练习是从上一个日期开始预测300个点,并将其与实际历史数据进行比较。1826年对我的数据进行的观察的一个片段 Date Open High Low Close 02/01/2004 17.96 18.68 17.54 18.22 05/01/2004 18.45 18.49 17.44 17.49 06/01/2004 17.66 17.67 16.19 16.73 07/01/2004
Date Open High Low Close
02/01/2004 17.96 18.68 17.54 18.22
05/01/2004 18.45 18.49 17.44 17.49
06/01/2004 17.66 17.67 16.19 16.73
07/01/2004 16.72 16.75 15.5 15.5
08/01/2004 15.42 15.68 15.32 15.61
09/01/2004 16.15 16.88 15.57 16.75
12/01/2004 17.32 17.46 16.79 16.82
13/01/2004 16.6 18.33 16.53 18.04
14/01/2004 17.29 17.3 16.4 16.75
15/01/2004 17.07 17.31 15.49 15.56
16/01/2004 15.4 15.44 14.9 15
20/01/2004 15.77 16.13 15.09 15.21
21/01/2004 15.63 15.63 14.24 14.34
22/01/2004 14.2 14.87 14.01 14.71
23/01/2004 14.73 15.05 14.56 14.84
26/01/2004 15.78 15.78 14.52 14.55
27/01/2004 15.28 15.44 14.74 15.35
28/01/2004 15.37 17.06 15.29 16.78
代码生成了一个预测,它是一个平面图,我想在同一个图中绘制历史数据。我该怎么做
r_vix=diff(log(VIX[,"Close"]))
fit_1step <- auto.arima(r_vix[1:15])
h=300
forecast_1step = forecast(fit_1step, h=h)
plot(forecast_1step, xaxt="n",type="b")
plot_labels = 5
axis(1, at=seq(0,length(r_vix)+h-1,plot_labels), labels=VIX$Date[seq(2, length(r_vix)+h,plot_labels)] )
r_vix=diff(log(vix[,“Close”]))
fit_1step部分问题在于,您试图使用ts
对象表示日期。通常,ts
用于在等间隔时间点(如每日、每周或每月)采样的数据。您的时间序列缺少周末和某些节假日的数据,因此ts
不合适,预测功能也不需要<代码>自动。arima可以使用包含数据的向量。您唯一的问题似乎是在由绘图功能为forecast
对象创建的图表上显示日期。下面是一个如何做到这一点的例子
library(forecast)
r_vix <- diff(log(VIX[,"Close"]))[-1]
num_train <- 1826 # number of points used to calculate ARIMA model
fit_1step <- auto.arima(r_vix[1:num_train])
h <- 300 # number of forecast points
forecast_1step = forecast(fit_1step, h=h)
plot_start <- 1000 # number of points at start of data series omitted from plot
plot(forecast_1step, xaxt="n", xlim=c(plot_start, num_train+300), ylim=range(r_vix))
data_fcst_pts <- num_train:(num_train+h) # range of data points in forecast interval
points(data_fcst_pts, r_vix[data_fcst_pts],col="blue", type="p", pch=16)
plot_labels <- 126 # interval between x-axis major tick marks
axis(1, at=seq(0,length(r_vix)+h-1,plot_labels),
labels=VIX$Date[seq(2, length(r_vix)+h,plot_labels)] )
库(预测)
嗨,沃尔茨,我已经编辑了我原来的问题。还有一些问题。你为什么要设置h->6,我想是300,这是我的预测期。我设置了h