from IPython.core.display import HTML
HTML("")
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rc('figure', figsize=(8, 7))
data = pd.read_csv('data/GoogleTrendsData.csv', index_col='Date', parse_dates=True)
data.head()
data.plot(subplots=True)
data['debt_mavg'] = pd.rolling_mean(data.debt, 3)
data.head()
data['debt_mavg'] = data.debt_mavg.shift(1)
data.head(10)
data['order'] = 0
data['order'][data.debt > data.debt_mavg] = -1 # Short if search volume goes up relative to mavg.
data['order'][data.debt < data.debt_mavg] = 1 # Long if search volume goes down relative to mavg.
data.head(10)
data['ret_djia'] = data.djia.pct_change()
data.head()
data['ret_djia'] = data['ret_djia'].shift(-1)
# Compute returns of our strategy
data['ret_google'] = data.order * data.ret_djia
data.head(10)
plt.figsize(10, 3)
(1 + data.ret_google).cumprod().plot();
plt.ylabel('Portfolio value')
from IPython.core.display import Image
Image("http://www.nature.com/srep/2013/130425/srep01684/carousel/srep01684-f2.jpg")
from IPython.core.display import Image
Image("http://cdn.meme.li/instances/300x300/39833146.jpg")