Exemple #1
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_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 #3
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 #4
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]]
Exemple #5
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 = "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]]
Exemple #7
0
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"]
    del xx_df["ADXR"]