GARCH model for day-Ahead stock price forecasting

6 次查看(过去 30 天)
Hello. I want to forecast stock market prices one day ahead (i.e 48 prices ahead). In the TrainDatax matrix (50X72) I have the input training data, while in the TrainDatay matrix (50X48) I have the output training data. I want to apply the model for price prediction. Additionally, I want the GARCH model for each row of the training data, i.e. 50 different GARCHs models. Also, the vector TestDatax (1X72) includes the test data. However, in the code below, the testing procedure cannot be done since the dimensions of the matrices are different. How can this problem be solved? Your help is valuable!!!
% GARCH(6,6) Model
garchModel = garch('GARCHLags', 1:6, 'ARCHLags', 1:6, 'Distribution', 't');
% Initialize an array to store GARCH parameters for each row
garchParams = cell(r, 1);
for i = 1:50
% Estimate parameters for each row
garchParams{i} = estimate(garchModel, TrainDatax(i, :)'); % TrainDatax: 50X72
end
% Forecasting
ForecastStock_Values = zeros(50, 48);
for i = 1:50
% Forecasting for each row
[variance, ~] = simulate(garchParams{i}, 48, 'NumPaths', 1);
ForecastStock_Values(i, :) = sqrt(variance(end, :)) .* TestDatax; % TestDatax: 1X72
end
Error message:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
ForecastValues(i, :) = sqrt(variance(end, :)) .* TestDatax;

回答(1 个)

Rishi
Rishi 2023-11-27
Hi Stelios,
I understand from your query that you want to know why you are getting the error and how to solve it.
The error is occurring due to the following line:
ForecastValues(i, :) = sqrt(variance(end, :)) .* TestDatax;
Here, the output of the multiplication is a matrix of size 1x72. The ‘ForecastValues’ matrix has been declared as a matrix of size 50x48, which means that each row only has 48 columns. Hence, when you try to assign the values, it throws an error.
To overcome this, you need to make sure that the matrices are of compatible sizes. This can be done either by making the ‘TestDatax’ matrix of size 1x48 or the ‘ForecastValues’ matrix of size 1x72.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Conditional Variance Models 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by