用XTS对象预测Arima

发布于 2025-01-24 09:08:55 字数 1902 浏览 2 评论 0原文

我有两个XTS对象(一列火车和一个测试/验证集),我想使用基于火车数据集的Arima模型在测试数据集上进行一步预测(即,一步一步样本预测)。但是,每当我使用“预测”功能时,结果似乎很奇怪。这可能是因为预测()假定一个时间序列对象,而我具有XTS对象。 我想知道是否有人知道我想完成的工作?我也想产生像上载的图一样,但是由于我相信使用XTS对象,这再次非常奇怪。 我真的很感谢您的帮助,因为我真的卡在分析的这一步骤中!:) 我的训练集:

dput(head(xts.data)) 结构(C(2.74983173511717,2.75110969056266,2.79971738962803, 2.81540871942271,2.9343864331294,3.01504458458636,NA,0.0012779554549159, 0.0486076990653772,0.0156913297946755,0.11897992389023,0.080659412734247 ),class = c(“ XTS”,“ Zoo”),index = structure(C(1333324800,1333411200, 1333497600,1333584000,1333929600,1334016000),tzone =“ utc”,tclass =“ date”),.dim = c(6l,6l,, 2L),.dimnames = list(null,c(“ lvixcls”,“ ldvixcls”)))

我的验证集:

dput(头(验证)) 结构(C(3.2846635654062,3.31890213893533,3.33077491736561, 3.38371206732114,3.33434507467431,3.27184770963431),类= C(“ XTS”, “ Zoo”),索引=结构(C(1601510400,1601596800,1601856000, 1601942400,1602028800,1602115200),tzone =“ utc”,tclass =“ date”),.dim = c(6l,,6l,, 1L),.dimnames = list(null,“ lvixcls”))

这是我的训练集(用我的训练集(对LVIXCLS建模lvixcls) arima)

这是我的验证数据集 我想产生

r-code:

    data<- read_excel("VIXCLS 10 year data.xls")
    data<-na.omit(data)
    date <- as.Date(data$Date, "%m/%d/%Y")
    ts.data<-data
    ts.data$Date<-as.Date(ts.data$Date, format="%m/%d/%Y")
    xts.data2 <- xts(ts.data[2],ts.data$Date)
    ts.data$Date<-as.Date(ts.data$Date, format="%m/%d/%Y")
    xts.data2 <- xts(ts.data[2],ts.data$Date)
    xts.data<-xts.data2$lVIXCLS[0:2139]
    validation<-xts.data2$lVIXCLS[2140:2517]

I have two xts objects (one train and one test/validation set) and I would like to use ARIMA models based on the train data set to carry out one-step-ahead forecast on the test dataset (namely, one-step out of sample forecasting). However, whenever I use the "forecast" function, the results seem weird. It's probably because forecast() assumes a time series object and I have xts objects.
I was wondering if anyone knows an R command for what I want to accomplish? I would also like to produce a graph like the uploaded one, but once again it turns out very weird due to using xts objects I believe.
I would really appreciate your help as I'm really stuck on this step of my analysis!:)
My training set:

dput(head(xts.data))
structure(c(2.74983173511717, 2.75110969056266, 2.79971738962803,
2.81540871942271, 2.93438864331294, 3.01504458458636, NA, 0.00127795544549159,
0.0486076990653772, 0.0156913297946755, 0.11897992389023, 0.0806559412734247
), class = c("xts", "zoo"), index = structure(c(1333324800, 1333411200,
1333497600, 1333584000, 1333929600, 1334016000), tzone = "UTC", tclass = "Date"), .Dim = c(6L,
2L), .Dimnames = list(NULL, c("lVIXCLS", "ldVIXCLS")))

My validation set:

dput(head(validation))
structure(c(3.2846635654062, 3.31890213893533, 3.33077491736561,
3.38371206732114, 3.33434507467431, 3.27184770963431), class = c("xts",
"zoo"), index = structure(c(1601510400, 1601596800, 1601856000,
1601942400, 1602028800, 1602115200), tzone = "UTC", tclass = "Date"), .Dim = c(6L,
1L), .Dimnames = list(NULL, "lVIXCLS"))

This is my training set (modelling lVIXCLS with ARIMA)

This is my validation dataset
Graph I would like to produce

