df=structure(list(X = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
json_data.time.updated = structure(1:41, .Label = c("Jan 19, 2019 15:18:00 UTC",
"Jan 19, 2019 15:19:00 UTC", "Jan 19, 2019 15:51:00 UTC",
"Jan 19, 2019 15:52:00 UTC", "Jan 19, 2019 15:54:00 UTC",
"Jan 19, 2019 15:55:00 UTC", "Jan 19, 2019 15:57:00 UTC",
"Jan 19, 2019 15:58:00 UTC", "Jan 19, 2019 16:00:00 UTC",
"Jan 19, 2019 16:01:00 UTC", "Jan 19, 2019 16:03:00 UTC",
"Jan 19, 2019 16:04:00 UTC", "Jan 19, 2019 16:06:00 UTC",
"Jan 19, 2019 16:07:00 UTC", "Jan 19, 2019 16:09:00 UTC",
"Jan 19, 2019 16:10:00 UTC", "Jan 19, 2019 16:12:00 UTC",
"Jan 19, 2019 16:13:00 UTC", "Jan 19, 2019 16:15:00 UTC",
"Jan 19, 2019 16:16:00 UTC", "Jan 19, 2019 16:18:00 UTC",
"Jan 19, 2019 16:19:00 UTC", "Jan 19, 2019 16:21:00 UTC",
"Jan 19, 2019 16:22:00 UTC", "Jan 19, 2019 16:24:00 UTC",
"Jan 19, 2019 16:25:00 UTC", "Jan 19, 2019 16:27:00 UTC",
"Jan 19, 2019 16:28:00 UTC", "Jan 19, 2019 16:30:00 UTC",
"Jan 19, 2019 16:31:00 UTC", "Jan 19, 2019 16:33:00 UTC",
"Jan 19, 2019 16:34:00 UTC", "Jan 19, 2019 16:36:00 UTC",
"Jan 19, 2019 16:37:00 UTC", "Jan 19, 2019 16:39:00 UTC",
"Jan 19, 2019 16:40:00 UTC", "Jan 19, 2019 16:42:00 UTC",
"Jan 19, 2019 16:43:00 UTC", "Jan 19, 2019 16:45:00 UTC",
"Jan 19, 2019 16:46:00 UTC", "Jan 19, 2019 16:48:00 UTC"), class = "factor"),
json_data.time.updatedISO = structure(1:41, .Label = c("2019-01-19T15:18:00+00:00",
"2019-01-19T15:19:00+00:00", "2019-01-19T15:51:00+00:00",
"2019-01-19T15:52:00+00:00", "2019-01-19T15:54:00+00:00",
"2019-01-19T15:55:00+00:00", "2019-01-19T15:57:00+00:00",
"2019-01-19T15:58:00+00:00", "2019-01-19T16:00:00+00:00",
"2019-01-19T16:01:00+00:00", "2019-01-19T16:03:00+00:00",
"2019-01-19T16:04:00+00:00", "2019-01-19T16:06:00+00:00",
"2019-01-19T16:07:00+00:00", "2019-01-19T16:09:00+00:00",
"2019-01-19T16:10:00+00:00", "2019-01-19T16:12:00+00:00",
"2019-01-19T16:13:00+00:00", "2019-01-19T16:15:00+00:00",
"2019-01-19T16:16:00+00:00", "2019-01-19T16:18:00+00:00",
"2019-01-19T16:19:00+00:00", "2019-01-19T16:21:00+00:00",
"2019-01-19T16:22:00+00:00", "2019-01-19T16:24:00+00:00",
"2019-01-19T16:25:00+00:00", "2019-01-19T16:27:00+00:00",
"2019-01-19T16:28:00+00:00", "2019-01-19T16:30:00+00:00",
"2019-01-19T16:31:00+00:00", "2019-01-19T16:33:00+00:00",
"2019-01-19T16:34:00+00:00", "2019-01-19T16:36:00+00:00",
"2019-01-19T16:37:00+00:00", "2019-01-19T16:39:00+00:00",
"2019-01-19T16:40:00+00:00", "2019-01-19T16:42:00+00:00",
"2019-01-19T16:43:00+00:00", "2019-01-19T16:45:00+00:00",
"2019-01-19T16:46:00+00:00", "2019-01-19T16:48:00+00:00"), class = "factor"),
json_data.time.updateduk = structure(1:41, .Label = c("Jan 19, 2019 at 15:18 GMT",
"Jan 19, 2019 at 15:19 GMT", "Jan 19, 2019 at 15:51 GMT",
"Jan 19, 2019 at 15:52 GMT", "Jan 19, 2019 at 15:54 GMT",
"Jan 19, 2019 at 15:55 GMT", "Jan 19, 2019 at 15:57 GMT",
"Jan 19, 2019 at 15:58 GMT", "Jan 19, 2019 at 16:00 GMT",
"Jan 19, 2019 at 16:01 GMT", "Jan 19, 2019 at 16:03 GMT",
"Jan 19, 2019 at 16:04 GMT", "Jan 19, 2019 at 16:06 GMT",
"Jan 19, 2019 at 16:07 GMT", "Jan 19, 2019 at 16:09 GMT",
"Jan 19, 2019 at 16:10 GMT", "Jan 19, 2019 at 16:12 GMT",
"Jan 19, 2019 at 16:13 GMT", "Jan 19, 2019 at 16:15 GMT",
"Jan 19, 2019 at 16:16 GMT", "Jan 19, 2019 at 16:18 GMT",
"Jan 19, 2019 at 16:19 GMT", "Jan 19, 2019 at 16:21 GMT",
"Jan 19, 2019 at 16:22 GMT", "Jan 19, 2019 at 16:24 GMT",
"Jan 19, 2019 at 16:25 GMT", "Jan 19, 2019 at 16:27 GMT",
"Jan 19, 2019 at 16:28 GMT", "Jan 19, 2019 at 16:30 GMT",
"Jan 19, 2019 at 16:31 GMT", "Jan 19, 2019 at 16:33 GMT",
"Jan 19, 2019 at 16:34 GMT", "Jan 19, 2019 at 16:36 GMT",
"Jan 19, 2019 at 16:37 GMT", "Jan 19, 2019 at 16:39 GMT",
"Jan 19, 2019 at 16:40 GMT", "Jan 19, 2019 at 16:42 GMT",
"Jan 19, 2019 at 16:43 GMT", "Jan 19, 2019 at 16:45 GMT",
"Jan 19, 2019 at 16:46 GMT", "Jan 19, 2019 at 16:48 GMT"), class = "factor"),
code = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = "USD", class = "factor"), rate = structure(1:41, .Label = c("3,735.7750",
"3,735.9150", "3,736.9100", "3,735.3200", "3,736.7717", "3,736.0750",
"3,734.9600", "3,734.9117", "3,734.2833", "3,734.4950", "3,735.8533",
"3,736.1917", "3,735.5450", "3,735.5867", "3,736.0617", "3,736.3417",
"3,737.0633", "3,736.9583", "3,737.1667", "3,737.1433", "3,737.0583",
"3,736.9283", "3,737.6383", "3,737.5167", "3,737.9133", "3,738.7533",
"3,738.6767", "3,738.5767", "3,738.5917", "3,738.8867", "3,739.6333",
"3,739.9600", "3,739.3383", "3,739.9267", "3,739.3067", "3,739.5867",
"3,739.6567", "3,739.4267", "3,739.1500", "3,739.8817", "3,739.5550"
), class = "factor"), description = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "United States Dollar", class = "factor"),
rate_float = structure(1:41, .Label = c("3735.775", "3735.915",
"3736.91", "3735.32", "3736.7717", "3736.075", "3734.96",
"3734.9117", "3734.2833", "3734.495", "3735.8533", "3736.1917",
"3735.545", "3735.5867", "3736.0617", "3736.3417", "3737.0633",
"3736.9583", "3737.1667", "3737.1433", "3737.0583", "3736.9283",
"3737.6383", "3737.5167", "3737.9133", "3738.7533", "3738.6767",
"3738.5767", "3738.5917", "3738.8867", "3739.6333", "3739.96",
"3739.3383", "3739.9267", "3739.3067", "3739.5867", "3739.6567",
"3739.4267", "3739.15", "3739.8817", "3739.555"), class = "factor")), row.names = c(NA,
41L), class = "data.frame")
我想执行GARCH模型,所以我有这段代码
df$rate_float=as.numeric(df$rate_float)
library("fGarch")
b=garchFit(formula = ~ garch(1, 1), data = df$rate_float,
init.rec = c( "mci","uev"),
delta = 2, skew = 1, shape = 4,
cond.dist = c("norm", "snorm", "ged", "sged", "std", "sstd",
"snig", "QMLE"),
include.mean = TRUE, include.delta = NULL, include.skew = NULL,
include.shape = NULL, leverage = NULL, trace = TRUE,
algorithm = c("nlminb", "lbfgsb", "nlminb+nm", "lbfgsb+nm"),
hessian = c("ropt"), control = list(),
title = NULL, description = NULL)
garchKappa(cond.dist = c("norm", "ged", "std", "snorm", "sged", "sstd",
"snig"), gamma = 0, delta = 2, skew = NA, shape = NA)
因此,时间变量为json_data.time.updateduk。 我如何在10分钟前创建预测? 其次,但相关的问题,我如何获取初始值的预测以了解预测的质量 所以作为输出我需要 1.像这样预测10分钟
如何做到?
答案 0 :(得分:2)
您可以预测前进10步
predict(b, n.ahead = 10)
# meanForecast meanError standardDeviation
# 1 20.19952 20.82351 20.82351
# 2 20.19952 20.84651 20.84651
# 3 20.19952 20.86948 20.86948
# 4 20.19952 20.89243 20.89243
# 5 20.19952 20.91535 20.91535
# 6 20.19952 20.93825 20.93825
# 7 20.19952 20.96112 20.96112
# 8 20.19952 20.98396 20.98396
# 9 20.19952 21.00679 21.00679
# 10 20.19952 21.02959 21.02959
而拟合值由
给出fitted(b)
# 1 2 3 4 5 6 7 8 9 10
# 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952
# 11 12 13 14 15 16 17 18 19 20
# 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952
# 21 22 23 24 25 26 27 28 29 30
# 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952
# 31 32 33 34 35 36 37 38 39 40
# 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952 20.19952
# 41
# 20.19952
由于要对条件方差建模,因此平均预测值和拟合值是恒定的;因此,预测的其他两列不是恒定的。拟合的条件标准偏差由
给出b@sigma.t
# [1] 11.8995423 19.2244571 18.2258257 17.2273530 16.2290683 15.2310087 14.2332215 13.2357682
# [9] 12.2387307 11.2422194 10.2463878 9.2514556 8.2577478 7.2657667 6.2763312 5.2908696
# [17] 4.3121073 3.3459283 2.4075307 1.5482802 0.9990692 1.2645580 2.0494083 2.9666550
# [25] 3.9245394 4.8992833 5.8825118 6.8705831 7.8616716 8.8547641 9.8492545 10.8447583
# [33] 11.8410198 12.8378627 13.8351612 14.8328235 15.8307808 16.8289806 17.8273822 18.8259534
# [41] 19.8246687