SimpleModelClassHomework.pdf

# SimpleModelClassHomework.pdf - 1 Simulating a macroeconomic...

• No School
• AA 1
• 5

This preview shows page 1 out of 5 pages. Unformatted text preview: SimpleModelClassHomework April 19, 2018 1 Simulating a macroeconomic model in Python Recall that you can run all of this code yourself! • First, open a web brower and go to the website: – Click &quot;Try Jupyter With Python&quot; • Second, after the notebook page has loaded, you can remove the pre-filled cells by clicking them and hitting the &quot;cut&quot; button in the toolbar at the top of the page (it has a pair of scissors on the button). • Third, copy a code cell from this PDF, paste into a cell in the notebook, and then hit &quot;run&quot; (again, in the toolbar at the top of the page) – Note that each code cell that has been &quot;run&quot; has a number alongside, e.g.  – You can create new cells by hitting &quot;add&quot; (it has a plus (+) symbol on the button). • Finally, you can always save your work via: &quot;File&quot;&gt;&quot;Download as&quot;&gt;&quot;HTML (.html)&quot;. – Unfortunately, saving as PDF doesn’t seem to work from the web browser – Note that using the web broswer version of the Notebook, it is not straightforward to load your saved work. – Instead, save as an HTML file, and next time you run the code, simply copy the code cells across to a new Notebook that you load from the web browser. 1.0.1 Simulate Impulse Response Functions for the IS/MP/AS model Consider the IS/MP/AS model with inflation, from class Lecture 10 slides (Slides 11-12). We also include a simple Taylor Rule (slide 22). The model is: y∗t = ηat + x 1 rt∗ = r ∗ + (y∗t+1 − y∗t + dt ) σ yt − y∗t = −σ (rtn − πt+1 − rt∗ ) + yt+1 − y∗t+1 πt = λ(yt − y∗t ) rtn = r ∗ + π 0 + ϕπ (πt+1 − π 0 ) where the final equation is the Taylor rule (using expected inflation targeting). In this model we assume that the agents in the economy have perfect foresight over future output gaps and future inflation. This allows us to solve the model simply, using backward iteration. 1 2 Set model parameters In : # Importing Python Libraries import numpy as np import matplotlib.pyplot as plt In : # Set model parameter values rnstar = 0.01 # Natural rate of interest phi_pi = 3 # coefficient in the Taylor rule pi0 = 0 # Steady state rate of inflation sigma = 0.5 lammbda = 0.75 eta = 0.75 x = -0.05 # # # # rho = 0.75 3 risk aversion in the utility function Philip's curve coefficient on the output gap LRAS curve coefficient on productivity shocks LRAS curve constant parameter # AR(1) persistence parameter Simulate demand and productivity shocks • Suppose the shocks are generated by an AR(1) process: dt = ρdt−1 + ε d,t • ρ is a parameter describing the persistence of shocks to demand • ε d,t is a shock to demand. • Notice that a single shock to demand (ε d,t ) affects today’s demand, dt , but because of the persistence of the shock, it will also affect tomorrow’s demand because: dt+1 = ρdt + ε d,t+1 = ρ(ρdt−1 + ε d,t ) + ε d,t+1 • When simulating an Impulse Response Function, we suppose there is a single shock to demand, and we trace out its impact over time In : # 1. Simulate a_t and d_t T = 50 # number of simulation periods a_t = np.zeros(T) d_t = np.zeros(T) eps_a_t = np.zeros(T) eps_d_t = np.zeros(T) # Consider a demand shock eps_d_t = 0.01 for tt in range(1,T): 2 d_t[tt] = rho*(d_t[tt-1] + eps_d_t[tt]) plt.plot(d_t) plt.title('Demand shock') plt.show() 4 Simulate the model • • • • We use backward iteration to solve the model Assume the model has returned to steady state in the final period Iterate backwards given the values of inflation and the output gap in the period ahead Note that flexible price output and the natural rate of interest can be simulated immediately since they only depend on the sequence of productivity and demand shocks In : # 2. Simulate natural rate of output and interest ystar_t = eta*a_t + x rnstar_t = rnstar*np.ones(T) for tt in range(0,T-1): rnstar_t[tt] = rnstar + 1/sigma*(ystar_t[tt+1] - ystar_t[tt] + d_t[tt]) In : # 3. Backwards iteration on the model taking current path of inflation as given 3 pi_t = pi0*np.ones(T+1) x_t = np.zeros(T+1) rn_t = (rnstar + pi0)*np.ones(T+1) for ss in range(1,T+1): rn_t[T-ss] = rnstar + pi0 + phi_pi*(pi_t[T-ss+1] - pi0) x_t[T-ss] = -sigma*(rn_t[T-ss] - pi_t[T-ss+1] - rnstar_t[T-ss]) + x_t[T-ss+1] pi_t[T-ss] = lammbda*x_t[T-ss] 5 Plot the Impulse Response Function for each of the model variables In : plt.figure(figsize=[15,10]) plt.subplot(2,3,1) plt.plot(a_t) plt.title('Productivity shock') plt.subplot(2,3,2) plt.plot(d_t) plt.title('Demand shock') plt.subplot(2,3,3) plt.plot(x_t) plt.title('Output gap') plt.subplot(2,3,4) plt.plot(x_t) plt.title('Inflation') plt.subplot(2,3,5) plt.plot(rn_t) plt.title('Nominal interest rate') plt.show() 4 5 ...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern