Adding a extra variable to a model

2 次查看(过去 30 天)
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!!

采纳的回答

Matt J
Matt J 2013-6-12
编辑:Matt J 2013-6-12
>> 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.

更多回答(1 个)

Kevin van Berkel
Kevin van Berkel 2013-6-12
Thanks Matt! Solved it.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by