예제 #1
0
def main(df):
    def call(row):
        if row["adx"] > 30 \
           and row["diff"] < 1.0 \
           and row["diff_shift1"] < 1.0 \
           and row["diff_shift2"] < 1.005 :
            return 1
        return 0

    df.reset_index(drop=True, inplace=True)
    df["adx"] = pta.ADX(df, 14, 7)
    df["diff"] = df.close / df.close.shift(1)

    df["diff_shift1"] = df["diff"].shift(1)
    df["diff_shift2"] = df["diff"].shift(2)
    df["diff_shift3"] = df["diff"].shift(3)

    df["ta_sig_123recall"] = df.apply(lambda row: call(row), axis=1)

    del df["adx"]
    del df["diff"]
    del df["diff_shift1"]
    del df["diff_shift2"]
    del df["diff_shift3"]
    return df
예제 #2
0
def main(df):
    highs = df['high'].values
    lows = df['low'].values
    closes = df['close'].values

    df = df.join(pta.MDI(df, span))
    df = df.join(pta.PDI(df, span))
    df = df.join(pta.ADX(df, span, span))

    df["cross_%d" % span] = df["ta_PDI_%d" % span] / df["ta_MDI_%d" % span]
    df["cross_%d_shift_1" % span] = df["cross_%d" % span].shift(1)
    df["ta_sig_adx"] = df.apply(lambda row: adx_signal(row), axis=1)
    del df["ta_MDI_%d" % span]
    del df["ta_PDI_%d" % span]
    del df["ta_ADX_%d_%d" % (span, span)]
    del df["cross_%d" % span]
    del df["cross_%d_shift_1" % span]
    return df
예제 #3
0
def main(df):
    def call(row):
        if row["adx"] > 40 and row["is_in"] > 0 and row["is_in_shift1"] > 0:
            return 1.0
        return 0.0

    def call_in(row):
        if row['high'] > row['high_shift1'] and row['low'] < row['low_shift1']:
            return 1
        return 0

    df.reset_index(drop=True, inplace=True)
    df["high_shift1"] = df["high"].shift(1)
    df["low_shift1"] = df["low"].shift(1)
    df["is_in"] = df.apply(lambda row: call_in(row), axis=1)
    df["is_in_shift1"] = df["low"].shift(1)
    df["adx"] = pta.ADX(df, 14, 14)

    df["ta_sig_spoon"] = df.apply(lambda row: call(row), axis=1)
    return df
예제 #4
0
def sig_adx(df):
    highs = df['high'].values
    lows = df['low'].values
    closes=df['close'].values

    df['ta_NATR_%d' % 14] = talib.NATR(highs, lows, closes, 14)
    df = df.join(pta.MDI(df, span))
    df = df.join(pta.PDI(df, span))
    df = df.join(pta.ADX(df, span, span))
    
    df["cross_%d" % span] = df["ta_PDI_%d" % span] / df["ta_MDI_%d" % span]
    df["cross_%d_shift_1" % span ] = df["cross_%d" % span].shift(1)
    df["ta_adx_signal_%d" % span] = df.apply(lambda row: adx_signal(row), axis = 1) 

    del df["ta_MDI_%d" % span]
    del df["ta_PDI_%d" % span]
    del df["ta_ADX_%d_%d" % (span,span)]
    del df["cross_%d" % span] 
    del df["cross_%d_shift_1" % span]
    return df