Hello! I am having a problem with discrete indexing. I want to run the code below for the 4 values of T specified in the matrix, but what the code actually does is run it 80 times with T=0 where I did not specify a value. This slows down my computation extremely because the real code includes some other operation (I am running a Monte Carlo experiment). Is there a way to do the loop ONLY with the 4 values of T specified? Thank you in advance!
clear
clc
rng('default')
runs = 10000;
alpha_0 = -0.8;
w(1) = 0;
for T = 10*2.^(0:3)
for i = 1:runs
for t = 1:T
if t > 1
epsilon(t) = normrnd(0,1);
w(t) = alpha_0 * w(t-1) + epsilon(t);
end
end
X = w(1:T-1);
Y = w(2:T);
alpha(i) = inv(X*X')*X*Y';
zed(i) = sqrt(T)*(alpha(i)-alpha_0);
lambda(i) = inv(T)*(epsilon*epsilon');
test(i) = (alpha(i) - alpha_0)* inv(T);
qz = quantile(zed, [0.005 0.01 0.025 0.05 0.10 0.25 0.50 0.75 0.90 0.95 0.975, 0.99, 0.995]);
qt = quantile(zed, [0.005 0.01 0.025 0.05 0.10 0.25 0.50 0.75 0.90 0.95 0.975, 0.99, 0.995]);
end
alphaa(:,T) = alpha';
zeda(:,T) = zed';
lambdaa(:,T) = lambda';
test(:,T) = t;
end