def get_quadstates(poly, paramplus): #returns exogenous states at each quadrature point and each exogenous grid point ninnov = poly['ninnov'] nqs = poly['nqs'] ns = poly['ns'] npoly = poly['npoly'] ne = ninnov quadgrid, quadweight = po.get_quadgrid(poly['nquad'], ninnov, nqs) if poly['ne'] == 0: nchebexog = np.prod(poly['ncheb'][2:]) pgridexog = poly['pgrid'][:nchebexog, 2:poly['nmsv']] ns = nchebexog exoggrid = np.zeros([nchebexog, poly['nmsv'] - 2]) exogscxx2msv = poly['scxx2msv'][2:poly['nmsv'] * 2:poly['nmsv']] for i in np.arange(ns): exoggrid[i, :] = po.msv2xx(pgridexog[i, :], poly['nmsv'] - 2, exogscxx2msv) else: exoggrid = poly['exoggrid'] sfut = np.zeros([ns, nqs, ninnov]) ind_sfut = np.zeros([ns, nqs, ne], dtype=int) for j in np.arange(nqs): for i in np.arange(ns): if poly['shockswitch'] == 0: sfut[i, j, 0] = paramplus['rhobeta'] * exoggrid[ i, 0] + paramplus['stdbeta'] * quadgrid[j, 0] if ninnov == 2: sfut[i, j, 1] = paramplus['rhomu'] * exoggrid[ i, 1] + paramplus['stdmu'] * quadgrid[j, 1] else: sfut[i, j, 0] = paramplus['rhomu'] * exoggrid[ i, 0] + paramplus['stdmu'] * quadgrid[j, 0] if ninnov == 2: sfut[i, j, 1] = paramplus['rhobeta'] * exoggrid[ i, 1] + paramplus['stdbeta'] * quadgrid[j, 1] if poly['ne'] > 0: ind_sfut[i, j, :] = po.get_index(sfut[i, j, :], ninnov, poly['ngrid'], poly['steps'], poly['bounds']) return (sfut, ind_sfut, quadweight)
def decr(endogvarm1, innov, paramplus, acoeff, poly): #decision rule with variables in levels and deviation from steady state. endogvar = {} kk = endogvarm1['kp_d'] invm1 = endogvarm1['inv_d'] shocks = np.zeros(poly['ne']) if poly['shockswitch'] == 0: shocks[0] = paramplus['rhobeta'] * endogvarm1['beta_d'] + paramplus[ 'stdbeta'] * innov[0] if poly['ne'] == 2: shocks[1] = paramplus['rhomu'] * endogvarm1['mu_d'] + paramplus[ 'stdmu'] * innov[1] else: shocks[0] = paramplus['rhomu'] * endogvarm1['mu_d'] + paramplus[ 'stdmu'] * innov[0] if poly['ne'] == 2: shocks[1] = paramplus['rhobeta'] * endogvarm1[ 'beta_d'] + paramplus['stdbeta'] * innov[1] if (poly['ne'] == 0): msvm1 = np.array([kk, invm1, shocks[0]]) xx1 = po.msv2xx(msvm1, poly['nmsv'], poly['scmsv2xx']) poly_xx = chebpolytensor(xx1, poly['nmsv'], poly['npoly'], poly['ncheb']) for ifunc in np.arange(nfunc): polycur[ifunc] = np.dot( acoeff[0, ifunc * poly['npoly']:(ifunc + 1) * poly['npoly']], poly_xx) else: msvm1 = np.array([kk, invm1]) ind_shocks = po.get_index(shocks, poly['ne'], poly['ngrid'], poly['steps'], poly['bounds']) xx1 = po.msv2xx(msvm1, poly['nmsv'], poly['scmsv2xx']) polycur = po.get_linspline(xx1,shocks,ind_shocks,acoeff,poly['exoggrid'],poly['steps'],poly['nfunc'],\ poly['ngrid'],poly['npoly'],poly['nmsv'],poly['ncheb'],poly['ne']) (dvar, lvar) = modelvariables(polycur, msvm1, shocks, paramplus, poly['eqswitch'], poly['shockswitch'], poly['ne']) for x in lvar: endogvar[x] = lvar[x] endogvar[x + '_d'] = dvar[x] return (endogvar)
def decr(endogvarm1, innov, regime, acoeff, poly, params): endogvar = np.zeros(poly['nvars']) ne = poly['nexog_fe'] npoly = poly['npoly'] nmsv = poly['nmsv'] nmsve = poly['nexog_nmsv'] nsreg = poly['nsreg'] nx = nmsv - nmsve - (nsreg - 1) ss = np.zeros(ne + nmsve) msvm1 = np.zeros(nmsv) shocks = np.zeros(ne + 1) #update non-monetary shocks and compute place on grid endogvar[ -6] = params['rhoeta'] * endogvarm1[-4] + params['stdeta'] * innov[0] ss[0] = endogvar[-6] ind_ss = po.get_index(ss, ne, poly['ngrid'], poly['steps'], poly['bounds']) ss[1] = poly['gamma0'][regime] + params['stdm'] * innov[1] endogvar[-3] = ss[1] endogvar[-4] = params['stdm'] * innov[1] endogvar[-5] = poly['gamma0'][regime] msvm1[:nx + nsreg - 1] = endogvarm1[:nx + nsreg - 1] msvm1[nx + nsreg - 1] = ss[1] xxm1 = po.msv2xx(msvm1, nmsv, poly['scmsv2xx']) polycur = po.get_linspline(xxm1, ss[:ne], ind_ss, acoeff, poly['exoggrid'], poly['steps'], poly['nfunc'], poly['ngrid'], npoly, nmsv, ne) (yy, dp, nr, lptp, post) = modelvariables(polycur, msvm1[:nmsv - nmsve], ss, params, nmsv, nmsve, nsreg, poly['gamma0'], poly['P']) endogvar[-2] = polycur[0] endogvar[-1] = polycur[1] endogvar[0] = nr endogvar[1] = yy endogvar[2] = dp if nsreg == 2: endogvar[nx] = lptp else: endogvar[nx:nx + nsreg - 1] = lptp endogvar[nx + nsreg - 1:nx + 2 * nsreg - 1] = post return (endogvar)
def get_quadstates(poly, params): #returns exogenous states at each quadrature point and each exogenous grid point ninnov = poly['ninnov'] nqs = poly['nqs'] ns = poly['ns'] npoly = poly['npoly'] ne = poly['nexog_fe'] quadgrid, quadweight = po.get_quadgrid(poly['nquad'], ninnov, nqs) sfut = np.zeros([ns, nqs, ninnov]) ind_sfut = np.zeros([ns, nqs, ne], dtype=int) for i in np.arange(ns): for j in np.arange(nqs): sfut[i, j, :ne] = poly['rhos'][:ne] * poly['exoggrid'][ i, :] + poly['stds'][:ne] * quadgrid[j, :ne] sfut[i, j, ne] = params['stdm'] * quadgrid[j, ne] ss = sfut[i, j, :ne] ind_sfut[i, j, :] = po.get_index(ss, ne, poly['ngrid'], poly['steps'], poly['bounds']) return (sfut, ind_sfut, quadweight)
def get_quadstates(poly, paramplus): #returns exogenous states at each quadrature point and each exogenous grid point ninnov = poly['ninnov'] nqs = poly['nqs'] ns = poly['ns'] npoly = poly['npoly'] ne = ninnov quadgrid, quadweight = po.get_quadgrid(poly['nquad'], ninnov, nqs) sfut = np.zeros([ns, nqs, ninnov]) ind_sfut = np.zeros([ns, nqs, ne], dtype=int) #meanpreserve = -paramplus['stdbeta']**2/(2*(1.0+paramplus['rhobeta'])) #print(meanpreserve) for j in np.arange(nqs): for i in np.arange(ns): sfut[i, j, 0] = paramplus['rhobeta'] * poly['exoggrid'][ i, 0] + paramplus['stdbeta'] * quadgrid[j, 0] #+ meanpreserve if ne == 2: sfut[i, j, 1] = paramplus['rhomu'] * poly['exoggrid'][ i, 1] + paramplus['stdmu'] * quadgrid[j, 0] ind_sfut[i, j, :] = po.get_index(sfut[i, j, :], ne, poly['ngrid'], poly['steps'], poly['bounds']) return (sfut, ind_sfut, quadweight)