使用蒙特卡洛模拟的预测VAR模型
此示例显示了如何通过模拟
预测VAR模型。
模拟
使您能够根据模型生成时间序列的模拟。如果您具有值得信赖的VAR模型对象,则可以将这些模拟用作示例预测。
模拟
要求:
一个模型 (
estmdl
以下内容)预测的期间数(
numobs
以下内容)
模拟
可选的是:
外源数据系列
一个预采样时间序列(
y(End-3:End,:)
以下内容)有条件模拟的未来样本响应
实现或路径的数量来模拟(
2000
以下内容)
加载data_useconmodel
数据集。该示例使用两个时间序列:真实GDP的对数和实际的3个月t-bill率,两者都有差异为大约固定。为了说明,一个VAR(4)模型描述了时间序列。
加载data_useconmodeldef = log(datatable.cpiaucsl);gdp = log(datatable.gdp);rgdp = diff(gdp -def);%真实GDP是GDP-放气tb3 = 0.01*datatable.tb3ms;ddef = 4*diff(def);缩放%rtb3 = tb3(2:end)-ddef;%真正的兴趣被放气y = [RGDP,RTB3];
适合VAR(4)模型规范。
mdl = varm(2,4);mdl.seriesnames = {“转变的真实GDP”,,,,“转变的实际3-MO T-BILL率”};estmdl =估计(MDL,y);
定义预测范围。
numobs = 21;fdates = dateshift(datatable.time(end),'结尾',,,,'四分之一',1:numobs);
模拟模型numobs
前进,并生成2000条路径。从数据末尾指定前样品观测值。
RNG(1);%可再现性ysim =仿真(estmdl,numobs,'y0',y(end-3:end,:),“数字”,2000);
计算出平均值和标准偏差的年代imulated series:
ymean =平均值(YSIM,3);%计算平均值ystd = std(ysim,0,3);%计算性病偏差
绘制模拟序列的均值+/- 1标准偏差:
数字;子图(2,1,1)图(datatable.time(end-10:end),y(end-10:end,1),'K') 抓住('上')图([datatable.time(end)fdates],[y(end,1); ymean(:,1)],'r')图([datatable.time(end)fdates],[y(end,1); ymean(::,1)]+[0; ystd(:,1)],'b')图([datatable.time(end)fdates],[y(end,1); ymean(::,1)] - [0; ystd(:,1)],'b') 标题(“转变的真实GDP”)子图(2,1,2)图(datatable.time(end-10:end),y(end-10:end,2),2),'K') 抓住('上')图([datatable.time(end)fdates],[y(end,2); ymean(:,2)],'r')图([datatable.time(end)fdates],[y(end,2); ymean(::,2)]+[0; ystd(:,2)],'b')图([datatable.time(end)fdates],[y(end,2); ymean(::,2)] - [0; ystd(:,2)],'b') 标题(“转变的实际3-MO T-BILL率”)