アットウィキロゴ

あせ

import java.awt.*;
import java.awt.event.*;
class dsge03 extends Frame {
    public static void main(String [] args) {
        Frame f=new dsge03();
        f.setTitle("Aiyagari Christiano Eichenbaum(1992)");
        f.setSize(700,700);
        f.setBackground(Color.yellow);
        f.setVisible(true);
    }

dsge03(){addWindowListener(new stopwin());}
class stopwin extends WindowAdapter{
    public void windowClosing(WindowEvent we){System.exit(0);}
    }

public void paint(Graphics g){
double maxc,minc,maxk,mink;
double ct[]=new double[101];  
int cp[]=new int[101];
double a;
double beta;
double ks;
double h;
double th[]=new double[11];
double k[]=new double[101];
double cx[][]=new double[11][101];
double cxs[][]=new double[11][101];
double lx[][]=new double[11][101];
double lxs[][]=new double[11][101];
double k1;
double n1;
int n2;
int n3;
int n;
double c1;
double r1;
double ep;
double ls;
double l1;
double w1;
int t;
int m;
int mx;
double uc;  
for (m=1;m<11;m++){
th[m]=0.01*m;
}
a=0.33;
beta=0.95;
ls=(1-a)/(2-a);
ks=ls*Math.pow((1 / beta - 1) / a , 1 / (a - 1));
h=2*ks/100;
for (n=1;n<101;n++){
k[n]=n*h;
for (m=1;m<11;m++){
lx[m][n]=ls;
cx[m][n]=Math.pow(k[n],a)*Math.pow(lx[m][n],1-a);
}
}
t=0;
while(t<100){
for (m=1;m<11;m++){
for (n=10;n<91;n++){
k1=k[n]+Math.pow(k[n],a)*Math.pow(lx[m][n],1-a)-cx[m][n]-th[m];
n1=k1/h;
n2=(int)n1;
n3=n2+1;
uc=0;
for (mx=1;mx<11;mx++){
c1=cx[mx][n2]+(n1-n2)*(cx[mx][n3]-cx[mx][n2]);
l1=lx[mx][n2]+(n1-n2)*(lx[mx][n3]-lx[mx][n2]);
r1=a*Math.pow(k1,a-1)*Math.pow(l1,1-a);
uc=uc+(beta*(1+r1))/c1;
}
uc=0.1*uc;
cxs[m][n]=1/uc;
w1=(1-a)*Math.pow(k[n],a)*Math.pow(lx[m][n],-a);
lxs[m][n]=1-cx[m][n]/w1;
}
}
ep=0;
for (m=1;m<11;m++){
for (n=10;n<91;n++){
ep=ep+Math.pow(cx[m][n]-cxs[m][n],2)+Math.pow(lx[m][n]-lxs[m][n],2);
}
}
for (m=1;m<11;m++){
for (n=10;n<91;n++){
cx[m][n]=cxs[m][n];
lx[m][n]=lxs[m][n];
}
}
if (ep<0.0001){
t=1000;
}
t=t+1;
}


k1=k[50];
for (t=1;t<100;t++){
m=(int)(10*Math.random())+1;
n1=k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[m][n2]+(n1-n2)*(cx[m][n3]-cx[m][n2]);
l1=lx[m][n2]+(n1-n2)*(lx[m][n3]-lx[m][n2]);
k1=k1+Math.pow(k1,a)*Math.pow(l1,1-a)-c1-th[m];
ct[t]=c1;
}


maxc=-999;
for (t=1;t<100;t++){
if (ct[t]>maxc)maxc=ct[t];
}

minc=999;
for (t=1;t<100;t++){
if (ct[t]<minc)minc=ct[t];
}


for (t=1;t<100;t++){
cp[t]=(int)(500*(ct[t]-minc)/(maxc-minc));
}

g.setColor(Color.green);
g.drawString("消費",50,400);
g.drawString("期間",400,650);
g.setColor(Color.red);  
g.drawLine(100,100,100,600);
g.drawLine(100,600,600,600);  
g.setColor(Color.blue);
for (t=1;t<99;t++){
g.drawLine(100+5*t,600-cp[t],105+5*t,600-cp[t+1]);
}  


}
}
最終更新:2011年01月28日 07:44