Demo entry 6344551

termpaper

   

Submitted by anonymous on Jan 15, 2017 at 16:56
Language: Matlab. Code size: 1.2 kB.

%% Exercise 1 %%
X = data(:,1);
Y = data(:,2:end);
T = length(X);
K = 100;

beta_exercise_1 = zeros(K,1);
for i = 1:K;
    beta_exercise_1(i) = (X'*X)^-1 * X' * Y(:,i);
end;

plot(beta_exercise_1)

beta_sorted=sort(beta_exercise_1);

%% Exercise 2 %%
constant = ones(T,1);
beta_exercise_2 = zeros(K,2);
for i = 1:K;
    beta = ([constant X]' * [constant X])^-1 * [constant X]' * Y(:,i);
    beta_exercise_2(i,:) = beta';
end;

t_statistics_beta=zeros(K,2); 
for j = 1:2; 
    for i = 1:K; 
        beta = ([constant X]' * [constant X])^-1 * [constant X]' * Y(:,i);
        u = Y(:,i) - [constant X] * beta;
        variance = 1/T * u' * u;
        beta_variance = variance * ([constant X]' * [constant X])^-1;
        t_statistics_beta(i,j) = beta_exercise_2(i,j) / sqrt(beta_variance(j,j));
    end;
end;

significant_alpha = t_statistics_beta(:,1);
for i=1:K;
    if significant_alpha(i) < 1.96 & significant_alpha(i) > -1.96;
        significant_alpha(i) = 0;
    end;
end;

percentage_significant = sum(significant_alpha > 0) / K * 100

bar(t_statistics_beta(:,1));
xlim([0 100])
line(xlim,[1.96 1.96 ], 'Color', 'b')

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).