Notebook
In [11]:
from quantopian.pipeline import Pipeline, CustomFactor
from quantopian.research import run_pipeline
from quantopian.pipeline.data.user_5aba7037bad61a0013e6e687 import test
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import Q500US
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import talib
from datetime import datetime, timedelta, date
from scipy.stats.mstats import gmean
In [12]:
class PreviousClose(CustomFactor):  
        inputs = [USEquityPricing.close]  
        window_length = 1

        def compute(self, today, assets, out, close):  
            out[:] = close[0]

class PreviousOpen(CustomFactor):  
        inputs = [USEquityPricing.open]  
        window_length = 1

        def compute(self, today, assets, out, open):  
            out[:] = open[0]
In [13]:
def make_pipeline():
    
    # Define our fundamental factor pipeline
    
    pipe = Pipeline()
    
    # PreviousClose(window_length = 1) is the same as USEquityPricing.close.latest
    previous_close_price = PreviousClose(window_length = 2)
    open_price = USEquityPricing.open.latest
    close_price = USEquityPricing.close.latest
    overnight_returns = open_price/previous_close_price - 1
    OR = overnight_returns + 1
    intraday_returns = close_price / open_price - 1
    first_30 = test.first_30.latest
    last_30 = test.last_30.latest
    
    pipe = Pipeline(
    
        columns = {
            'Overnight Returns': overnight_returns,
            'OR': OR,
            'Intraday Returns': intraday_returns,
            'First 30': first_30,
            'Last 30': last_30
                        
        },
        
    screen = Q500US()
       
    )
    return pipe
pipe = make_pipeline()
In [14]:
df = run_pipeline(pipe, '2006-01-03', '2018-11-08').dropna()

df.head(10)
Out[14]:
First 30 Intraday Returns Last 30 OR Overnight Returns
2006-01-04 00:00:00+00:00 Equity(24 [AAPL]) 0.017115 0.032876 0.002684 1.008533 0.008533
Equity(60 [ABS]) 0.004635 0.010242 -0.000467 1.005147 0.005147
Equity(62 [ABT]) -0.011533 -0.008020 -0.000256 1.011151 0.011151
Equity(67 [ADSK]) -0.003720 -0.004419 -0.000700 1.001631 0.001631
Equity(114 [ADBE]) -0.007785 0.041342 0.014913 1.008392 0.008392
Equity(128 [ADM]) -0.005674 -0.014545 0.000823 1.003650 0.003650
Equity(168 [AET]) -0.010447 -0.004132 0.000638 1.001379 0.001379
Equity(205 [AGN]) 0.008449 0.023192 0.002107 0.986294 -0.013706
Equity(239 [AIG]) -0.000407 0.009864 0.001586 1.010110 0.010110
Equity(328 [ALTR]) -0.019189 0.018124 -0.006760 1.012412 0.012412
In [15]:
df= df.reset_index()
df.rename(columns={'level_0':'date', 'level_1': 'ticker'}, inplace=True)
df.head(5)

earnings = pd.DataFrame(local_csv(path='bespoke_4Jun_2018.csv' , thousands=','))

#: Data cleaning
earnings.columns = (['symbol', 'date', 'time', 'prior_close', 'eps_act', \
                     'eps_est', 'eps_actvsest', 'rev_act', 'rev_est', 'rev_actvsest',\
                     'guidance', 'gap%', 'gap_pt', 'open_to_close%', 'open_to_close_pt',\
                    'day_chng%', 'day_chng_pt'])
earnings['date']=pd.to_datetime(earnings['date'])
In [16]:
def remove_earnings(data, earnings_df=earnings):
    ticker = data['ticker'].unique()
    earnings_stock_dates = earnings_df.loc[earnings_df.symbol==ticker[0], 'date']
    
    dates = data[~data.date.isin(earnings_stock_dates)].copy()
    del dates['ticker']

    return dates
In [17]:
def get_RSI_first30(data, column='First 30', timeperiod=7):   
    data['RSI_'+str(column)] = talib.RSI(np.array(data[column], dtype='f8'), timeperiod)
    data['RSI_'+ str(column)] = data['RSI_'+str(column)].shift()
    return data
