Beispiel #1
0
def main(df):
    df = df.reset_index("date", drop = True)
    df = base1.main(df)
    for each in ["ta_ROC_5","ta_WILLR_2", "ta_ROC_7", "ta_WILLR_7", "ta_WILLR_5", "ta_STOCHRSI_slowd_28_5_3", "ta_NATR_28"]:
        for i in [1, 2, 5, 7, 14]:
            df["%s-shift-%d" % (each, i)] = df[each].shift(i)
    return df
Beispiel #2
0
def main(df):
    df = base1.main(df)
    lipt = get_lipt()
    df = df[lipt]
    sym = df['sym'].values[0]
    vol = pd.read_csv(os.path.join(base.dir_vol(), sym + ".csv"))
    d = {'Date': 'date'}
    for each in vol.columns[1:]:
        d[each] = 'ta_' + each
    vol = vol.rename(columns=d)
    vol = vol.fillna(0)
    dfDate = df[["date"]]
    vol = pd.merge(how='left',
                   left=dfDate,
                   right=vol,
                   left_on='date',
                   right_on='date')
    vol = vol.fillna(0)
    print df.shape[1]
    df = pd.merge(how='left',
                  left=df,
                  right=vol,
                  left_on="date",
                  right_on="date")
    print df.shape[1]
    return df
Beispiel #3
0
def main(df):
    df = df.reset_index("date", drop=True)
    df = base1.main(df)
    df = sig_123recall.main(df)
    df = sig_adx.main(df)
    #df = sig_upbreak.main(df)

    #assert 40 == df.shape[1]
    return df
Beispiel #4
0
def main(df):
    df = df.reset_index("date", drop=True)
    df = base1.main(df)
    df = sig_123recall.main(df)
    df = sig_adx.main(df)
    df = sig_upbreak.main(df)

    # assert 40 == df.shape[1]
    return df
Beispiel #5
0
def main(df):
    df.reset_index(drop=True, inplace=True)
    df = base1.main(df)
    lipt = get_lipt()
    df  =  df[lipt]
    df = sig_adx(df)
    df.reset_index(drop=True, inplace=True)
    assert 38 == df.shape[1]
    return df
Beispiel #6
0
def main(df):
    df = df.reset_index("date", drop=True)
    df = base1.main(df)
    lipt = get_lipt()
    df = df[lipt]
    del df["ta_ADX_7"]
    df = adx_sig(df)
    df = df.eset_index()
    assert 37 == df.shape[1]
    return df
Beispiel #7
0
def main(df):
    df = df.reset_index("date", drop=True)
    df = base1.main(df)
    for each in [
            "ta_ROC_5", "ta_WILLR_2", "ta_ROC_7", "ta_WILLR_7", "ta_WILLR_5",
            "ta_STOCHRSI_slowd_28_5_3", "ta_NATR_28"
    ]:
        for i in [1, 2, 5, 7, 14]:
            df["%s-shift-%d" % (each, i)] = df[each].shift(i)
    return df
Beispiel #8
0
def main(df):
    df = df.reset_index("date", drop=True)
    df = base1.main(df)
    df = sig_123recall.main(df)
    df = sig_adx.main(df)
    df = sig_upbreak.main(df)
    df = sig_ta_PLUS_DM_28.main(df)
    del df["ta_PLUS_DM_28"]

    #assert 40 == df.shape[1]
    return df
def main(df):
    df = base1.main(df)
    lipt = get_lipt()
    df = df[lipt]
    df["shift"] = df['close'].shift(5)
    df["trend"] = df['close'] / df['shift']
    df = df[df["trend"] < 1.0]
    del df["trend"]
    del df["shift"]
    assert 37 == df.shape[1]
    return df
Beispiel #10
0
def main(df):
    df = df.reset_index("date", drop = True)
    df = base1.main(df)
    df = sig_123recall.main(df)
    df = sig_adx.main(df)
    df = sig_upbreak.main(df)
    df = sig_ta_PLUS_DM_28.main(df)
    del df["ta_PLUS_DM_28"]

    #assert 40 == df.shape[1]
    return df
