Azzera filtri
Azzera filtri

how to forecast and plot 1-step for a Log Spot Price (in expanding window)?

3 visualizzazioni (ultimi 30 giorni)
This is what I have so far, i'm not sure how to plot the 1-step forecasts and the actual values of the log spot price
%% Load data
Q1_Crypto = readtable("Q1_Crypto.xlsx"); % Reads excel file as table
t = Q1_Crypto.Dates;
%% 9. Re-estimate model until 09/2021 and forecast 1-step for LogS - in expanding window scheme
% Find the sample period: "10142:11529" chooses the period from 09/2021 to 11/2021
t1 = yyyymmdd(t); % convert datetime to array with numbers
t1_sample = t1(10142:11529,1); % get sample period
LogS_sample = LogS(10142:11529,1);
% LogS (log spot price) has been previously calculated hence it is not included.
%forecast 1-step for LogS with expanding window
%more for sample period but this is for forecasting
T1 = size(t1,1);
t1_sample_EstWind = size(t1_sample,1);
mdf = arima(1, 0, 0) ;
frc = zeros(T1 - t1_sample_EstWind + 1, 1);
msfe = zeros(T1 - t1_sample_EstWind + 1, 1);
k = 1 ; % Just an indexing variable
%the forecast scheme (recursive) and expanding window
tic
for i = t1_sample : T1
esf = estimate(mdf, LogS(1 : i), 'display', 'off');
[frc(k), msfe(k)] = forecast(esf, 1, LogS(1 : i));
k = k + 1;
end
toc
If above is correct, then need to plot the Log Spot price with 1 step forecast which im not sure of

Risposte (1)

Gyan Vaibhav
Gyan Vaibhav il 10 Nov 2023
Hi Sharad,
I understand that you want to forecast and plot 1-step Log Spot price and then plot the 1-step forecast and the actual values of the log spot price.
Yes, the code that you have shared above seems correct for 1-step forecast using the expanding window scheme.
Here is how you can plot the actual Log Spot Prices and the 1-step forecasts on the same graph, giving a comparative view of how well the forecast prices meet the actual prices.
%% Plot the actual LogS and 1-step forecast
figure
plot(t1_sample, LogS_sample, 'Color', 'blue')
hold on
plot(t1_sample, frc, 'Color', 'red')
legend('Actual LogS', '1-step forecast')
title('Actual and 1-step forecast of Log Spot Price')
xlabel('Date')
ylabel('Log Spot Price')
hold off
The above code can be included below the existing code and it should give the expected plot. Refer to the following documentation for knowing more about how to plot data in MATLAB.
Hope this helps.
Thanks
Gyan

Community Treasure Hunt

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

Start Hunting!

Translated by