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!!
0 个评论
采纳的回答
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!