In [1]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline  

N = 500

G0     = 5

theta = np.zeros(N) # tax rate
theta[0:250] = 0.2
theta[250:] = 0.25

C   = np.zeros(N) # consumption
G   = np.zeros(N) # government spending
Y   = np.zeros(N) # income
Y_d = np.zeros(N) # disposable income
T   = np.zeros(N) # tax revenue
H_g = np.zeros(N) # government debt

Y_d[0] = 100

for t in range(1, N):
    
    # calculate consumer spending
    C[t]   = Y_d[t-1] 
    
    # calculate government spending
    G[t]   = T[t-1]
    
    # calculate total income (consumer spending plus constant government spending)
    Y[t]   = G[t] + C[t] 
    
    # calculate the tax take
    T[t] = theta[t] * Y[t]
    
    # calculate disposable income
    Y_d[t] = Y[t] - T[t]
        
    # calculate the change in government debt
    H_g[t] = H_g[t-1] + T[t]- G[t]

In [2]:
fig = plt.figure(figsize=(12, 8))

consumption_plot = fig.add_subplot(241, xlim=(0, N), ylim=(0, np.max(Y)))
consumption_plot.plot(range(N), C, lw=3)
consumption_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('consumption')

gov_plot = fig.add_subplot(242, xlim=(0, N), ylim=(0, np.max(Y)))
gov_plot.plot(range(N), G, lw=3)
gov_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government spending')

income_plot = fig.add_subplot(243, xlim=(0, N), ylim=(0, np.max(Y)))
income_plot.plot(range(N), Y, lw=3)
income_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('income')



gov_plot = fig.add_subplot(245, xlim=(0, N), ylim=(0, np.max(G)*1.5))
gov_plot.plot(range(N), G, lw=3)
gov_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government spending')

tax_plot = fig.add_subplot(246, xlim=(0, N), ylim=(0, np.max(G)*1.5))
tax_plot.plot(range(N), T, lw=3)
tax_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('tax revenue')

deficit_plot = fig.add_subplot(247, xlim=(0, N), ylim=(np.min(T-G)*1.5,0))
deficit_plot.plot(range(N), T-G, lw=3)
deficit_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government budget')

debt_plot = fig.add_subplot(248, xlim=(0, N), ylim=(np.min(H_g)*1.5,0))
debt_plot.plot(range(N), H_g, lw=3)
debt_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government debt')

# space subplots neatly
plt.tight_layout()


/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py:2757: UserWarning: Attempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=0.0, top=0
  + 'bottom=%s, top=%s') % (bottom, top))

In [27]:
print(C[35])
print(C[-1])


80.0
78.75

In [28]:
print(Y[35])
print(Y[-1])


100.0
105.0

In [29]:
print(T[35])
print(T[-1])


20.0
26.25

In [30]:
print(G[35])
print(G[-1])


20.0
26.25

In [3]:
N = 500

G = 20

theta = np.zeros(N) # tax rate
theta[0:250] = 0.2
theta[250:] = 0.25

C   = np.zeros(N) # consumption
Y   = np.zeros(N) # income
Y_d = np.zeros(N) # disposable income
T   = np.zeros(N) # tax revenue
H_g = np.zeros(N) # government debt

for t in range(0, N):
    
    # calculate consumer spending
    C[t]   = Y_d[t-1] 
    
    # calculate total income (consumer spending plus constant government spending)
    Y[t]   = G + C[t] 
    
    # calculate the tax take
    T[t] = theta[t] * Y[t]
    
    # calculate disposable income
    Y_d[t] = Y[t] - T[t]
    
    # calculate the change in government debt
    H_g[t] = H_g[t-1] + T[t]- G

In [4]:
fig = plt.figure(figsize=(12, 8))

consumption_plot = fig.add_subplot(241, xlim=(0, N), ylim=(0, np.max(Y)))
consumption_plot.plot(range(N), C, lw=3)
consumption_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('consumption')

gov_plot = fig.add_subplot(242, xlim=(0, N), ylim=(0, np.max(Y)))
gov_plot.plot(range(N), np.repeat(G,N), lw=3)
gov_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government spending')

income_plot = fig.add_subplot(243, xlim=(0, N), ylim=(0, np.max(Y)))
income_plot.plot(range(N), Y, lw=3)
income_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('income')



gov_plot = fig.add_subplot(245, xlim=(0, N), ylim=(0, np.max(np.repeat(G,N))*1.5))
gov_plot.plot(range(N), np.repeat(G,N), lw=3)
gov_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government spending')

tax_plot = fig.add_subplot(246, xlim=(0, N), ylim=(0, np.max(np.repeat(G,N))*1.5))
tax_plot.plot(range(N), T, lw=3)
tax_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('tax revenue')

deficit_plot = fig.add_subplot(247, xlim=(0, N), ylim=(np.min(T-np.repeat(G,N))*1.5,0))
deficit_plot.plot(range(N), T-np.repeat(G,N), lw=3)
deficit_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government budget')

debt_plot = fig.add_subplot(248, xlim=(0, N), ylim=(np.min(H_g)*1.5,0))
debt_plot.plot(range(N), H_g, lw=3)
debt_plot.grid()
# label axes
plt.xlabel('time')
plt.ylabel('government debt')

# space subplots neatly
plt.tight_layout()



In [ ]: