Exemple #1
0
    def select_x003(cls, st_df):
        """
        k30
        """
        name = "s003"

        mdi_df = ZB.mdi(st_df)
        x1 = (mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)) & (mdi_df["DIFF"] > mdi_df["DIFF"].shift(2))
        x2 = ZB.cross(mdi_df['ADX'], mdi_df['ADXR'])

        mdi_df[name] = False

        mdi_df.ix[x1 & x2, name] = True

        return mdi_df.ix[:, [name]]
Exemple #2
0
    def get_vol_kdj_values(cls, base_df, dt, ktype="60"):
        base_df = base_df[base_df.index <= dt].tail(cls.get_max_30k(ktype))
        data_df = gkd.Generator.generate_k_data(base_df, ktype=ktype)

        # 忽略当前volume
        data_df = data_df[:-1]

        data_df['v5'] = data_df['volume'].rolling(center=False,
                                                  min_periods=1,
                                                  window=5).sum()
        data_df['v15'] = data_df['volume'].rolling(center=False,
                                                   min_periods=1,
                                                   window=15).sum()

        zb_df = ZB.kdj(data_df)

        zb_df['direction'] = 1

        # 向下的趋势
        xd1 = (zb_df['kdj_d'] < zb_df['kdj_d'].shift(1)) | (
            zb_df['kdj_k'] < zb_df['kdj_k'].shift(1))

        zb_df.ix[xd1, 'direction'] = -1
        zb_df['energy_d'] = zb_df['direction'] * zb_df['kdj_d']

        data_df['direction'] = zb_df['direction']
        data_df['energy_kdj_d'] = zb_df['energy_d']
        data_df['energy_vol_kdj_d'] = data_df['energy_kdj_d'] * (
            data_df['v5'] / data_df['v15'])

        cns = ['direction', 'energy_kdj_d', 'energy_vol_kdj_d']

        return cls._extract(data_df, cns)
Exemple #3
0
    def get_mdi_values(cls, base_df, dt, ktype="60"):
        base_df = base_df[base_df.index <= dt].tail(cls.get_max_30k(ktype))
        data_df = gkd.Generator.generate_k_data(base_df, ktype=ktype)

        zb_df = ZB.mdi(data_df)

        zb_df['energy'] = zb_df["DIFF"] * zb_df['ADXR'] / 100

        e1 = zb_df['energy']
        e3 = zb_df['energy'].shift(3)
        e5 = zb_df['energy'].shift(5)
        e9 = zb_df['energy'].shift(9)
        e15 = zb_df['energy'].shift(15)

        zb_df['e_1_3'] = (e1 - e3) / e3 * 100
        zb_df['e_1_5'] = (e1 - e5) / e5 * 100
        zb_df['e_1_9'] = (e1 - e9) / e9 * 100

        zb_df['e_3_5'] = (e3 - e5) / e5 * 100
        zb_df['e_3_9'] = (e3 - e9) / e9 * 100
        zb_df['e_3_15'] = (e3 - e15) / e15 * 100

        zb_df['e_5_9'] = (e5 - e9) / e9 * 100
        zb_df['e_5_15'] = (e5 - e15) / e15 * 100

        cns = [
            'ADX', 'ADXR', 'DIFF', 'energy', 'e_1_3', 'e_1_5', 'e_1_9',
            'e_3_5', 'e_3_9', 'e_3_15', 'e_5_9', 'e_5_15'
        ]
        return cls._extract(zb_df, cns)
    def select_x003(cls, st_df):
        """
        k30
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df)

        x1 = mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)
        x2 = ZB.cross(mdi_df['ADXR'], mdi_df['ADX'])

        t1 = (mdi_df.index.hour > 10) & (mdi_df.index.hour <= 14)
        mdi_df[name] = False

        mdi_df.ix[t1 & x1 & x2, name] = True

        return mdi_df.ix[:, [name]]
    def select_x003(cls, st_df):
        """
        k30
        """
        name = "s003"

        kdj_df = ZB.kdj(st_df)

        x1 = ZB.cross(kdj_df["kdj_k"], kdj_df["kdj_d"])
        x2 = kdj_df["kdj_k"] <= 60

        t1 = kdj_df.index.hour >= 11

        kdj_df[name] = False

        kdj_df.ix[t1 & x1 & x2, name] = True

        return kdj_df.ix[:, [name]]
    def select_x005(cls, st_df):
        name = "s005"

        mdi_df = ZB.mdi(st_df)
        x1 = mdi_df["DIFF"] < mdi_df["DIFF"].shift(1)

        mdi_df[name] = False

        mdi_df.ix[x1, name] = True

        return mdi_df.ix[:, [name]]
Exemple #7
0
    def select_x003(cls, st_df):
        """

        """
        name = "s004"

        kdj_df = ZB.kdj(st_df)

        x1 = kdj_df["kdj_k"] < kdj_df['kdj_d']
        x2 = kdj_df["kdj_k"] >= kdj_df["kdj_k"].shift(1)

        x3 = ZB.cross(kdj_df["kdj_k"], kdj_df["kdj_d"])

        t1 = kdj_df.index.hour >= 13

        kdj_df[name] = False

        kdj_df.ix[t1 & x1 & x2, name] = True
        kdj_df.ix[t1 & x3, name] = True

        return kdj_df.ix[:, [name]]
    def select_x003(cls, st_df):
        """
        k30
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df)
        ma_df = ZB.ma(st_df)
        close = st_df['close']

        x1 = ZB.cross(mdi_df['ADX'], mdi_df['ADXR']) & (mdi_df['ADXR'] < 30)
        x2 = mdi_df['DIFF'] > mdi_df['DIFF'].shift(1)
        x21 = (mdi_df['PDI'] > mdi_df['ADXR']) & (mdi_df['PDI'] > mdi_df['MDI'])
        x3 = (ma_df['ma50'] <= close + (close * 0.02)) & (ma_df['ma50'] <= close - (close * 0.02))

        t1 = (mdi_df.index.hour > 10) & (mdi_df.index.hour <= 14)
        mdi_df[name] = False

        mdi_df.ix[t1 & x1 & x2 & x21 & x3, name] = True

        return mdi_df.ix[:, [name]]
    def select_x004(cls, st_df):
        """
        k60
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df, d=6)
        kdj_df = ZB.kdj(st_df)

        x1 = mdi_df["DIFF"] < mdi_df["DIFF"].shift(1)
        k1 = kdj_df["kdj_d"] < kdj_df["kdj_d"].shift(1)

        max_close = st_df['high'].rolling(center=False,
                                          min_periods=1,
                                          window=6).max()
        x2 = st_df['close'] <= (max_close - (max_close * 0.03))

        mdi_df[name] = False

        mdi_df.ix[(x1 & k1) | x2, name] = True

        return mdi_df.ix[:, [name]]
    def select_x004(cls, st_df):
        """
        k60
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df)
        ma_df = ZB.ma(st_df)

        x1 = mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)

        close = st_df['close']
        mdi_df['MAX_ADXR'] = mdi_df['ADXR'].rolling(center=False, min_periods=1, window=10).max()
        #
        # x2 = (mdi_df['ADXR'] < 24) & (mdi_df['DIFF'] > -30)
        x3 = (ma_df['ma50'] <= close + (close * 0.02)) & (ma_df['ma50'] <= close - (close * 0.02))
        # x4 = mdi_df['MAX_ADXR'] < 30
        mdi_df[name] = False

        # mdi_df.ix[x1 & x2 & x3 & kk, name] = True
        mdi_df.ix[x1 & x3, name] = True

        return mdi_df.ix[:, [name]]
Exemple #11
0
    def select_x004(cls, st_df):
        """
        k60
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df)
        x1 = mdi_df['DIFF'] > mdi_df['DIFF'].shift(1)

        mdi_df[name] = False

        mdi_df.ix[x1, name] = True

        return mdi_df.ix[:, [name]]
Exemple #12
0
    def select_x005(cls, st_df):
        """
        kd
        """
        name = "selected"

        kdj_df = ZB.kdj(st_df)

        x1 = kdj_df['kdj_k'] > kdj_df['kdj_k'].shift()

        kdj_df[name] = False

        kdj_df.ix[x1, name] = True

        return kdj_df.ix[:, [name]]
Exemple #13
0
    def select_x004(cls, st_df):
        """

        """
        name = "s004"

        kdj_df = ZB.kdj(st_df)

        diff = kdj_df['kdj_k'] - kdj_df['kdj_d']
        kdj_df["diff"] = diff.ewm(com=1).mean()

        # 高位, 确认趋势变坏
        x1 = kdj_df["diff"] > 0
        x2 = kdj_df["diff"] < kdj_df["diff"].shift(1)
        x3 = kdj_df["diff"].shift(1) <= kdj_df["diff"].shift(2)

        c1 = ZB.cross(kdj_df['kdj_d'], kdj_df['kdj_k'])
        c2 = kdj_df['kdj_k'] >= 30
        kdj_df[name] = False

        kdj_df.ix[x1 & x2 & x3, name] = True
        kdj_df.ix[c1 & c2, name] = True

        return kdj_df.ix[:, [name]]
Exemple #14
0
    def select_x006(cls, st_df):
        """
        k60
        """
        name = "s006"

        mdi_df = ZB.mdi(st_df)

        x10 = mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)

        mdi_df[name] = False

        mdi_df.ix[x10, name] = True

        return mdi_df.ix[:, [name]]
    def select_x005(cls, st_df):
        """
        kd
        """
        name = "selected"

        mdi_df = ZB.mdi(st_df)

        # x1 = kdj_df['kdj_k'] > kdj_df['kdj_k'].shift()

        mdi_df[name] = True

        x1 = mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)
        mdi_df.ix[x1, name] = True

        return mdi_df.ix[:, [name]]
Exemple #16
0
    def select_x005(cls, st_df):
        """
        kd
        """
        name = "s005"

        kdj_df = ZB.kdj(st_df)

        x1 = kdj_df["kdj_k"] > kdj_df["kdj_k"].shift(1)
        # x2 = kdj_df["kdj_k"] <= 80

        kdj_df[name] = False

        kdj_df.ix[x1, name] = True

        return kdj_df.ix[:, [name]]
Exemple #17
0
    def select_x004(cls, st_df):
        """
        k60
        """
        name = "s004"

        mdi_df = ZB.mdi(st_df)

        x1 = mdi_df["DIFF"] > mdi_df["DIFF"].shift(1)
        # x2 = mdi_df['ADXR'] < mdi_df['ADXR'].shift(1)

        mdi_df[name] = False

        mdi_df.ix[x1, name] = True

        return mdi_df.ix[:, [name]]
    def select_x004(cls, st_df):
        """
        k60
        """
        name = "s004"

        kdj_df = ZB.kdj(st_df)

        x1 = kdj_df["kdj_k"] > kdj_df["kdj_k"].shift(1)
        x2 = kdj_df["kdj_k"] <= 50

        kdj_df[name] = False

        kdj_df.ix[x1 & x2, name] = True

        return kdj_df.ix[:, [name]]
Exemple #19
0
    def get_kdj_values(cls, base_df, dt, ktype="60"):
        base_df = base_df[base_df.index <= dt].tail(cls.get_max_30k(ktype))
        data_df = gkd.Generator.generate_k_data(base_df, ktype=ktype)

        zb_df = ZB.kdj(data_df)

        cur_d = zb_df['kdj_d']
        max_d = zb_df['kdj_d'].rolling(center=False, min_periods=1,
                                       window=20).max()
        min_d = zb_df['kdj_d'].rolling(center=False, min_periods=1,
                                       window=20).max()

        zb_df['up_ratio'] = (cur_d - min_d) / cur_d
        zb_df['down_ratio'] = (max_d - cur_d) / max_d

        cns = ['kdj_k', 'kdj_d', 'up_ratio', 'down_ratio']
        return cls._extract(zb_df, cns)
Exemple #20
0
    def select_x005(cls, st_df):
        """
        k60
        """
        name = "s005"

        kdj_df = ZB.kdj(st_df)

        diff = kdj_df['kdj_k'] - kdj_df['kdj_d']
        kdj_df["diff"] = diff.ewm(com=2).mean()

        x10 = kdj_df["diff"] > kdj_df["diff"].shift(1)
        x11 = (kdj_df["kdj_k"] > kdj_df["kdj_k"].shift(1)) & (
            kdj_df["kdj_k"] > kdj_df["kdj_k"].shift(2))
        x2 = kdj_df["diff"] <= 0

        kdj_df[name] = False

        kdj_df.ix[x2 & x10 & x11, name] = True

        return kdj_df.ix[:, [name]]
Exemple #21
0
    def get_ma_values(cls, base_df, dt, ktype="60"):
        """
        描述了均线的分布情况
        :param base_df:
        :param dt:
        :param ktype:
        :return:
        """
        base_df = base_df[base_df.index <= dt].tail(cls.get_max_30k(ktype))
        data_df = gkd.Generator.generate_k_data(base_df, ktype=ktype)

        ma_df = ZB.ma(data_df)
        ma_df['close'] = data_df['close']

        ma_df['m_1_5'] = (ma_df['close'] - ma_df['ma5']) / ma_df['ma5'] * 100
        ma_df['m_1_10'] = (ma_df['close'] -
                           ma_df['ma10']) / ma_df['ma10'] * 100
        ma_df['m_5_10'] = (ma_df['ma5'] - ma_df['ma10']) / ma_df['ma10'] * 100
        ma_df['m_5_20'] = (ma_df['ma5'] - ma_df['ma20']) / ma_df['ma20'] * 100
        ma_df['m_10_20'] = (ma_df['ma10'] -
                            ma_df['ma20']) / ma_df['ma20'] * 100
        ma_df['m_10_50'] = (ma_df['ma10'] -
                            ma_df['ma50']) / ma_df['ma50'] * 100

        ma_df['avg'] = (ma_df['m_1_5'] + ma_df['m_1_10'] + ma_df['m_5_10'] +
                        ma_df['m_5_20'] + ma_df['m_10_20'] +
                        ma_df['m_10_50']) / 6

        ma_df['abs'] = (ma_df['m_1_5'].abs() + ma_df['m_1_10'].abs() +
                        ma_df['m_5_10'].abs() + ma_df['m_5_20'].abs() +
                        ma_df['m_10_20'].abs() + ma_df['m_10_50'].abs()) / 6

        cns = [
            'm_1_5', 'm_1_10', 'm_5_10', 'm_5_20', 'm_10_20', 'm_10_50', 'avg',
            'abs'
        ]
        return cls._extract(ma_df, cns)
Exemple #22
0
# coding=utf-8
import pandas as pd
import matplotlib.pyplot as plt
import gen_k_data as gkd
from zibiao import ZB

if __name__ == '__main2__':
    pd.set_option("display.max_columns", 500)

    df = gkd.read_5min_data('files/SH#600280.txt')
    df = df.tail(2000)
    df = df.head(1000)

    df_d = gkd.generate_k_data(df, ktype="30")

    df_kdj = ZB.kdj(df_d)
    df_mdi = ZB.mdi(df_d)

    xx_df = pd.concat([df_kdj, df_mdi], axis=1)

    xx_df = xx_df.reset_index(drop=True)

    diff1 = xx_df['kdj_k'] - xx_df['kdj_d']
    xx_df["diff1"] = diff1.ewm(com=3).mean()

    diff2 = xx_df['PDI'] - xx_df['MDI']
    xx_df["diff2"] = diff2.ewm(com=3).mean()

    del xx_df["PDI"]
    del xx_df["MDI"]
    del xx_df["ADX"]