def get_RSI_last30(data, column='Last 30', timeperiod=7):   
    data['RSI_'+str(column)] = talib.RSI(np.array(data[column], dtype='f8'), timeperiod)
    data['RSI_'+ str(column)] = data['RSI_'+str(column)].shift()
    return data
def get_RSI_intraday(data, column='Intraday Returns', timeperiod=7):   
    data['RSI_'+str(column)] = talib.RSI(np.array(data[column], dtype='f8'), timeperiod)
    data['RSI_'+ str(column)] = data['RSI_'+str(column)].shift()
    return data
def get_RSI_overnight(data, column='Overnight Returns', timeperiod=7):   
    data['RSI_'+str(column)] = talib.RSI(np.array(data[column], dtype='f8'), timeperiod)
    data['RSI_'+ str(column)] = data['RSI_'+str(column)].shift()
    return data
In [18]:
df = df.groupby('ticker').apply(get_RSI_first30).dropna()
df = df.groupby('ticker').apply(get_RSI_last30).dropna()
df = df.groupby('ticker').apply(get_RSI_intraday).dropna()
df = df.groupby('ticker').apply(get_RSI_overnight).dropna()

df.head(5)
Out[18]:
date ticker First 30 Intraday Returns Last 30 OR Overnight Returns RSI_First 30 RSI_Last 30 RSI_Intraday Returns RSI_Overnight Returns
13577 2006-02-21 00:00:00+00:00 Equity(24 [AAPL]) -0.002844 -0.000142 -0.001817 0.996598 -0.003402 48.016855 56.264533 52.712174 47.057132
13578 2006-02-21 00:00:00+00:00 Equity(60 [ABS]) 0.001987 0.002762 -0.001188 0.999606 -0.000394 50.341245 49.819532 52.106877 48.644796
13579 2006-02-21 00:00:00+00:00 Equity(62 [ABT]) -0.001117 0.004304 0.000681 0.995490 -0.004510 40.867892 62.093079 49.476252 53.565946
13580 2006-02-21 00:00:00+00:00 Equity(67 [ADSK]) -0.019737 -0.035369 0.000000 0.998809 -0.001191 53.432756 62.706817 60.843696 57.777930
13583 2006-02-21 00:00:00+00:00 Equity(114 [ADBE]) -0.002083 -0.015885 -0.001848 0.995592 -0.004408 53.761789 60.924024 60.632490 55.050145
In [19]:
df['First 30 Dec'] = pd.qcut(df['First 30'],10,labels = False)
df['Last 30 Dec'] = pd.qcut(df['Last 30'],10,labels = False)
df['Intraday Dec'] = pd.qcut(df['Intraday Returns'],10,labels = False)
df['Overnight Dec'] = pd.qcut(df['Overnight Returns'],10,labels = False)
df['RSI_First 30 Dec'] = pd.qcut(df['RSI_First 30'],10,labels = False)
df['RSI_Last 30 Dec'] = pd.qcut(df['RSI_Last 30'],10,labels = False)
df['RSI_Intraday Dec'] = pd.qcut(df['RSI_Intraday Returns'],10,labels = False)
df['RSI_Overnight Dec'] = pd.qcut(df['RSI_Overnight Returns'],10,labels = False)
In [20]:
df = df.dropna()
df.head(10)
Out[20]:
date ticker First 30 Intraday Returns Last 30 OR Overnight Returns RSI_First 30 RSI_Last 30 RSI_Intraday Returns RSI_Overnight Returns First 30 Dec Last 30 Dec Intraday Dec Overnight Dec RSI_First 30 Dec RSI_Last 30 Dec RSI_Intraday Dec RSI_Overnight Dec
13577 2006-02-21 00:00:00+00:00 Equity(24 [AAPL]) -0.002844 -0.000142 -0.001817 0.996598 -0.003402 48.016855 56.264533 52.712174 47.057132 3 2 4 2 3 8 6 3
13578 2006-02-21 00:00:00+00:00 Equity(60 [ABS]) 0.001987 0.002762 -0.001188 0.999606 -0.000394 50.341245 49.819532 52.106877 48.644796 6 3 5 4 5 4 6 4
13579 2006-02-21 00:00:00+00:00 Equity(62 [ABT]) -0.001117 0.004304 0.000681 0.995490 -0.004510 40.867892 62.093079 49.476252 53.565946 4 6 6 2 1 9 4 7
13580 2006-02-21 00:00:00+00:00 Equity(67 [ADSK]) -0.019737 -0.035369 0.000000 0.998809 -0.001191 53.432756 62.706817 60.843696 57.777930 0 4 0 3 6 9 9 9
13583 2006-02-21 00:00:00+00:00 Equity(114 [ADBE]) -0.002083 -0.015885 -0.001848 0.995592 -0.004408 53.761789 60.924024 60.632490 55.050145 3 2 1 2 7 9 9 8
13585 2006-02-21 00:00:00+00:00 Equity(128 [ADM]) -0.008803 -0.016029 -0.000719 1.000982 0.000982 45.911069 49.631564 47.945488 52.554460 1 3 1 5 2 4 3 6
13587 2006-02-21 00:00:00+00:00 Equity(168 [AET]) 0.002168 -0.002760 0.001088 1.000099 0.000099 50.543451 48.631218 46.413849 46.343653 6 6 4 4 5 4 2 2
13589 2006-02-21 00:00:00+00:00 Equity(205 [AGN]) 0.005586 -0.001003 -0.001676 1.000821 0.000821 80.142232 25.482152 61.985630 34.552089 7 2 4 5 9 0 9 0
13590 2006-02-21 00:00:00+00:00 Equity(239 [AIG]) -0.002203 -0.006779 0.003391 0.995015 -0.004985 47.556095 57.720570 44.182089 48.469603 3 8 2 1 3 8 1 3
13591 2006-02-21 00:00:00+00:00 Equity(328 [ALTR]) 0.000994 -0.009940 -0.002403 1.004995 0.004995 51.024134 59.740854 43.332244 56.249259 5 2 2 7 5 9 1 8
In [21]:
# Heatmap of RSI Intraday Dec/RSI Overnight Dec with mean of Overnight Returns
a = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Overnight Dec'])['Overnight Returns'].mean())
sns.heatmap(a.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Overnight Dec')
plt.title('RSI Intraday vs RSI Overnight with mean of Overnight Returns')
Out[21]:
<matplotlib.text.Text at 0x7f25cd7399d0>
In [22]:
# Heatmap of RSI Intraday Dec/RSI First 30 Dec with mean of Overnight Returns
b = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_First 30 Dec'])['Overnight Returns'].mean())
sns.heatmap(b.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Intraday vs RSI First 30 with mean of Overnight Returns')
Out[22]:
<matplotlib.text.Text at 0x7f25cdc9e790>
In [23]:
# Heatmap of RSI Intraday Dec/RSI Last 30 Dec with mean of Overnight Returns
c = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].mean())
sns.heatmap(c.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Intraday vs RSI Last 30 with mean of Overnight Returns')
Out[23]:
<matplotlib.text.Text at 0x7f25ce8f7850>
In [24]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with mean of Overnight Returns
d = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_First 30 Dec'])['Overnight Returns'].mean())
sns.heatmap(d.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Overnight vs RSI First 30 with mean of Overnight Returns')
Out[24]:
<matplotlib.text.Text at 0x7f25cedb5a50>
In [25]:
# Heatmap of RSI Overnight Dec/RSI Last 30 Dec with mean of Overnight Returns
e = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].mean())
sns.heatmap(e.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with mean of Overnight Returns')
Out[25]:
<matplotlib.text.Text at 0x7f25cde5d390>
In [26]:
# Heatmap of RSI First 30 Dec/RSI Last 30 Dec with mean of Overnight Returns
f = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].mean())
sns.heatmap(f.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_First 30 Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI First 30 vs RSI Last 30 with mean of Overnight Returns')
Out[26]:
<matplotlib.text.Text at 0x7f25cd51ad90>
In [27]:
# Heatmap of RSI Intraday Dec/RSI Overnight Dec with standard deviation of Overnight Returns
g = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Overnight Dec'])['Overnight Returns'].std())
sns.heatmap(g.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Overnight Dec')
plt.title('RSI Intraday vs RSI Overnight with standard deviation of Overnight Returns')
Out[27]:
<matplotlib.text.Text at 0x7f25cdcfb090>
In [28]:
# Heatmap of RSI Intraday Dec/RSI First 30 Dec with standard deviation of Overnight Returns
h = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_First 30 Dec'])['Overnight Returns'].std())
sns.heatmap(h.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Intraday vs RSI First 30 with standard deviation of Overnight Returns')
Out[28]:
<matplotlib.text.Text at 0x7f25ce8917d0>
In [29]:
# Heatmap of RSI Intraday Dec/RSI Last 30 Dec with standard deviation of Overnight Returns
i = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].std())
sns.heatmap(i.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Intraday vs RSI Last 30 with standard deviation of Overnight Returns')
Out[29]:
<matplotlib.text.Text at 0x7f25eb93b3d0>
In [30]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with standard deviation of Overnight Returns
j = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_First 30 Dec'])['Overnight Returns'].std())
sns.heatmap(j.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Overnight vs RSI First 30 with standard deviation of Overnight Returns')
Out[30]:
<matplotlib.text.Text at 0x7f25eb715b50>
In [31]:
# Heatmap of RSI Overnight Dec/RSI Last 30 Dec with standard deviation of Overnight Returns
k = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].std())
sns.heatmap(k.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with standard deviation of Overnight Returns')
Out[31]:
<matplotlib.text.Text at 0x7f25eb4ec850>
In [32]:
# Heatmap of RSI First 30 Dec/RSI Last 30 Dec with standard deviation of Overnight Returns
l = pd.Series(df.groupby(['RSI_First 30 Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].std())
sns.heatmap(l.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_First 30 Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI First 30 vs RSI Last 30 with standard deviation of Overnight Returns')
Out[32]:
<matplotlib.text.Text at 0x7f25e3536110>
In [33]:
# Heatmap of RSI Intraday Dec/RSI Overnight Dec with geometric mean of Overnight Returns
m = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Overnight Dec'])['OR'].apply(gmean))
sns.heatmap(m.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Overnight Dec')
plt.title('RSI Intraday vs RSI Overnight with geometric mean of Overnight Returns')
Out[33]:
<matplotlib.text.Text at 0x7f25e33117d0>
In [34]:
# Heatmap of RSI Intraday Dec/RSI First 30 Dec with geometric mean of Overnight Returns
n = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_First 30 Dec'])['OR'].apply(gmean))
sns.heatmap(n.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Intraday vs RSI First 30 with geometric mean of Overnight Returns')
Out[34]:
<matplotlib.text.Text at 0x7f25e306c3d0>
In [35]:
# Heatmap of RSI Intraday Dec/RSI Last 30 Dec with geometric mean of Overnight Returns
o = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Last 30 Dec'])['OR'].apply(gmean))
sns.heatmap(o.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Intraday vs RSI Last 30 with geometric mean of Overnight Returns')
Out[35]:
<matplotlib.text.Text at 0x7f25e1e030d0>
In [36]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with geometric mean of Overnight Returns
p = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_First 30 Dec'])['OR'].apply(gmean))
sns.heatmap(p.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Overnight vs RSI First 30 with geometric mean of Overnight Returns')
Out[36]:
<matplotlib.text.Text at 0x7f25cf1a5750>
In [37]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with geometric mean of Overnight Returns
q = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['OR'].apply(gmean))
sns.heatmap(q.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with geometric mean of Overnight Returns')
Out[37]:
<matplotlib.text.Text at 0x7f25cd37e450>
In [38]:
# Heatmap of RSI Overnight Dec/RSI Last 30 Dec with geometric mean of Overnight Returns
r = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['OR'].apply(gmean))
sns.heatmap(r.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with geometric mean of Overnight Returns')
Out[38]:
<matplotlib.text.Text at 0x7f25cb916190>
In [39]:
# Heatmap of RSI First 30 Dec/RSI Last 30 Dec with geometric mean of Overnight Returns
s = pd.Series(df.groupby(['RSI_First 30 Dec', 'RSI_Last 30 Dec'])['OR'].apply(gmean))
sns.heatmap(s.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_First 30 Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI First 30 vs RSI Last 30 with geometric mean of Overnight Returns')
Out[39]:
<matplotlib.text.Text at 0x7f25cb6e5e90>
In [40]:
# Heatmap of RSI Intraday Dec/RSI Overnight Dec with number of observations from Overnight Returns
t = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Overnight Dec'])['Overnight Returns'].count())
sns.heatmap(t.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Overnight Dec')
plt.title('RSI Intraday vs RSI Overnight with counts of observations from Overnight Returns')
Out[40]:
<matplotlib.text.Text at 0x7f25cb43d8d0>
In [41]:
# Heatmap of RSI Intraday Dec/RSI First 30 Dec with number of observations from Overnight Returns
u = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_First 30 Dec'])['Overnight Returns'].count())
sns.heatmap(u.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Intraday vs RSI First 30 with counts of observations from Overnight Returns')
Out[41]:
<matplotlib.text.Text at 0x7f25b8033c50>
In [42]:
# Heatmap of RSI Intraday Dec/RSI Last 30 Dec with number of observations from Overnight Returns
v = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].count())
sns.heatmap(v.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Intraday vs RSI Last 30 with counts of observations from Overnight Returns')
Out[42]:
<matplotlib.text.Text at 0x7f25a3bf4550>
In [43]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with number of observations from Overnight Returns
w = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_First 30 Dec'])['Overnight Returns'].count())
sns.heatmap(w.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Overnight vs RSI First 30 with counts of observations from Overnight Returns')
Out[43]:
<matplotlib.text.Text at 0x7f25a394b290>
In [44]:
# Heatmap of RSI Overnight Dec/RSI Last 30 Dec with number of observations from Overnight Returns
x = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].count())
sns.heatmap(x.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with counts of observations from Overnight Returns')
Out[44]:
<matplotlib.text.Text at 0x7f25a371ef50>
In [45]:
# Heatmap of RSI First 30 Dec/RSI Last 30 Dec with number of observations from Overnight Returns
y = pd.Series(df.groupby(['RSI_First 30 Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].count())
sns.heatmap(y.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = 'g')
plt.xlabel('RSI_First 30 Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI First 30 vs RSI Last 30 with counts of observations from Overnight Returns')
Out[45]:
<matplotlib.text.Text at 0x7f25a34f6610>
In [46]:
def pt_succeed_rate(data):
    sc = pd.Series(data > 0)
    pt = float(sum(sc))/float(len(data))
    return pt
In [47]:
# Heatmap of RSI Intraday Dec/RSI Overnight Dec with succeed rate of Overnight Returns
z = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Overnight Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(z.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Overnight Dec')
plt.title('RSI Intraday vs RSI Overnight with succeed rate of Overnight Returns')
Out[47]:
<matplotlib.text.Text at 0x7f25a3251150>
In [ ]:
# Heatmap of RSI Intraday Dec/RSI First 30 Dec with succeed rate of Overnight Returns
x1 = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_First 30 Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(x1.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Intraday vs RSI First 30 with succeed rate of Overnight Returns')
In [ ]:
# Heatmap of RSI Intraday Dec/RSI Last 30 Dec with succeed rate of Overnight Returns
y1 = pd.Series(df.groupby(['RSI_Intraday Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(y1.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_Intraday Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Intraday vs RSI Last 30 with succeed rate of Overnight Returns')
In [ ]:
# Heatmap of RSI Overnight Dec/RSI First 30 Dec with number of observations from Overnight Returns
y1 = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_First 30 Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(y1.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True)
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_First 30 Dec')
plt.title('RSI Overnight vs RSI First 30 with counts of observations from Overnight Returns')
In [ ]:
# Heatmap of RSI Overnight Dec/RSI Last 30 Dec with succeed rate of Overnight Returns
z1 = pd.Series(df.groupby(['RSI_Overnight Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(z1.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt ='.2%')
plt.xlabel('RSI_Overnight Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI Overnight vs RSI Last 30 with succeed rate of Overnight Returns')
In [ ]:
# Heatmap of RSI First 30 Dec/RSI Last 30 Dec with succeed rate of Overnight Returns
z3 = pd.Series(df.groupby(['RSI_First 30 Dec', 'RSI_Last 30 Dec'])['Overnight Returns'].apply(pt_succeed_rate))
sns.heatmap(z3.unstack(), linewidths = 1, cmap = 'RdYlGn', xticklabels=True, yticklabels=True, robust=True, annot=True, fmt = '.2%')
plt.xlabel('RSI_First 30 Dec')
plt.ylabel('RSI_Last 30 Dec')
plt.title('RSI First 30 vs RSI Last 30 with succeed rate of Overnight Returns')
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: