예제 #1
0
def plotQmodel(model, exog, returnDF = False):
    
    # Simpulate the optimal response
    dr = pf.deterministic_solve(model = model,shocks = exog,verbose=True)
    
    # Plot exogenous variables
    ex = ['R','tau','itc_1','psi']
    fig, axes = plt.subplots(1,len(ex), figsize = (10,3))
    axes = axes.flatten()
    
    for i in range(len(ex)):
        ax = axes[i]
        ax.plot(dr[ex[i]],'.')
        ax.set_xlabel('Time')
        ax.set_ylabel(ex[i])
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    
    fig.suptitle('Exogenous variables', fontsize=16)
    
    # Plot optimal response variables
    fig, axes = plt.subplots(2,2, figsize = (10,6))
    axes = axes.flatten()
    opt = ['k','i','lambda_1','q_1']
    
    for i in range(len(opt)):
        ax = axes[i]
        ax.plot(dr[opt[i]],'.')
        ax.set_xlabel('Time')
        ax.set_ylabel(opt[i])
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    
    fig.suptitle('Endogenous response', fontsize=16)
    
    if returnDF:
        return(dr)
예제 #2
0
def simul_change_dolo(model, k0, exog0, exog1, t_change, T_sim):

    # The first step is to create time series for the exogenous variables
    exog = np.array([
        exog1,
    ] * (T_sim - t_change))
    if t_change > 0:
        exog = np.concatenate(
            (
                np.array([
                    exog0,
                ] * (t_change)),
                exog,
            ),
            axis=0,
        )
    exog = pd.DataFrame(exog, columns=["R", "tau", "itc_1", "psi"])

    # Simpulate the optimal response
    dr = pf.deterministic_solve(model=model,
                                shocks=exog,
                                T=T_sim,
                                verbose=True,
                                s1=k0)

    # Dolo uses the first period to report the steady state
    # so we ommit it.
    return dr[1:]
예제 #3
0
def plotQmodel(model, exog, returnDF=False):

    # Simpulate the optimal response
    dr = pf.deterministic_solve(model=model, shocks=exog, verbose=True)

    # Plot exogenous variables
    ex = ["R", "tau", "itc_1", "psi"]
    fig, axes = plt.subplots(1, len(ex), figsize=(10, 3))
    axes = axes.flatten()

    for i in range(len(ex)):
        ax = axes[i]
        ax.plot(dr[ex[i]], ".")
        ax.set_xlabel("Time")
        ax.set_ylabel(ex[i])
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])

    fig.suptitle("Exogenous variables", fontsize=16)

    # Plot optimal response variables
    fig, axes = plt.subplots(2, 2, figsize=(10, 6))
    axes = axes.flatten()
    opt = ["k", "i", "lambda_1", "q_1"]

    for i in range(len(opt)):
        ax = axes[i]
        ax.plot(dr[opt[i]], ".")
        ax.set_xlabel("Time")
        ax.set_ylabel(opt[i])
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])

    fig.suptitle("Endogenous response", fontsize=16)

    if returnDF:
        return dr
예제 #4
0
# Dolo receives a DataFrame with the full future paths for ALL exogenous
# variables. So we create one:
Exog = pd.DataFrame({'R':[R]*T,
                     'tau':[tau]*T,
                     'itc_1':[zeta]*T,
                     'psi':Psi_sequence})

# Examine the first few entries.
Exog.head()
# Note all other variables are left constant.

# %%
# Now use the "perfect foresight" dolo solver
response = pf.deterministic_solve(model = QDolo, # Model we are using (in dolo)
                                  shocks = Exog, # Paths for exog. variables 
                                  T=T,           # Total simulation time
                                  s1 = [k0],     # Initial state
                                  verbose=True)

# Response is a DataFrame with the paths of every variable over time.
# It adds information we don't need on the first row. So we delete it
response = response[1:]

# Inspect the first few elements.
response.head()

# %% [markdown]
# # IMPORTANT
#
# Because of the way the model is implemented, it does not keep track of $\lambda_t$ or $ITC_t$, but  $\lambda_{t+1}$ and $ITC_{t+1}$ instead. 
#