Skip to content

Instantly share code, notes, and snippets.

@mcohen01
Created June 19, 2022 16:51
Show Gist options
  • Save mcohen01/fd2d49c64f99df845a0433025a013c45 to your computer and use it in GitHub Desktop.
Save mcohen01/fd2d49c64f99df845a0433025a013c45 to your computer and use it in GitHub Desktop.
import pandas_datareader.data as web
import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
def get_series(name, start, end):
df = web.DataReader('^GSPC', 'yahoo', start=start, end=end)['Adj Close']
index = range(len(df.index))
ath = df.values[0]
return pd.Series(df.values / ath, index=index, name=name)
fig, ax = plt.subplots(figsize=(16, 9))
get_series(name="1929-1932", start='1929-09-16', end='1932-06-01').plot(ax=ax)
get_series(name="1968-1970", start='1968-11-28', end='1970-05-26').plot(ax=ax)
get_series(name="1973-1974", start='1973-02-13', end='1974-10-06').plot(ax=ax)
get_series(name="2000-2002", start='2000-03-24', end='2002-10-09').plot(ax=ax)
get_series(name="2007-2009", start='2007-10-09', end='2009-03-03').plot(ax=ax)
get_series(name="2022-?", start='2022-01-03', end='2022-06-18').plot(ax=ax, lw=2, color='#000000')
plt.title('SP500 Max Drawdown')
plt.xlabel('Trading Days')
plt.legend();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment