def simulate(self,B_,s_0,T,sHist=None): ''' Simulates planners policies for T periods ''' Para,Pi,beta = self.Para,self.Pi,self.beta Uc = Para.Uc if sHist == None: sHist = mc_sample_path(Pi,s_0,T) cHist,nHist,Bhist,TauHist,muHist = np.zeros((5,T)) RHist = np.zeros(T-1) #time0 mu,cHist[0],nHist[0],_ = self.time0_allocation(B_,s_0) TauHist[0] = self.Tau(cHist[0],nHist[0])[s_0] Bhist[0] = B_ muHist[0] = mu #time 1 onward for t in range(1,T): c,n,x,Xi = self.time1_allocation(mu) Tau = self.Tau(c,n) u_c = Uc(c,n) s = sHist[t] Eu_c = Pi[sHist[t-1]].dot(u_c) cHist[t],nHist[t],Bhist[t],TauHist[t] = c[s],n[s],x[s]/u_c[s],Tau[s] RHist[t-1] = Uc(cHist[t-1],nHist[t-1])/(beta*Eu_c) muHist[t] = mu return cHist,nHist,Bhist,TauHist,sHist,muHist,RHist
def simulate(self,B_,s_0,T,sHist=None): ''' Simulates Ramsey plan for T periods ''' Para,Pi = self.Para,self.Pi Uc = Para.Uc cf,nf,xprimef = self.policies if sHist == None: sHist = mc_sample_path(Pi,s_0,T) cHist,nHist,Bhist,TauHist,muHist = np.zeros((5,T)) RHist = np.zeros(T-1) #time0 cHist[0],nHist[0],xprime = self.time0_allocation(B_,s_0) TauHist[0] = self.Tau(cHist[0],nHist[0])[s_0] Bhist[0] = B_ muHist[0] = 0. #time 1 onward for t in range(1,T): s,x = sHist[t],xprime[sHist[t]] c,n,xprime = np.empty(self.S),nf[s](x),np.empty(self.S) for shat in range(self.S): c[shat] = cf[shat](x) for sprime in range(self.S): xprime[sprime] = xprimef[s,sprime](x) Tau = self.Tau(c,n)[s] u_c = Uc(c,n) Eu_c = Pi[sHist[t-1]].dot(u_c) muHist[t] = self.Vf[s](x,1) RHist[t-1] = Uc(cHist[t-1],nHist[t-1])/(self.beta*Eu_c) cHist[t],nHist[t],Bhist[t],TauHist[t] = c[s],n,x/u_c[s],Tau return cHist,nHist,Bhist,TauHist,sHist,muHist,RHist
def mc_sample_path(P, init, sample_size): return mc_tools.mc_sample_path(P, init, sample_size)