When VIX spiking 40% or more

Vix return after 40% spike
Emini SP500 futures returns X days after VIX spike more than 40%

When VIX spiked 40% or more in the pass?

Red dots are when VIX spiked 40%++in recent year
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import Quandl

sns.set(style="whitegrid")
auth_tok = 'YOUR_TOKEN'

data = pd.DataFrame()
data["VIX"] = Quandl.get("YAHOO/INDEX_VIX",trim_start="1990-01-01", authtoken=auth_tok)["Close"]
data["pct"] = 100*data["VIX"].pct_change()
data['ES'] = Quandl.get('CHRIS/CME_SP1',trim_start="1990-01-01", authtoken = auth_tok)['Settle']
data["ESpct"] = 100*data["ES"].pct_change()



#Displaying VIX heatmap
def heatmap(df):
heat = round(df[(df["pct"] >40)].transpose().iloc[1:2],2)
heat.columns = heat.columns.map(lambda x: x.strftime("%Y-%m-%d"))
cmap = sns.dark_palette("red", as_cmap=True)
fig, ax = plt.subplots(1, figsize=(16, 9))
ax = sns.heatmap(heat, square=True, cmap=cmap, linewidths=1,
annot=True, cbar=False, annot_kws={"size": 42}, fmt="g")
ax.axes.get_yaxis().set_visible(False)
plt.title("All Vix spike > 40% since 1990 ")
plt.show()



def rets(df, days):
out = 100*((df.shift(-days) / df) - 1)
return out

def getRets_scatter(df, days):
rets_21 = rets(df["ES"], days).where((df["pct"] >40)).dropna()
#vix_21 = df["ES"][(df["pct"] > 20)]
vix_21 = df["ES"][(df["pct"] >20)].iloc[:-2]
print(len(rets_21))
print(len(vix_21))
plt.figure(figsize=(9, 9))
plt.scatter(vix_21, rets_21, color="crimson", alpha=0.89, s=34)
plt.grid(alpha=0.21)
plt.title("VIx returns 21 days after large single day declines")
plt.ylabel("Vix % return 21 days later")
plt.xlabel("Vix single day decline pct (from close to close)")
plt.axhline(linestyle="--", linewidth=1, color="#333333")
plt.legend(loc="upper left")
plt.show()



def getRets_chart(df, days):
df = df.reset_index()
df_out = pd.DataFrame()
for index, row in df.iterrows():
#if ((df["VIX"].iloc[index - 1] >= 10) & (df["VIX"].iloc[index] < 10)):
if (df["pct"].iloc[index] < -15):
ret = df["ESpct"].iloc[index:index + days]
ret.iloc[:1] = 0
ret.reset_index(drop=True, inplace=True)
df_out[index] = ret

plt.figure(figsize=(16, 9))
#print(df_out)
plt.plot(df_out.iloc[:,:-1].cumsum(), color="#555555", alpha=0.34)
plt.plot(df_out.mean(axis=1).cumsum(), color="r", label="Mean rets")
plt.plot(df_out.iloc[:, -1:].cumsum(), color="k", label="Last time")
#plt.plot(df_out.iloc[:, -1:].cumsum(), color="#555555", alpha=0.34)
plt.grid(alpha=0.21)
plt.title("#ES_F returns after 40% spike")
plt.ylabel("% Return")
plt.xlabel("Days after")
plt.axhline(linestyle="--", linewidth=1, color="#333333")
plt.xticks(np.arange(0, days + 1, 5))
plt.legend(loc="upper left")
plt.show()
#return df_out

#heatmap(data)
#getRets_scatter(data, 21)
getRets_chart(data, 21 + 1)
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.