コード例 #1
0
def getinputdict_bayesian():
    """
    Run this function before doing any evaluation

    inputdict without solving for parameters
    Note that we have specified an empty parameter dict here
    """
    inputdict = getinputdict_noparamssdict()

    # get model
    # we haven't solved for the steady state so allow for missingparams
    inputdict['missingparams'] = True
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    getmodel_inputdict(inputdict)

    # compute analytical fx, fxp, fy, fyp matrices
    # don't cancel params so do full replace of variables
    inputdict['fxefy_cancelparams'] = False
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgediff_func import getfxefy_inputdict
    inputdict = getfxefy_inputdict(inputdict)

    # convert fx, fxy, fy, fyp matrices to functions (makes it quicker to do conversion)
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgediff_func import funcstoeval_inputdict
    inputdict = funcstoeval_inputdict(inputdict)

    return (inputdict)
コード例 #2
0
def getpartialeval(partialeval = False, partialeval_numeval = False):
    """
    """
    inputdict = getinputdict_noparamssdict()

    if partialeval is True:
        # need to specify some parameters here since we're doing a partial eval
        p = getparamssdict_partial()
        # if we are doing a numeval then we should specify some steady state parameters
        # otherwise doing a numerical eval makes no difference
        if partialeval_numeval is True:
            p['A'] = 1
        inputdict['paramssdict'] = p
    else:
        # no need to specify parameters if not partially evaluating
        # however we could choose to specify parameters here and it wouldn't make any difference
        inputdict['paramssdict'] = {}

    # get model
    # we haven't solved for the steady state so allow for missingparams
    inputdict['missingparams'] = True
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    getmodel_inputdict(inputdict)

    if partialeval is True:
        if partialeval_numeval is True:
            # compute numerical fx, fxp, fy, fyp matrices
            # since we don't specify fxefy_cancelparams = False then we do cancel the params we have defined
            # since we specify fxefy_f_usenumerical then when we're doing the partial conversion, we use the numerical derivatives rather than the analytical derivatives
            inputdict['fxefy_f_usenumerical'] = True
            sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
            from dsgediff_func import getnfxenfy_inputdict
            inputdict = getnfxenfy_inputdict(inputdict)
        else:
            # compute analytical fx, fxp, fy, fyp matrices
            # since we don't specify fxefy_cancelparams = False then we do cancel the params we have defined
            # however we don't cancel out any steady state variables
            sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
            from dsgediff_func import getfxefy_inputdict
            inputdict = getfxefy_inputdict(inputdict)
    else:
        # compute analytical fx, fxp, fy, fyp matrices
        # don't cancel params so do full replace of variables
        inputdict['fxefy_cancelparams'] = False
        sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from dsgediff_func import getfxefy_inputdict
        inputdict = getfxefy_inputdict(inputdict)

    # convert fx, fxy, fy, fyp matrices to functions (makes it quicker to do conversion)
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgediff_func import funcstoeval_inputdict
    inputdict = funcstoeval_inputdict(inputdict)

    return(inputdict)
コード例 #3
0
def simlinear():
    
    sys.path.append(str(__projectdir__ / Path('dsgesetup')))
    from rbc_simple import getinputdict
    inputdict = getinputdict()

    # add model
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict) 

    # get policy function
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsge_bkdiscrete_func import polfunc_inputdict
    inputdict = polfunc_inputdict(inputdict)

    # add shocks
    inputdict['pathsimperiods'] = 100
    inputdict['shocksddict'] = {'epsilon_a': 0.01}
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from getshocks_func import getshockpath_inputdict
    inputdict = getshockpath_inputdict(inputdict)

    # simulate path
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from simlineardsge_func import simpathlinear_inputdict
    inputdict = simpathlinear_inputdict(inputdict)

    # path of non log-linearized variable
    print(inputdict['expssvarpath'])

    # standard deviation of consumption
    print(np.std(inputdict['varpath'][:, inputdict['stateshockcontrolposdict']['c']]))
コード例 #4
0
def stochsimul(run=True):

    sys.path.append(str(__projectdir__ / Path('dsgesetup')))
    from rbc_simple import getinputdict
    inputdict = getinputdict()
    inputdict['savefolder'] = __projectdir__ / Path(
        'python2dynare/temp/stochsimul/')

    # add model
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # add shocksddict
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from getshocks_func import getshocksddict_inputdict
    inputdict = getshocksddict_inputdict(inputdict)

    # python2dynare
    inputdict['python2dynare_simulation'] = 'stoch_simul(order=1);'
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from python2dynare_func import python2dynare_inputdict
    python2dynare_inputdict(inputdict)

    # run dynare
    if run is True:
        # run dynare
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import rundynare_inputdict
        rundynare_inputdict(inputdict)
コード例 #5
0
def stochsimul(run = True):
    
    sys.path.append(str(__projectdir__ / Path('dsgesetup')))
    from rbc_simple import getinputdict
    inputdict = getinputdict()
    inputdict['savefolder'] = __projectdir__ / Path('python2dynare/temp/stochsimul/')

    # add model
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict) 

    # add shocksddict
    inputdict['shocksddict'] = {'epsilon_a': 0.01}
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from getshocks_func import getshocksddict_inputdict
    inputdict = getshocksddict_inputdict(inputdict)

    # python2dynare
    inputdict['python2dynare_simulation'] = 'extended_path(periods=100,solver_periods=100);'
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from python2dynare_func import python2dynare_inputdict
    python2dynare_inputdict(inputdict)

    # run dynare
    if run is True:
        # run dynare
        sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import rundynare_inputdict
        rundynare_inputdict(inputdict)
        # get irfs
        sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import getirfs_dynare_inputdict
        getirfs_dynare_inputdict(inputdict)
