我是 R 代码和计量经济学的初学者。目前我创建了一个阈值 GARCH 模型来预测资产价格的波动性。我很难理解如何在彼此之上绘制两个图表,试图将波动性与实际时间序列进行比较,甚至使用它来查看模型在实际数据中的表现。
spec.tgarch <- ugarchspec(variance.model = list(model = "fGARCH",
submodel = "TGARCH",
garchOrder = c(1,1)),
mean.model = list(armaOrder=c(1,0)))
tGarchModel <- ugarchfit(spec.tgarch, data=dl_data)
tGarchModel
vol <- ts(tGarchModel@fit$sigma^2,end = c(2024,1), frequency = 12)
plot(vol, xlab="", ylab="", main="Threshold GARCH Volatility")
plot(ts_data, type = "l", col = "blue", ylab = "Price", xlab = "Time", main = "Comparison of Actual Volatility vs Model Predicted Volatility")
lines(vol, col = "red")
# Add a legend
legend("topright", legend = c("Actual Volatility", "Model Predicted Volatility"), col = c("blue", "red"), lty = 1)
然而,我所做的只是将时间序列数据添加到图中(蓝色),并且不出现红线。另外,传说也出现了。
我不完全确定你想要绘制什么,但假设你想看到陆地上建模波动率的回报,也许是这样的?
spec.tgarch <- ugarchspec(
variance.model = list(
model = "fGARCH",
submodel = "TGARCH",
garchOrder = c(1,1)
),
mean.model = list(armaOrder=c(1,0))
)
tGarchModel <- ugarchfit(spec.tgarch, data=dl_data)
tGarchModel
plt <- plot(
dl_data,
col = "darkgrey",
xlab="",
ylab="",
main="Threshold GARCH Volatility",
grid.col = "lightgrey"
)
plt <- addSeries(sigma(tGarchModel), col = "red", on = 1)
plt <- addSeries(-sigma(tGarchModel), col = "red", on = 1)
plt