关于matlab循环计算的问题:本来结果应该都是数值,但是有些出现了NaN,不知是否是程序的问题?
loadF:\b1.txt%文本中的数据都为数值型ri=b1(:,1);rm=b1(:,2);fori=61:length(ri);ari(i)=mean(ri(i-60...
load F:\b1.txt%文本中的数据都为数值型
ri=b1(:,1);
rm=b1(:,2);
for i=61:length(ri);
ari(i)=mean(ri(i-60):ri(i-1));%求过去5年(即60个月)的均值
arm(i)=mean(rm(i-60):rm(i-1));%求过去5年(即60个月)rm的均值
fz1(i-60)=(ri(i-60)-ari(i))*(rm(i-60)-arm(i));
fm1(i-60)=rm(i-60)-arm(i);
zfm1(i-60)=fm1(i-60)*fm1(i-60);
fz2(i-60)=(ri(i-60)-ari(i))*(rm(i-60)-arm(i))^2;
fm2(i-60)=(rm(i-60)-arm(i))^3;
zfm2(i-60)=fm2(i-60);
for t=i-59:i-1
fz1(t)=fz1(t-1)+(ri(t)-ari(i))*(rm(t)-arm(i));%分子
fm1(t)=rm(t)-arm(i);
zfm1(t)=zfm1(t-1)+fm1(t)*fm1(t);
fz2(t)=fz2(t-1)+(ri(t)-ari(i))*(rm(t)-arm(i))^2;
fm2(t)=(rm(t)-arm(i))^3;
zfm2(t)=zfm2(t-1)+fm2(t);
end
beta(i)=fz1(i-1)/zfm1(i-1);
gamma(i)=fz2(i-1)/zfm2(i-1);
end
beta
gamma
beta和gamma的具体计算公式如下 展开
ri=b1(:,1);
rm=b1(:,2);
for i=61:length(ri);
ari(i)=mean(ri(i-60):ri(i-1));%求过去5年(即60个月)的均值
arm(i)=mean(rm(i-60):rm(i-1));%求过去5年(即60个月)rm的均值
fz1(i-60)=(ri(i-60)-ari(i))*(rm(i-60)-arm(i));
fm1(i-60)=rm(i-60)-arm(i);
zfm1(i-60)=fm1(i-60)*fm1(i-60);
fz2(i-60)=(ri(i-60)-ari(i))*(rm(i-60)-arm(i))^2;
fm2(i-60)=(rm(i-60)-arm(i))^3;
zfm2(i-60)=fm2(i-60);
for t=i-59:i-1
fz1(t)=fz1(t-1)+(ri(t)-ari(i))*(rm(t)-arm(i));%分子
fm1(t)=rm(t)-arm(i);
zfm1(t)=zfm1(t-1)+fm1(t)*fm1(t);
fz2(t)=fz2(t-1)+(ri(t)-ari(i))*(rm(t)-arm(i))^2;
fm2(t)=(rm(t)-arm(i))^3;
zfm2(t)=zfm2(t-1)+fm2(t);
end
beta(i)=fz1(i-1)/zfm1(i-1);
gamma(i)=fz2(i-1)/zfm2(i-1);
end
beta
gamma
beta和gamma的具体计算公式如下 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询