Adding a extra variable to a model
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys,
I have the following model:
function [R_e, dp] = VAR_CRSP(M,T,r_f);
epsilon = zeros(M,T,2);
r = zeros(M,T);
dp= zeros(M,T);
for m=1:M
epsilon(m,:,:,: ) = mvnrnd([0;0;0], [0.0012,-0.001;-0.001,0.0027],T)
end
for m=1:M
dp0=-3.461;
r(m,1) = 0.1161+0.060*dp0 + epsilon(m,1,1);
dp(m,1)=-0.052+0.9702*dp0 + epsilon(m,1,2);
for i = 1:T-1
r(m,i+1) = 0.1161+0.060*dp(m,i) + epsilon(m,i+1,1);
dp(m,i+1) = -0.052+0.9702*dp(m,i) + epsilon(m,i+1,2);
end
end
end
Now i want to add a extra variable to the model. I did it as simply as this, but I don't think it's the correct way:
function [R_e, dp] = VAR_CRSP(M,T,r_f);
epsilon = zeros(M,T,3);
r = zeros(M,T);
dp= zeros(M,T);
mom=zeros(M,T);
for m=1:M
epsilon(m,:,:,: ) = mvnrnd([0;0;0], [0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001],T)
end
for m=1:M
dp0=-3.461;
r(m,1) = 0.1161+0.060*dp0 + epsilon(m,1,1);
dp(m,1)=-0.052+0.9702*dp0 + epsilon(m,1,2);
mom(m,1)=-0.344+0.966*dp0 + epsilon(m,1,3);
for i = 1:T-1
r(m,i+1) = 0.1161+0.060*dp(m,i) + epsilon(m,i+1,1);
dp(m,i+1) = -0.052+0.9702*dp(m,i) + epsilon(m,i+1,2);
mom(m,i+1) = -0.533+0.931*dp(m,i) + epsilon(m,i+1,3);
end
end
R_e = r_f*exp(r)-r_f;
end
My first error is:
Error using mvnrnd (line 110)
SIGMA must be a symmetric positive semi-definite matrix.
Error in VAR_CRSP (line 9)
epsilon(m,:,:,:) = mvnrnd([0;0;0], [0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001],T)
So anyone knows how to resolve this?
Many thanks in advance!!
0 commentaires
Réponse acceptée
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!