def get_griddetails(poly, paramplus): #Return details of polynomial associated with constructing the grids used nmsv = poly['nmsv'] poly['scmsv2xx'] = np.zeros([2 * nmsv]) poly['scxx2msv'] = np.zeros([2 * nmsv]) poly['scmsv2xx'][0:nmsv] = 2.0 / (poly['msvbounds'][nmsv:2 * nmsv] - poly['msvbounds'][0:nmsv]) poly['scmsv2xx'][nmsv:2 * nmsv] = -2.0 * poly['msvbounds'][0:nmsv] / ( poly['msvbounds'][nmsv:2 * nmsv] - poly['msvbounds'][0:nmsv]) - 1.0 poly['scxx2msv'][0:nmsv] = 0.5 * (poly['msvbounds'][nmsv:2 * nmsv] - poly['msvbounds'][0:nmsv]) poly['scxx2msv'][nmsv:2 * nmsv] = poly['msvbounds'][0:nmsv] + 0.5 * ( poly['msvbounds'][nmsv:2 * nmsv] - poly['msvbounds'][0:nmsv]) #for the approximating function. poly['rhos'][0] = paramplus['rhobeta'] poly['stds'][0] = paramplus['stdbeta'] if poly['ne'] == 2: poly['rhos'][1] = paramplus['rhomu'] poly['stds'][1] = paramplus['stdmu'] poly['exoggrid'],poly['exogindex'],poly['steps'],poly['bounds'],poly['ind2poly'] = po.get_exoggrid(poly['ngrid'],poly['ne'], \ poly['ns'],poly['rhos'],poly['stds'],poly['maxstd']) #meanspread = -paramplus['stdbeta']**2/(2*(1.0+paramplus['rhobeta'])*(1.0-paramplus['rhobeta'])) poly['exoggrid'][:, 0] = poly['exoggrid'][:, 0] #+ meanspread poly['quadgrid'], poly['quadweight'] = po.get_quadgrid( poly['nquad'], poly['ninnov'], poly['nqs']) poly['sfutquad'], poly['ind_sfutquad'], poly[ 'quadweights'] = get_quadstates(poly, paramplus) return (poly)
def get_griddetails(polyapp, params): #Return details of polynomial associated with constructing the grids used nmsv = polyapp['nmsv'] nmsve = polyapp['nexog_nmsv'] nsreg = polyapp['nsreg'] npoly = polyapp['npoly'] nx = nmsv - nmsve - (nsreg - 1) #grid for polynomial approximation polyapp['msvbounds'] = np.zeros([2 * nmsv]) if (nx >= 1): polyapp['msvbounds'][0] = -0.05 polyapp['msvbounds'][nmsv] = 0.05 if (nx >= 2): polyapp['msvbounds'][1] = -0.075 polyapp['msvbounds'][nmsv + 1] = 0.075 if (nx == 3): polyapp['msvbounds'][2] = -0.02 polyapp['msvbounds'][nmsv + 2] = 0.02 ubd = np.log(0.96) for i in np.arange(nsreg - 1): polyapp['msvbounds'][nx + i] = np.log(0.0001) polyapp['msvbounds'][nmsv + nx + i] = ubd bd = polyapp['maxstd'] polyapp['msvbounds'][nmsv - 1] = -bd * params['stdm'] polyapp['msvbounds'][nmsv + nmsv - 1] = bd * params['stdm'] polyapp['scmsv2xx'] = np.zeros([2 * nmsv]) polyapp['scxx2msv'] = np.zeros([2 * nmsv]) polyapp['scmsv2xx'][0:nmsv] = 2.0 / (polyapp['msvbounds'][nmsv:2 * nmsv] - polyapp['msvbounds'][0:nmsv]) polyapp['scmsv2xx'][nmsv:2 * nmsv] = -2.0 * polyapp['msvbounds'][0:nmsv] / ( polyapp['msvbounds'][nmsv:2 * nmsv] - polyapp['msvbounds'][0:nmsv]) - 1.0 polyapp['scxx2msv'][0:nmsv] = 0.5 * (polyapp['msvbounds'][nmsv:2 * nmsv] - polyapp['msvbounds'][0:nmsv]) polyapp['scxx2msv'][nmsv:2 * nmsv] = polyapp['msvbounds'][0:nmsv] + 0.5 * ( polyapp['msvbounds'][nmsv:2 * nmsv] - polyapp['msvbounds'][0:nmsv]) #for the approximating function. polyapp['rhos'][0] = params['rhoeta'] polyapp['stds'][0] = params['stdeta'] polyapp['exoggrid'],polyapp['exogindex'],polyapp['steps'],polyapp['bounds'],polyapp['ind2poly'] = po.get_exoggrid(polyapp['ngrid'],polyapp['nexog_fe'], \ polyapp['ns'],polyapp['rhos'],polyapp['stds'],polyapp['maxstd']) polyapp['quadgrid'], polyapp['quadweight'] = po.get_quadgrid( polyapp['nquad'], polyapp['ninnov'], polyapp['nqs']) polyapp['sfutquad'], polyapp['ind_sfutquad'], polyapp[ 'quadweights'] = get_quadstates(polyapp, params) #print('sfut = ', polyapp['sfutquad'][:,1,10]) #sys.exit() return (polyapp)
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 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)