|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import matplotlib |
| 4 | +from datetime import datetime |
| 5 | + |
| 6 | +fig = plt.figure() |
| 7 | +ax = fig.add_subplot(1, 1, 1) |
| 8 | + |
| 9 | +data = pd.read_csv('spx.csv', index_col=0, parse_dates=True) |
| 10 | +spx = data['SPX'] |
| 11 | + |
| 12 | +spx.plot(ax=ax, style='k-') |
| 13 | + |
| 14 | +crisis_data = [ |
| 15 | + (datetime(2007, 10, 11), 'Peak of bull market'), |
| 16 | + (datetime(2008, 3, 12), 'Bear Stearns Fails'), |
| 17 | + (datetime(2008, 9, 15), 'Lehman Bankruptcy') |
| 18 | +] |
| 19 | + |
| 20 | +for date, label in crisis_data: |
| 21 | + ax.annotate(label, xy=(date, spx.asof(date) + 75), |
| 22 | + xytext=(date, spx.asof(date) + 225), |
| 23 | + arrowprops=dict(facecolor='black', headwidth=4, width=2, |
| 24 | + headlength=4), |
| 25 | + horizontalalignment='left', verticalalignment='top') |
| 26 | + |
| 27 | +# Zoom in on 2007-2010 |
| 28 | +ax.set_xlim(['1/1/2007', '1/1/2011']) |
| 29 | +ax.set_ylim([600, 1800]) |
| 30 | + |
| 31 | +ax.set_title('Important dates in the 2008-2009 financial crisis') |
| 32 | + |
| 33 | +fig.show() |
0 commit comments