Example #1
0
subdata = data[data['_rep'] < 3][['time', 'investment', '_rep']]
subdata.pivot(index='time', columns='_rep',
              values='investment').plot(legend=False, lw=1)
plt.plot(data.groupby('time')['investment'].mean(), 'k-')
plt.title('Simulated and Expected Investment')
plt.xlabel('Period')
plt.ylabel('Investment')

# Print Steady-State and Ergodic Moments
ff = '\t%15s = %5.2f'
D = data[data['time'] == T][['wealth', 'investment']]

print('\nDeterministic Steady-State')
print(ff % ('Wealth', sstar))
print(ff % ('Investment', kstar))
print('\nErgodic Means\n')
print(ff % ('Wealth', D['wealth'].mean()))
print(ff % ('Investment', D['investment'].mean()))
print('\nErgodic Standard Deviations\n')
print(ff % ('Wealth', D['wealth'].std()))
print(ff % ('Investment', D['investment'].std()))

# Compute and Plot Ergodic Wealth Distribution

demo.figure('Ergodic Wealth Distribution', 'Wealth', 'Probability',
            [smin, smax])
D['wealth'].plot.kde()

plt.show()
prt('Newton semismooth', t2, n2, x2)


# ### Plot results
# Here we use the methods *ssmooth* and *minmax* from class **MCP** to compute the semi-smooth and minimax transformations.

# In[7]:

fig = plt.figure()
original = {'label':'Original', 'alpha':0.5, 'color':'gray'}
x = np.linspace(-0.5, 2.5, 500)

ax1 = fig.add_subplot(121, title='Difficult NCP', aspect=1,
                     xlabel='x', xlim=[-0.5, 2.5], ylim=[-1, 1.5])
ax1.axhline(ls='--', color='gray')
ax1.plot(x, billups(x)[0], **original)
ax1.plot(x, Billups.ssmooth(x), label='Semismooth')
ax1.plot(x, Billups.minmax(x), label='Minmax')
ax1.legend(loc='best')

x = np.linspace(-0.03, 0.03, 500)
ax2 = fig.add_subplot(122, title='Difficult NCP Magnified', aspect=1,
                      xlabel='x', xlim = [-.035, .035], ylim=[ -.01, .06])
ax2.axhline(ls='--', color='gray')
ax2.plot(x, Billups.original(x), **original)
ax2.plot(x, Billups.ssmooth(x), label='Semismooth')
ax2.plot(x, Billups.minmax(x), label='Minmax')
ax2.legend(loc='best')

plt.show()