好的
附件前几页是作者给的代码
最后面加上资产价格是我自己设的代码
我需要跑出跟chap7 一样的图来
再麻烦高手了
Behaviormodel
pstar=0
a1=0.5 %coefficient of expected output inoutput equation
a2=-0.2 %a2 is the interest elasticity ofoutput demand
b1=0.5 %b1 is coefficient of expectedinflation in inflation equation
b2=0.05 %b2 is coefficient of output in inflationequation
c1=1.5 %c1 is coefficient of inflation inTaylor equation
c2=0.5 %c2 is coefficient of output inTaylor equation
c3=0.5 %interest smoothing parameter inTaylor equation
beta=1
delta=2
gamma=1
sigma1=0.5 %standard deviation shocks output
sigma2=0.5 %standard deviation shocksinflation
sigma3=0.5 %standard deviation shocks Taylor
rho=0.5
mm=1 %switching parameter gamma in BrockHommes
pstar=0 % the central bank's inflationtarget
eprational=0 % if all agents have rational forecast ofinflation this parameter is 1
epextrapol=0 % if all agents use inflation extrapolationthis parameter is 1
A=[1 -b2;-a2*c11 -a2*c2]
A=[1 -b2;-a2*c1 1-a2*c2]
B=[b1 0;-a2 a1]
C=[1-b1 0;0 1-a1]
T=2000
TI=250
K=50 %length of period to computedivergence
rho=0.5
rhoout=0.0
rhoinf=0.0
rhotayl=0.0
rhoBH=0.0
epfs=pstar
p=zeros(T,1)
y=zeros(T,1)
plagt=zero(T,1)
plagt=zeros(T,1)
ylagt=zeros(T,1)
r=zeros(T,1)
epf=zeros(T,1)
epc=zeros(T,1)
ep=zeros(T,1)
ey=zeros(T,1)
CRp=zeros(T,1)
FRp=zeros(T,1)
alfapt=zeros(T,1)
eyfunt=zeros(T,1)
CRy=zeros(T,1)
FRy=zeros(T,1)
alfayt=zeros(T,1)
anspirits=zeros(T,1)
epsilont=zeros(T,1)
etat=zeros(T,1)
ut=zeros(T,1)
alfap=0.5
alfay=0.5
K1=K+1
for t=2:T
epsilont(t)=rhoout*epsilont(t-1) +sigma1*randn %shocks in output equation (demand shock)
etat(t)=rhoinf*etat(t-1)+ sigma2*randn %shocksin inflation equation (supply shock)
ut(t)=rhotayl*ut(t-1)+sigma3*randn %shocksin Taylor rule (interest rate)
epsilon=epsilont(t)
u=ut(t)
shocks=[eta;as*u+epsilon]
epcs=p(t-1)
if eprational==1
eps=p(t-1)
end
eps=alfap*epcs+(1-alfap)*epfs
epcs
epcs=p(t-1)
for t=2:T
epcs=p(t-1)
eps=alfap*epcs+(1-alfap)*epfs
if epextrapol==1
eps=p(t-1)
end
eychar
eychar=y(t-1)
eyfun=0+randn/2
eyfunt(t)=eyfun
eys=alfay*eychar+(1-alfay)*eyfun
forecast=[eps;eys]
plag=p(t-1)
ylag=y(t-1)
rlag=r(t-1)
lag=[plag;ylag]
smooth=[0;a2*c2]
D=B*forecast+C*lag+smooth*rlag+shocks
X = A\D
p(t)= X(1,1)
y(t)= X(2,1)
r(t)= c1*p(t)+c2*y(t)+c3*r(t-1)+u
if square==1
r(t)= c1*(p(t))^2+c2*y(t)+c3*r(t-1)+u
end
plag(t)=p(t-1)
ylag(t)=y(t-1)
CRp(t)=rho*CRp(t-1) - (1-rho)*(epcs-p(t))^2
FRp(t)=rho*FRp(t-1) - (1-rho)*(epfs-p(t))^2
CRy(t)=rho*CRy(t-1) -(1-rho)*(eychar-y(t))^2
FRy(t)=rho*FRy(t-1) -(1-rho)*(eyfun-y(t))^2
alfap=(rhoBH*alfapt(t-1)+(1-rhoBH)*exp(mm*CRp(t)))/(exp(mm* CRp(t))+exp(mm*FRp(t)))
alfay=(rhoBH*alfayt(t-1)+(1-rhoBH)*exp(mm*CRy(t)))/(exp(mm* CRy(t))+exp(mm*FRy(t)))
alfapt(t)=alfap
alfayt(t)=alfay
if eychar>0
anspirits(t)=alfay
end
eychar=y(t-1)
if eychar>0
anspirits(t)=alfay
end
if eychar<0
anspirits(t)=1-arfay
end
autocory=corrcoef(y,ylagt)
autocorp=corrcoef(p,plagt)
coroutanimal=corr(y,anspirits)
coroutanimal=corrcoef(y,anspirits)
kurt=kurtosis(y)
[jb,pvalue,jbstat]=jbtest(y,0.05)
来源
http://www.econ.kuleuven.be/ew/academic/intecon/Degrauwe/PDG-papers/Contributions%20to%20books/Behavioral%20Macro%20Book-Fin.pdf