Beispiel #11
0
def main(df):
    df['closer'] = df['close'] / df['close'].shift(1)
    closes=df['closer'].values
    df = base1.main(df)
    for tri in [(6,13,8),(12, 26, 9), (24, 52, 18)]:
        macd = talib.MACD(closes, tri[0], tri[1], tri[2])
        df['ta_MACD_macd_%d_%d_%d'%(tri[0],tri[1],tri[2])] = macd[0]
        df['ta_MACD_macdsignal_%d_%d_%d'%(tri[0],tri[1],tri[2])] = macd[1]
        df['ta_MACD_macdhist_%d_%d_%d'%(tri[0],tri[1],tri[2])] = macd[2]
    print df.shape
    return df
Beispiel #12
0
def main(df):
    df['closer'] = df['close'] / df['close'].shift(1)
    closes = df['closer'].values
    df = base1.main(df)
    for tri in [(6, 13, 8), (12, 26, 9), (24, 52, 18)]:
        macd = talib.MACD(closes, tri[0], tri[1], tri[2])
        df['ta_MACD_macd_%d_%d_%d' % (tri[0], tri[1], tri[2])] = macd[0]
        df['ta_MACD_macdsignal_%d_%d_%d' % (tri[0], tri[1], tri[2])] = macd[1]
        df['ta_MACD_macdhist_%d_%d_%d' % (tri[0], tri[1], tri[2])] = macd[2]
    print df.shape
    return df
Beispiel #13
0
def main(df):
    df = base1.main(df)
    df.reset_index(inplace=True,drop=True)
    orig_feats = base.get_feat_names(df)
    df = merge(df, 1)
    df = merge(df, 2)
    df = merge(df, 3)
    for each in orig_feats:
        if not each.startswith("ta_ADX"):
            del df[each]
    print list(df.columns)
    return df
Beispiel #14
0
def main(df):
    df = base1.main(df)
    lipt = get_lipt()
    df = df[lipt]
    df["shift"] = df['close'].shift(5)
    df["trend"] = df['close'] / df['shift']
    #print df[['date','sym','close',"shift", 'trend']].tail(10)
    df = df[df["trend"] > 1.0]
    del df["trend"]
    del df["shift"]
    assert 37 == df.shape[1]
    return df
def main(df):
    df = base1.main(df)
    df.reset_index(inplace=True,drop=True)
    orig_feats = base.get_feat_names(df)
    print df.shape
    df = merge(df, 1)
    print df.shape
    df = merge(df, 2)
    print df.shape
    for each in orig_feats:
        del df[each]
    print df.shape
    return df
Beispiel #16
0
def main(df):
    df = base1.main(df)
    df.reset_index(inplace=True, drop=True)
    orig_feats = base.get_feat_names(df)
    print df.shape
    df = merge(df, 1)
    print df.shape
    df = merge(df, 2)
    print df.shape
    for each in orig_feats:
        del df[each]
    print df.shape
    return df
Beispiel #17
0
def main(df):
    df = base1.main(df)
    lipt = get_lipt()
    df = df[lipt]

    df.reset_index(drop=True)

    print df.shape
    for i in range(14, 28):
        df = df.join(pta.PDM(df, i))
    print df.shape
    #for i in (28,):
    #    ma = pta.MA(df, i)
    #    df["ta_MA_diff_%d" % i] = 100 * df["close"] / ma
    #for d in [(5, 7), (7,14), (14,21), (21,28), (7,21), (7,28)]:
    #    df["ta_MA_diff_%d_%d"%(d[0],d[1])] = 100 * pta.MA(df,d[1])/pta.MA(df,d[0])
    return df
def main(df):
    df = base1.main(df)
    df.reset_index(inplace=True,drop=True)

    dfStable = pd.read_pickle(os.path.join(dataroot,
                              "phase1_dump",
                              "sp500_base1_stable.pkl"))
    dfStable = dfStable[dfStable.direct != 0]
    tobe = []
    for i, each in  dfStable.iterrows():
        name = each["name"]
        fname = each["fname"]
        start = each["start"]
        end = each["end"]
        #df.loc[:,name] = df.apply(lambda row:
        #             1 if ((row[fname] >= start) and (row[fname] < end)) else 0, axis=1)
        new = df.apply(lambda row:
                     1 if ((row[fname] >= start) and (row[fname] < end)) else 0, axis=1)
        tobe.append(pd.Series(new, name = name))
    df = df.join(pd.DataFrame(tobe).transpose())
    return df