R-code:

    data<- read_excel("VIXCLS 10 year data.xls")
    data<-na.omit(data)
    date <- as.Date(data$Date, "%m/%d/%Y")
    ts.data<-data
    ts.data$Date<-as.Date(ts.data$Date, format="%m/%d/%Y")
    xts.data2 <- xts(ts.data[2],ts.data$Date)
    ts.data$Date<-as.Date(ts.data$Date, format="%m/%d/%Y")
    xts.data2 <- xts(ts.data[2],ts.data$Date)
    xts.data<-xts.data2$lVIXCLS[0:2139]
    validation<-xts.data2$lVIXCLS[2140:2517]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2025-01-31 09:08:55

为了能够在{tocast}软件包中将功能应用于数据,您只需要使用as.ts将数据转换为时间序列即可。例如:

# Your data

train.dat <- structure(c(2.74983173511717, 2.75110969056266, 2.79971738962803, 
             2.81540871942271, 2.93438864331294, 3.01504458458636, NA, 
             0.00127795544549159, 0.0486076990653772, 0.0156913297946755, 
             0.11897992389023, 0.0806559412734247 ), 
             class = c("xts", "zoo"), 
             index = structure(c(1333324800, 1333411200, 1333497600, 1333584000, 
                     1333929600, 1334016000), tzone = "UTC", tclass = "Date"), 
             .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lVIXCLS", "ldVIXCLS")))

library(forecast)

fit <- auto.arima(as.ts(train.dat[,1]))
fit
# Series: as.ts(train.dat[, 1]) 
# ARIMA(0,1,0) 
# 
# sigma^2 = 0.004656:  log likelihood = 6.33
# AIC=-10.66   AICc=-9.33   BIC=-11.05

然后,您可以使用模型预测值:

forecast(fit)
# Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
# 7       3.015045 2.927599 3.102491 2.881307 3.148782
# 8       3.015045 2.891377 3.138712 2.825912 3.204177
# 9       3.015045 2.863584 3.166506 2.783405 3.246684
# 10       3.015045 2.840153 3.189937 2.747570 3.282519
# 11       3.015045 2.819509 3.210580 2.715999 3.314090
# 12       3.015045 2.800846 3.229243 2.687457 3.342632
# 13       3.015045 2.783684 3.246405 2.661209 3.368880
# 14       3.015045 2.767710 3.262379 2.636779 3.393310
# 15       3.015045 2.752707 3.277383 2.613833 3.416256
# 16       3.015045 2.738516 3.291573 2.592131 3.437959

绘制预测数据

plot(fit)

您还可以使用plot“在此处输入图像说明”

您可以使用与相同的步骤分析测试数据多于。

To be able to apply the functions in {forecast} package to your data, you just need to convert the data to a time series by using as.ts. For example:

# Your data

train.dat <- structure(c(2.74983173511717, 2.75110969056266, 2.79971738962803, 
             2.81540871942271, 2.93438864331294, 3.01504458458636, NA, 
             0.00127795544549159, 0.0486076990653772, 0.0156913297946755, 
             0.11897992389023, 0.0806559412734247 ), 
             class = c("xts", "zoo"), 
             index = structure(c(1333324800, 1333411200, 1333497600, 1333584000, 
                     1333929600, 1334016000), tzone = "UTC", tclass = "Date"), 
             .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lVIXCLS", "ldVIXCLS")))

library(forecast)

fit <- auto.arima(as.ts(train.dat[,1]))
fit
# Series: as.ts(train.dat[, 1]) 
# ARIMA(0,1,0) 
# 
# sigma^2 = 0.004656:  log likelihood = 6.33
# AIC=-10.66   AICc=-9.33   BIC=-11.05

Then, you can use the model to forecast values:

forecast(fit)
# Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
# 7       3.015045 2.927599 3.102491 2.881307 3.148782
# 8       3.015045 2.891377 3.138712 2.825912 3.204177
# 9       3.015045 2.863584 3.166506 2.783405 3.246684
# 10       3.015045 2.840153 3.189937 2.747570 3.282519
# 11       3.015045 2.819509 3.210580 2.715999 3.314090
# 12       3.015045 2.800846 3.229243 2.687457 3.342632
# 13       3.015045 2.783684 3.246405 2.661209 3.368880
# 14       3.015045 2.767710 3.262379 2.636779 3.393310
# 15       3.015045 2.752707 3.277383 2.613833 3.416256
# 16       3.015045 2.738516 3.291573 2.592131 3.437959

You can also plot the forecast data using plot:

plot(fit)

enter image description here

You can analyze the test data with the same steps as above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文