<jupyter_start><jupyter_text>A simple analysis of inflation and bnp in a closed economy Imports and set magics:<jupyter_code>import numpy as np
from scipy import optimize
import sympy as sm
import ipywidgets as wg
import matplotlib.pyplot as plt
from IPython.display import display

# autoreload modules when code is run
%load_ext autoreload
%autoreload 2

# local modules
import modelproject as mp<jupyter_output>The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>Model description We consider  the following model of inflation and GDP.<!---it looks like a mess because I don't know how to indent, "&nbsp;" is equal to one space.-->||||:---|---||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AD.   |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$y_t = \bar{y} - \alpha (\pi_t - \pi^*)$   ||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AS.   |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$\pi_t = \pi_{t-1} + \gamma (y_t - \bar{y})$   | Using $\hat{y}_t = y_t - \bar{y}$ and $\hat{\pi}_t = \pi_t - \pi^*$ we get:||||:---|---||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AD.   |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$\hat{y}_t = - \alpha \hat{\pi}_t$   ||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AS.   |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$\pi_t = \pi_{t-1} + \gamma (y_t - \bar{y})$ $\rightarrow$ $\pi_t = \hat{\pi}_{t-1} + \pi^* + \gamma \hat{y_t}$ $\rightarrow$  ||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AS. |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$\hat{\pi}_t = \hat{\pi}_{t-1} + \gamma \hat{y_t}$ |$\pi_{t}$ is inflation at period t, $y_t$ is GDP at period t, and $\gamma$ and $\alpha$ are parameters larger than 0. $\pi^*$ is the central banks inflation goal$\bar{y}$ and $\bar{\pi}$ are the natural levels of output and inflation, meaning the levels if every resource in the economy is used effeciently. $\hat{y}_t$ and $\hat{\pi}_t$ are the differences between the actual value and the efficient value of GDP and the inflation goal at period t.  Steady state<jupyter_code>#using sympy to find steady state

# Defining the symbols
yt, ybar, pit, pistar, pitm1, yhat_t, yhat_t1, alpha, pihat_t, pihat_t1, gamma = sm.symbols('y_t ybar pi_t pi^* pi_t-1 yhat_t yhat_t-1 alpha pihat_t pihat_t-1 gamma')
# Defining our equations
AD_yt = sm.Eq(yhat_t, - alpha*pihat_t)
AS_pit = sm.Eq(pihat_t, pihat_t1+gamma*yhat_t)
display("AD = ", AD_yt, "AS = ", AS_pit)

# the steady state for pi is found by inserting AD into AS
ss1 = sm.Eq(pihat_t, pihat_t1-gamma*alpha*pihat_t)
#solving for pihat_t
sspi1 = sm.solve(ss1, pihat_t) # solving for pihat_t
sspi = sm.Eq(pihat_t,(pihat_t1/(alpha*gamma + 1))) # converting result to equation
display('steady state for pi is: ', sspi) # displaying result

# the steady state for y is found by inserting AS into AD
ss2 = sm.Eq(yhat_t, - alpha*(pihat_t1+gamma*yhat_t))
ssy1 = sm.solve(ss2, yhat_t) # solving for yhat_t
#by inserting AD in time t-1 we get yhat_t as a function of y_t-1
ss3 = sm.Eq(yhat_t,(alpha/(alpha*gamma + 1)*(yhat_t1/alpha)))
ssy2 = sm.solve(ss3, yhat_t) # solve again for yhat_t
ssy3 = sm.Eq(yhat_t,(yhat_t1/(alpha*gamma + 1))) # converting result to equation
display('steady state for y is: ', ssy3) # displaying result<jupyter_output><empty_output><jupyter_text>By solving the model we find that steady state for both $\hat{y}_t$ and $\hat{\pi}_t$ is equal to the the previouse periods value times $\frac{1}{\alpha \gamma + 1}$  Graphing the equations<jupyter_code># Defining AD and AS as graphs
def AD_graph(a):
    yt = np.linspace(0,100)
    ybar = 10
    pistar = 0.02
    pit = (a*pistar - yt + ybar)/a
    
    # Making the graph
    plt.plot(yt, pit ,'r-')
    plt.ylabel('pi') 
    plt.xlabel('yt')
    plt.ylim([0,0.1])
    plt.xlim([9.8,10.2])
    
def AS_graph(g):
    yt = np.linspace(0,100)
    ybar = 10
    pitm1 = 0.01
    pit = g*(yt-ybar)+pitm1
    # Making the graph

    plt.plot(yt, pit, 'b-')
    plt.ylabel('pi') 
    plt.xlabel('yt')
    plt.ylim([0,0.1])
    plt.xlim([9.8,10.2])

# Makeing a slider for alpha and gamma
a_slider = wg.FloatSlider(value=0.5, min=0, max=1, step = 0.01)
g_slider = wg.FloatSlider(value=0.5, min=0, max=1, step = 0.01)

AD = wg.interact(AD_graph, a = a_slider)
AS = wg.interact(AS_graph, g = g_slider)
# Graphic solution for alpha = gamma = 1/3
AD_graph(0.33)
AS_graph(0.33)<jupyter_output><empty_output><jupyter_text>Unforseen changes to inflation Because of unforseen consequenses the inflation in period t-1 is now 1 pct., where as the goal for the inflation is 2 pct.By using a solver we can see that the optimal level for the inflation in our model is 2 pct. meaning the inflation will settle at 2 pct. in the steady state.<jupyter_code>#Defining values used in this exampla.
pi_t1 = 0.01 # the inflation is 1% instead of the 2% inflation goal.
gamma = 0.33
ybar = 10
pistar = 0.02
alpha = 0.33

def AS(y_t):
    return pi_t1 + gamma*(y_t - ybar)
def obj(y_t):
    return alpha * (AS(y_t) - pistar)
#using solver from modelproject to find the optimal pi
optimum = mp.solve_for_ss(pi_t1, gamma, ybar, pistar, alpha)<jupyter_output><empty_output><jupyter_text>Conclusion<jupyter_code>yoptimum = optimum.x[0]
print(f'the optimal y is equal to {yoptimum:.2f} which is also equal to the most effecient output')
pioptimum = AS(optimum.x[0])
print(f'the optimal pi is equal to {pioptimum:.2f} which is also equal to the inflation goal')<jupyter_output>the optimal y is equal to 10.03 which is also equal to the most effecient output
the optimal pi is equal to 0.02 which is also equal to the inflation goal
{'fraction_non_alphanumeric': 0.14576517629952745, 'fraction_numerical': 0.023446019629225736, 'mean_word_length': 4.337536372453928, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '132920', 'license': 'MIT', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2051, 'n_words': 635, 'path': 'modelproject/modelproject.ipynb', 'repo_name': 'NumEconCopenhagen/projects-2020-group404', 'size': '5502'}