小编Stu*_*eid的帖子

R中的StructTS(卡尔曼滤波器)模型无法正确拟合

我想使用卡尔曼滤波器来预测某些金融时间序列数据中的价格水平。谷歌搜索使我进入了R中的一些功能,即StructTS和KalmanForecast。目前,我正在使用StructTS将模型拟合到部分数据中,然后使用拟合的模型来预测未来的几天。我遇到的问题是该模型似乎不合适。现在,我不确定我训练的模型是否错误?还是如果模型没有使用优化收敛?

我的代码和示例输出如下所示:

alsi <- read.csv("http://www.turingfinance.com/wp-content/uploads/2015/11/ALSI.csv")
alsi <- as.vector(t(alsi['ALSI']))

kDays <- length(alsi)
kDays.sample <- as.integer(kDays*0.9)

alsi.train <- alsi[1:kDays.sample]
alsi.test <- alsi[kDays.sample:kDays]

fitted.model <- StructTS(alsi.train, type = "level")

alsi.test.forecast <- KalmanForecast(n.ahead = length(alsi.test), mod = fitted.model$model)
plot.ts(alsi.test, col = 'blue')
lines(alsi.test.forecast$pred, col = 'red')

alsi.train.forecast <- KalmanForecast(n.ahead =  length(alsi.train), mod = fitted.model$model)
plot.ts(alsi.train, col = 'blue')
lines(alsi.train.forecast$pred, col = 'red')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如您所见,该模型并不十分合适。在发布此问题之前,我已经在Google上进行了很多搜索,并且已经阅读了R中针对?KalmanLike和的文档?StructTS。请帮忙。谢谢!

万一将来有人在R中使用Kalman过滤器,以下是我个人认为非常有用的链接:

R中的卡尔曼滤波(软件包调查)

r time-series forecasting kalman-filter

5
推荐指数
0
解决办法
900
查看次数

标签 统计

forecasting ×1

kalman-filter ×1

r ×1

time-series ×1