Adding a extra variable to a model

2 vues (au cours des 30 derniers jours)
Kevin van Berkel
Kevin van Berkel le 12 Juin 2013
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!!

Réponse acceptée

Matt J
Matt J le 12 Juin 2013
Modifié(e) : Matt J le 12 Juin 2013
>> SIGMA=[0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001];
>> eig(SIGMA)
ans =
-0.0001
0.0016
0.0034
As you can see, your SIGMA matrix has a negative eigenvalue, and is therefore not positive semi-definite.

Plus de réponses (1)

Kevin van Berkel
Kevin van Berkel le 12 Juin 2013
Thanks Matt! Solved it.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by