have the following code but can not get the value of the forecast because it tells me I have exceeded the bounds of the array ... can someone help me?

in the vector data loading data loading them and I'm sure everyone ...

pdf with all the steps that this function should be found is here:

SSRN-An Algorithm Using GARCH Process, Monte-Carlo Simulation and Wavelets Analysis for Stock Prediction by Eleftherios Giovanis

clc, clear, close all;
% Load input data
load ( 'c: \ file.mat', '-mat');
% T is the number of the days
T = length (data);
% We consider a random permutation of days
ord = randperm (T);
% We consider half-days of our first data for simulation
FirstSample = (T / 2);
% We consider the remaining days for second simulation
secondsample = T-(FirstSample);
% From FirstSample days we consider 10 randomly selected date
firstPoint = 10;
% From secondsample days we consider 10 randomly selected date
secondpoint = 10;
% We consider the simulation parameters
N = 32;% length of input data
M = 1,% length of the predicted date
% We decompose our data with function db3
[DD] = dwt (data (1: FirstSample), 'db3');
% We define GARCH (1,1) process
[Kappa, Alpha, Beta] = ugarch (dd, 1, 1)
% We Set the random number generator seed for reproducability
randn ( 'seed', 10)
NumSamples = FirstSample;
% We simulated the process with Monte Carlo
[U, H] = ugarchsim (Kappa, Alpha, Beta, NumSamples);
% Length of vector
V = 1;
% From current day we extract randomly selected date firstPoint
currentprice = randperm (V + N-M);
currentprice = currentprice + N;
for j = 1: firstPoint
Y1 = currentprice (j);
Y0 = Y1-N +1;
p = U (Y0: Y1);
p = p (;
Y (1, = p (1,;
pred = U (Y1 +1: Y1 + M);
end
% We decompose our data with function db3
[DD1] = dwt (date (FirstSample +1: + FirstSample secondsample), 'db3')
% We define GARCH (1,1) process
[Kappa, Alpha, Beta] = ugarch (dd1, 1, 1)
% We Set the random number generator seed for reproducability
randn ( 'seed', 10)
NumSamples = secondsample;
% We simulated the process with Monte Carlo
[J, H] = ugarchsim (Kappa, Alpha, Beta, NumSamples);
V = 1;
% From current day we extract randomly selected date secondpoint
currentprice = randperm (V + N-M);
currentprice = currentprice + N;
for j = 1: secondpoint
W1 = currentprice (j);
W0 = W1-N +1;
p = J (W0: W1);
p = p (;
W (1, = p (1,;
pred = J (W1 +1: W1 + M);
end

can someone help me to traslate it into a function??

thanks a lot