1-step ahead forecast VECM

1 次查看(过去 30 天)
Niccolò Ghionzoli
Niccolò Ghionzoli 2022-3-26
回答: Jasvin 2024-1-22
Hi to everybody!
Do you know how to do 1-step ahead forecasts in VAR or in VEC models?
Please find below an example I am trying to do in VEC. How to transform it into 1-step ahead? Because this code produces strange results. I found no resources to do it on the net.
%forecast 1-step ahead from 1 to 120
for i=1:120
numperiods = i;
initial_data = UKDATA_2; %216 observations
[forecast_data_vecm, forecast_data_MSE_vecm] = forecast(Mdl,numperiods,initial_data,'X',EXOG);
fh = dateshift(dates(217),'start','month',1:120);
end
I've also tried to adapt this code ion this MATLAB webpage to my scope:
My code stops just at 1 step ahead.
I mean, instead of quarterly basis, how to do a 1-step ahead forecast on a monthly basis for 10 years?
% Y = UKDATA; % Work directly with the timetable %336 obs
% T0 = datetime(2002,12,1); % Initialize forecast origin
% T = T0;
% horizon = 1; % Forecast horizon in months (12 months = 1 year)
% numForecasts = numel(T:calmonths(1):dates(end)) - horizon; %check for monthly interval
% yForecast = nan(numForecasts, horizon, Mdl.NumSeries);
%
% %
% for t = 1:numForecasts
% %
% % Get the end-of-month dates for the current forecast origin.
% %
% %monthlyDates = dates(2):calmonths(1):T; %check for monthly interval
% %
% % Estimate the VEC model %already done
% %
% % Forecast the model at each monthly out to the forecast horizon.
% %
% % Store the forecasts for the current origin (T) as a 3-D array in which
% % the 1st page stores all forecasts for the 1st series (r1), the 2nd page
% % stores all forecasts for the 2nd series (r24), and so forth. This
% % storage convention facilitates the access of data from the timetable
% % of forecasts created below.
% %
% yForecast(t,:,:) = forecast(Mdl, horizon, Y(2:1:217,4:7)); %make a forecast only for four interest rates
% %
% % Update the forecast origin to include the data of the next month.
% %
% T = dateshift(T, 'end', 'month', 'next');
% end
%
% originDates = dateshift(T0, 'end', 'month', (0:(numForecasts-1))');
% forecastDates = NaT(numForecasts,horizon);
% for i = 1:horizon
% forecastDates(:,i) = dateshift(originDates, 'end', 'month', i);
% end
%
% Forecast = timetable(forecastDates,'RowTimes',originDates, 'VariableNames', {'Times'});
% for i = 1:size(Y,2)
% Forecast.(Mdl.SeriesNames{1,i}) = yForecast(:,:,i); %check again
% end
%
% %plot actual vs. forecast
% % (y - yhat) % Errors
% % (y - yhat).^2 % Squared Error
% % mean((y - yhat).^2) % Mean Squared Error
% RMSE = sqrt(mean((r1(217:336) - Forecast.r1).^2)); % Root Mean Squared Error
%
% figure;
% subplot(2,1,1)
% plot(Forecast.Times, Forecast.r1, 'r') %check again the variable and time
% hold on
% plot(Forecast.Times, r1(217:336), 'b')
% title('r1 vs. Forecast r1: 1-month-ahead')
% xlabel('Time');
% ylabel('r1')
% h = legend('Forecast','Actual','Location','Best');
% h.Box = 'off';
Best regards, Niccolò Ghionzoli

回答(1 个)

Jasvin
Jasvin 2024-1-22
Hi Niccolo,
So it looks like you are on the right track as per the code you have shared and the documentation page you have linked.
There's two things that stand out to me in the commented code you shared:
% For your code you have written it as,
horizon = 1; % Forecast horizon in months (12 months = 1 year)
% The documentation page writes it as,
horizon = 4; % Forecast horizon in quarters (4 = 1 year)
However as per your use-case you want monthly one-step ahead forecasting, so shouldn't the "horizon" variable be set to 12?
Or because you want to forecast on a monthly-basis for 10 years, "horizon" should be 12*10 = 120 instead.
And I don't know if I have missed it but I don't see a section in your code that accounts for one-step ahead forecasting, is this already accounted by the functions that are being called or something that must be handled by the user themselves is something that I am not too sure on, have a double-check at this as well.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Commercial & Off-Highway Vehicles 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by