Beispiel #19
0
def main(df):
    df = base1.main(df)
    df.reset_index(inplace=True, drop=True)

    dfStable = pd.read_pickle(
        os.path.join(dataroot, "phase1_dump", "sp500_base1_stable.pkl"))
    dfStable = dfStable[dfStable.direct != 0]
    tobe = []
    for i, each in dfStable.iterrows():
        name = each["name"]
        fname = each["fname"]
        start = each["start"]
        end = each["end"]
        #df.loc[:,name] = df.apply(lambda row:
        #             1 if ((row[fname] >= start) and (row[fname] < end)) else 0, axis=1)
        new = df.apply(lambda row: 1 if
                       ((row[fname] >= start) and (row[fname] < end)) else 0,
                       axis=1)
        tobe.append(pd.Series(new, name=name))
    df = df.join(pd.DataFrame(tobe).transpose())
    return df
Beispiel #20
0
def main(df):
    df1 = base1.main(df)
    df1.reset_index(drop=True, inplace=True)

    df2 = stable_3.main(df)
    df2.reset_index(drop=True, inplace=True)

    l = [
        'ta_CMO_14', 'ta_RSI_14', 'ta_CMO_7', 'ta_RSI_7', 'ta_CMO_10',
        'ta_RSI_10', 'ta_TRIX_2', 'ta_RSI_28', 'ta_CMO_28', 'ta_RSI_5',
        'ta_STOCHRSI_slowd_5_20_12', 'ta_ROC_7', 'ta_ROCR100_7', 'ta_ROCP_7',
        'ta_ROCR_7', 'ta_STOCHRSI_slowd_7_20_12', 'ta_RSI_2', 'ta_ROC_5',
        'ta_ROCR100_5', 'ta_ROCR_5', 'ta_ROCP_5', 'ta_WILLR_10', 'ta_WILLR_14',
        'ta_ROC_2', 'ta_ROCR100_2', 'ta_ROCP_2', 'ta_ROCR_2', 'ta_WILLR_7'
    ]
    df1 = feat_select.append_deep_feats(df1, l)

    df1 = df1[base.get_feat_names(df1).extend(["date"])]
    print df2.shape
    df2 = df2.merge(df1, left_on='date', right_on="date", how='inner')
    print df2.shape
    return df2
def main(df):
    df1 = base1.main(df)
    df1.reset_index(drop=True, inplace=True)

    df2 = stable_3.main(df)
    df2.reset_index(drop=True, inplace=True)

    l = ['ta_CMO_14', 'ta_RSI_14','ta_CMO_7','ta_RSI_7','ta_CMO_10',
         'ta_RSI_10',
         'ta_TRIX_2',
         'ta_RSI_28',
         'ta_CMO_28',
         'ta_RSI_5',
         'ta_STOCHRSI_slowd_5_20_12',
         'ta_ROC_7',
         'ta_ROCR100_7',
         'ta_ROCP_7',
         'ta_ROCR_7',
         'ta_STOCHRSI_slowd_7_20_12',
         'ta_RSI_2',
         'ta_ROC_5',
         'ta_ROCR100_5',
         'ta_ROCR_5',
         'ta_ROCP_5',
         'ta_WILLR_10',
         'ta_WILLR_14',
         'ta_ROC_2',
         'ta_ROCR100_2',
         'ta_ROCP_2',
         'ta_ROCR_2',
         'ta_WILLR_7']
    df1 = feat_select.append_deep_feats(df1,l)

    df1 = df1[base.get_feat_names(df1).extend(["date"])]
    print df2.shape
    df2 = df2.merge(df1, left_on='date', right_on="date", how='inner')
    print df2.shape
    return df2
Beispiel #22
0
def main(df):
    df = base1.main(df)
    lipt = get_lipt()
    df  =  df[lipt]
    assert 37 == df.shape[1]
    return df
Beispiel #23
0
def main(df):
    df = base1.main(df)
    df = cdl.main(df)
    return df
Beispiel #24
0
def main(df):
    df = base1.main(df)
    df = cdl.main(df)
    print df.shape
    return df
Beispiel #25
0
def main(df):
    df = base1.main(df)
    df = cdl.main(df)
    return df