コード例 #6
0
def getsimdata(varnames, numperiods = 100):
    """
    To get simulated data, we simulate out the system of equations.
    """
    inputdict = getinputdict_full()

    # complete inputdict
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # get policy function
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsge_bkdiscrete_func import polfunc_inputdict
    inputdict = polfunc_inputdict(inputdict)

    # add shocks
    inputdict['pathsimperiods'] = numperiods
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from getshocks_func import getshockpath_inputdict
    inputdict = getshockpath_inputdict(inputdict)

    # simulate path
    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from simlineardsge_func import simpathlinear_inputdict
    inputdict = simpathlinear_inputdict(inputdict)

    data = inputdict['varpath'][:, [inputdict['stateshockcontrolposdict'][varnames[i]] for i in range(len(varnames))]]

    return(data)
コード例 #7
0
def getmodel():
    from rbc_simple import getinputdict
    inputdict = getinputdict()

    sys.path.append(str(__projectdir__ / Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict) 

    return(inputdict)
コード例 #8
0
def simul(run=False, shockpathspecify=False):
    """
    If run = True, need to specify inputdict['dynarepath'] and (if you want to use Octave) inputdict['runwithoctave'] = True
    """

    sys.path.append(str(__projectdir__ / Path('dsgesetup')))
    from rbc_simple import getinputdict
    inputdict = getinputdict()
    inputdict['savefolder'] = __projectdir__ / Path(
        'python2dynare/temp/simul_shockpath/')

    # add model
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # add pathshock
    if shockpathspecify is True:
        inputdict['shockpath'] = np.array([[1, 1, 1] + [0] * 17]).transpose()
    else:
        inputdict['pathsimperiods'] = 20
        inputdict['pathsimperiods_noshock'] = 10
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from getshocks_func import getshockpath_inputdict
        inputdict = getshockpath_inputdict(inputdict)

    # python2dynare
    inputdict['python2dynare_simulation'] = 'simul(periods = 300);'
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from python2dynare_func import python2dynare_inputdict
    python2dynare_inputdict(inputdict)

    # run dynare
    if run is True:
        # run dynare
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import rundynare_inputdict
        rundynare_inputdict(inputdict)
        # get irfs
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import getirfs_dynare_inputdict
        getirfs_dynare_inputdict(inputdict)
コード例 #9
0
def dynare_extendedpath(p=None, run=False):
    """
    Solve model by extended path.
    The extended path method in Dynare assumes agents at t only know shocks at t.

    If I could input the shockpath, this should yield the same as occbin/myoccbin.
    But I don't see to be able to do that - I have to specify the shock s.d. instead.
    """
    if p is None:
        p = getp_default()

    p['monetary'] = 'taylor-zlb'
    inputdict = getinputdict(p)

    inputdict['savefolder'] = os.path.join(__projectdir__,
                                           'regimes/temp/extendedpath/')

    # add model
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # add shock path
    inputdict['shocksddict'] = copy.deepcopy(shocksddict_default)

    # generate python2dynare
    inputdict[
        'python2dynare_simulation'] = 'extended_path(periods = 20,solver_periods=100);'
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from python2dynare_func import python2dynare_inputdict
    python2dynare_inputdict(inputdict)

    # run dynare
    if run is True:
        # run dynare
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import rundynare_inputdict
        rundynare_inputdict(inputdict)
        # get irfs
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import getirfs_dynare_inputdict
        getirfs_dynare_inputdict(inputdict)
コード例 #10
0
def dynare_simul(p=None, run=False):
    """
    Use the Dynare simul method to solve given the constraint.
    This method implies that at time t, agents anticipate the values of future shocks.
    Thus, this method does not produce the same results as occbin which assumes that agents only know the values of shocks today.
    """
    if p is None:
        p = getp_default()

    p['monetary'] = 'taylor-zlb'
    inputdict = getinputdict(p)

    inputdict['savefolder'] = os.path.join(__projectdir__,
                                           'regimes/temp/perfect_foresight/')

    # add model
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # add shock path
    inputdict['shockpath'] = shockpath_default

    # generate python2dynare
    inputdict['python2dynare_simulation'] = 'simul(periods = 20);'
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from python2dynare_func import python2dynare_inputdict
    python2dynare_inputdict(inputdict)

    # run dynare
    if run is True:
        # run dynare
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import rundynare_inputdict
        rundynare_inputdict(inputdict)
        # get irfs
        sys.path.append(
            str(__projectdir__ / Path('submodules/dsge-perturbation/')))
        from python2dynare_func import getirfs_dynare_inputdict
        getirfs_dynare_inputdict(inputdict)
コード例 #11
0
def polfunc():

    sys.path.append(str(__projectdir__ / Path('dsgesetup')))
    from rbc_simple import getinputdict
    inputdict = getinputdict()

    # add model
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsgesetup_func import getmodel_inputdict
    inputdict = getmodel_inputdict(inputdict)

    # get policy function
    sys.path.append(str(__projectdir__ /
                        Path('submodules/dsge-perturbation/')))
    from dsge_bkdiscrete_func import polfunc_inputdict
    inputdict = polfunc_inputdict(inputdict)

    print(inputdict['hx'])
    print(inputdict['gx'])