Beispiel #1
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'hk_kline_day'
    pixel = 64
    # path = "f://zjf/image/USA_boll_kline_day_test"
    interval = KlineInfo.get_interval(kline)
    detal = KlineInfo.get_detal(kline)
    tabel_name = "boll_" + kline
    # path = "f://zjf/image/ma_kline_min30_test"
    for sc in stocks:
        end_time = dt.datetime(2018, 6, 25)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -203)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= 200:
            continue
        data = CalBoll.cal_boll(data, interval)
        data = data.dropna()
        while end_time > dt.datetime(2016, 1, 1):
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            date = data0['date']
            data0 = CalBoll.data_normalization(data0, pixel)
            data0['date'] = date
            data0['profit'] = profit
            if len(data0) < pixel:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[len(data0) - 1]
            date = data0.date.iloc[len(data0) - 1]
            if 'min' in kline:
                if abs(profit) > 0.11:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
            try:
                visualization.drow_boll_line(data=data0,
                                             profits=profit,
                                             date=date,
                                             code=sc,
                                             pixel=pixel,
                                             table_name=tabel_name)
            except Exception as e:
                pass
            data = data[
                data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date
    return 1
Beispiel #2
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'hk_kline_day'
    table_name='MA_'+kline
    pixel=64
    interval = KlineInfo.get_interval(kline)
    for sc in stocks:
        end_time = dt.datetime(2018, 6, 25)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -203)['date'], end_date=end_time,
                                   kline=kline, timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMa.cal_ma(data, interval)
        data = data.dropna()
        print(sc)
        while end_time > dt.datetime(2016, 1, 1):
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            date = data0['date']
            price=data0.close.iloc[0]
            data0 = CalMa.data_normalization(data0,pixel=pixel)
            data0['date'] = date
            data0['profit'] = profit
            if len(data0) < pixel or price<2:
                break
            date = data0.date.iloc[len(data0) - 1]
            profit = data0.profit.iloc[len(data0) - 1]
            if 'min' in kline:
                    if abs(profit) > 0.11:
                        data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                        continue
            else:
                if abs(profit) > 0.1*interval:
                    data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                    continue
            data0 = data0.reset_index(drop=True)



            try:
                visualization.draw_ma_line(data=data0, profits=profit,
                                           date=date, code=sc,
                                           table_name=table_name,pixel=pixel)
            except Exception as e:
                print(e)
                pass
            data = data[data.date<dt.datetime(date.year,date.month,date.day)]
            end_time = date
    return 1
Beispiel #3
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'index_min5'
    pixel=54
    n=5
    count=2
    interval = KlineInfo.get_interval(kline=kline)
    detal=KlineInfo.get_detal(kline=kline)
    table_name='A_Volume_'+kline+'_version5'
    print(table_name)
    for sc in stocks:
        end_time = dt.datetime(2018, 8, 15)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -203)['date'], end_date=end_time,
                                   kline=kline, timemerge=True)
        if len(data) <= 200 :
            continue
        data=CalMa.cal_profit(data,interval,detal)
        data=data.dropna()
        d = data.date.iloc[-1]
        data=data[data.date<=dt.datetime(d.year,d.month,d.day,9,55)]
        print(sc)
        while end_time > start_time:
            data0 = data.tail(pixel*4)
            amax=data0.volume.max()
            data0 = data0.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[ - 1]
            profitself = data0.profit_self.iloc[- 1]
            date = data0['date']
            if len(data0) < pixel:
                break
            date2 = date.iloc[ - 6]
            date1 = date.iloc[ - 1]
            data0=CalMa.data_normalization_volume2(data0,pixel=pixel+n*count,amax=amax)
            if 'min' in kline:
                if 'A' in table_name:
                    if date1.hour != 9 and date1.minute!=55:
                        data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, 9, 55)]
                        break
                if abs(profit) > 0.11 or abs(profitself)>0.097:
                    data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, 9, 55)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, 9, 55)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, 9, 55)]
                        print(sc, str(profitself) + '_' + str(date))
                        continue
            try:
                visualization.draw_volume(data=data0, profits=profit,
                                          date=date1, code=sc,
                                          table_name=table_name, pixel=pixel, n=n,
                                          count=count)
                pass
            except Exception as e:
                print(e)
                pass
            data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day,9,55)]
            end_time = date2

    return 1
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'index_min5'
    pixel = 128
    n = 0
    count = 0
    hour = 9
    minute = 55
    off = 203
    interval = KlineInfo.get_interval(kline=kline)
    detal = KlineInfo.get_detal(kline=kline)
    table_name = 'A_MA_index_min5_time955_pixel128'
    print(table_name)
    for sc in stocks:
        end_time = dt.datetime(2018, 8, 10)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -off)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMa.cal_ma(data=data, interval=interval, detal=detal)
        data = data.dropna()
        d = data.date.iloc[-1]
        data = data[
            data.date <= dt.datetime(d.year, d.month, d.day, hour, minute)]
        print(sc)
        while end_time > start_time:
            # print(sc,dt.datetime.now())
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            profit_self = data0['profit_self']
            date = data0['date']
            # amin, amax = data0.low.min(), data0.high.max()
            if len(data0) < pixel:
                break
            date2 = date.iloc[pixel - interval - 1]
            date1 = date.iloc[pixel - 1]
            data0 = CalMa.data_normalization_ok(data0, pixel=pixel + n * count)
            profit = profit.iloc[pixel - 1]
            profitself = profit_self.iloc[pixel - 1]
            profit_relative = 0
            if 'min' in kline:
                if 'A' in table_name:
                    if date1.hour != hour and date1.minute != minute:
                        data = data[data.date <= dt.datetime(
                            date2.year, date2.month, date2.day, hour, minute)]
                        break
                if abs(profit) > 0.11 or abs(profitself) > 0.097:
                    data = data[data.date <= dt.datetime(
                        date2.year, date2.month, date2.day, hour, minute)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date <= dt.datetime(
                        date2.year, date2.month, date2.day, hour, minute)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date <= dt.datetime(
                            date2.year, date2.month, date2.day, hour, minute)]
                        print(sc, str(profitself) + '_' + str(date))
                        continue
            try:
                visualization.draw_ma_line3(data=data0,
                                            profits=profit,
                                            date=date1,
                                            code=sc,
                                            table_name=table_name,
                                            pixel=pixel,
                                            n=n,
                                            profit_relative=profit_relative,
                                            count=count)

                pass
            except Exception as e:
                print(e)
                pass
            data = data[data.date <= dt.datetime(date2.year, date2.month,
                                                 date2.day, hour, minute)]
            end_time = date2

    return 1
Beispiel #5
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'usa_kline_day'
    pixel = 64
    length = pixel * 2
    interval = KlineInfo.get_interval(kline=kline)
    off = KlineInfo.get_off(kline=kline)
    table_name = 'MACD_and_MA_' + kline
    print(table_name)
    for sc in stocks:
        print(os.getpid(), sc)
        end_time = dt.datetime(2018, 6, 20)
        start_time = dt.datetime(2015, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -off)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= (off - 20):
            continue
        data = calculate.calculate_data(data, interval)
        # data = data.sort_values(by=['date'], ascending=True)
        data = data.dropna()
        # data = data[0:len(data) - interval]

        while end_time > dt.datetime(2016, 1, 5):
            # print(sc,dt.datetime.now())
            data0 = data.tail(length)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            date = data0['date']
            data0 = calculate.data_normalization(data=data0,
                                                 pixel=pixel,
                                                 length=length)
            # print(sc, dt.datetime.now())
            data0['date'] = date
            data0['profit'] = profit
            if len(data0) < length:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[length - 1]
            date = data0.date.iloc[length - 1]
            if 'min' in kline:
                if 'A' in table_name:
                    if date.hour != 15:
                        data = data[data.date < dt.datetime(
                            date.year, date.month, date.day)]
                        break
                if abs(profit) > 0.11:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue

            # print(sc, dt.datetime.now())
            try:
                visualization.draw_macd_and_ma(data=data0,
                                               profits=profit,
                                               date=date,
                                               code=sc,
                                               table_name=table_name,
                                               pixel=pixel,
                                               length=length)
                pass
            except Exception as e:
                print(e)
                pass
            data = data[
                data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date
    return 1
Beispiel #6
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'hk_kline_min30'
    pixel = 64
    table_name = 'MACD_' + kline
    print(table_name)
    interval = KlineInfo.get_interval(kline=kline)
    # detal= KlineInfo.get_detal(kline=kline)
    # path = "//DESKTOP-4JKCMO0/zjf1/H_macd_kline_day"
    # path = "f:/zjf/image/macd_kline_day_test"
    # File.check_file(path=path)
    for sc in stocks:
        end_time = dt.datetime(2018, 6, 20)
        start_time = dt.datetime(2015, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -203)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMacd.cal_macd(data, interval)
        data = data.sort_values(by=['date'], ascending=True)
        data = data.dropna()
        # data = data[0:len(data) - interval]
        print(sc)
        while end_time > dt.datetime(2016, 1, 5):
            # print(sc,dt.datetime.now())
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            date = data0['date']
            data0 = CalMacd.data_normalization(data0, pixel=pixel)
            # print(sc, dt.datetime.now())
            data0['date'] = date
            data0['profit'] = profit
            if len(data0) < pixel:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[pixel - 1]
            date = data0.date.iloc[pixel - 1]
            if 'min' in kline:
                if abs(profit) > 0.11:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    end_time = date
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    end_time = date
                    continue
            # print(sc, dt.datetime.now())
            try:
                visualization.draw_macd_line(data=data0,
                                             profits=profit,
                                             date=date,
                                             code=sc,
                                             table_name=table_name,
                                             pixel=pixel)
                # pass
            except Exception as e:
                print(e)
                pass
            # data = data[0:len(data) - detal]
            data = data[
                data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date
    return 1
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'index_min30'
    pixel = 56
    n = 4
    count = 2
    interval = KlineInfo.get_interval(kline=kline)
    detal = KlineInfo.get_detal(kline=kline)
    table_name = 'A_MACD_left_right_' + kline + '_version6'

    print(table_name)
    for sc in stocks:
        end_time = dt.datetime(2018, 8, 10)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -203)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)

        if len(data) <= 200:
            continue
        data = CalMacd.cal_macd(data=data, interval=interval, detal=detal)
        data = data.dropna()

        d = data.date.iloc[-1]
        data = data[data.date <= dt.datetime(d.year, d.month, d.day, 10, 0)]
        print(sc)
        while end_time > start_time:
            # print(sc,dt.datetime.now())
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            profit_self = data0['profit_self']
            date = data0['date']
            if len(data0) < pixel:
                break

            date1 = date.iloc[pixel - 1]
            date2 = date.iloc[pixel - 2]
            data0 = CalMacd.data_normalization(data0, pixel=pixel + n * count)
            profit = profit.iloc[pixel - 1]
            profitself = profit_self.iloc[pixel - 1]
            profit_relative = 0
            if 'min' in kline:
                if 'A' in table_name:
                    if date1.hour != 10 and date1.minute != 0:
                        data = data[data.date <= dt.datetime(
                            date2.year, date2.month, date2.day, 10, 0)]
                        break
                if abs(profit) > 0.11 or abs(profitself) > 0.097:
                    data = data[data.date <= dt.datetime(
                        date2.year, date2.month, date2.day, 10, 0)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date <= dt.datetime(
                        date2.year, date2.month, date2.day, 10, 0)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date <= dt.datetime(
                            date2.year, date2.month, date2.day, 10, 0)]
                        print(sc, str(profitself) + '_' + str(date))
                        continue

            try:
                visualization.draw_macd_line4(data=data0,
                                              profits=profit,
                                              date=date1,
                                              code=sc,
                                              table_name=table_name,
                                              pixel=pixel,
                                              n=n,
                                              profit_relative=profit_relative,
                                              count=count)
                pass
            except Exception as e:
                print(e)
                pass
            data = data[data.date <= dt.datetime(date2.year, date2.month,
                                                 date2.day, 10, 0)]
            end_time = date2
            # break

    return 1
Beispiel #8
0
def fun(data):
    stocks=data['stocks']
    kline=data['kline']
    # print(os.getpid(), stocks)
    table_name='MA_A_'+kline
    interval = KlineInfo.get_interval(kline)
    detal=KlineInfo.get_detal(kline)
    off=KlineInfo.get_off(kline=kline)
    day_interval=KlineInfo.get_day_interval(kline)
    pixel=64
    for sc in stocks:
        end_time = Calendar.today()
        start_time = Calendar.calc(end_time,-day_interval)['date']
        # end_time = dt.datetime(2018,8,1)
        # start_time=dt.datetime(2018,6,20)

        data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -off)['date'], end_date=end_time,
                                   kline=kline, timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMa.cal_ma(data, interval,detal)
        data = data.dropna()
        print(sc)
        while end_time > start_time:
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            profitself = data0['profit_self']
            date = data0['date']
            data0 = CalMa.data_normalization(data0,pixel)
            data0['date'] = date
            data0['profit'] = profit
            data0['profitself'] = profitself
            if len(data0) < pixel:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[len(data0)-1]
            profitself = data0.profitself.iloc[len(data0)-1]
            date = data0.date.iloc[len(data0)-1]

            if 'min' in kline:
                if 'A' in table_name:
                    if date.hour != 15:
                        data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                        break
                if abs(profit) > 0.11 or abs(profitself) > 0.097:
                    data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date < dt.datetime(date.year, date.month, date.day)]
                        continue


            try:
                visualization.draw_ma_line(data=data0, profits=profit,
                                           date=date, code=sc,
                                           table_name=table_name,pixel=pixel)
            except Exception as e:
                print(e)
                pass
            data = data[data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date

    return 1
Beispiel #9
0
def fun(stocks):
    # print(os.getpid(), stocks)
    kline = 'kline_day'
    table_name = 'A_new_plus_last8_MA_' + kline
    print(table_name)
    interval = KlineInfo.get_interval(kline)
    detal = KlineInfo.get_detal(kline)
    pixel = 64
    n = 8
    for sc in stocks:
        end_time = dt.datetime(2018, 6, 25)
        start_time = dt.datetime(2016, 1, 1)
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -203)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMa.cal_ma(data, interval, detal)
        data = data.dropna()
        print(sc)

        while end_time > dt.datetime(2016, 1, 1):
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            profitself = data0['profit_self']
            date = data0['date']
            data0 = CalMa.data_normalization2(data0, pixel)
            data0['date'] = date
            data0['profit'] = profit
            data0['profitself'] = profitself
            if len(data0) < pixel:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[len(data0) - 1]
            profitself = data0.profitself.iloc[len(data0) - 1]
            date = data0.date.iloc[len(data0) - 1]

            if 'min' in kline:
                if 'A' in table_name:
                    if date.hour != 15:
                        data = data[data.date < dt.datetime(
                            date.year, date.month, date.day)]
                        break
                if abs(profit) > 0.11 or abs(profitself) > 0.097:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date < dt.datetime(
                            date.year, date.month, date.day)]
                        print(sc, str(profitself) + '_' + str(date))
                        continue
            try:
                visualization.draw_ma_line2(data=data0,
                                            profits=profit,
                                            date=date,
                                            code=sc,
                                            table_name=table_name,
                                            pixel=pixel,
                                            n=n)
            except Exception as e:
                print(e)
                pass
            data = data[
                data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date
    return 1
Beispiel #10
0
def fun(data):
    stocks = data['stocks']
    kline = data['kline']
    pixel = 64
    interval = KlineInfo.get_interval(kline=kline)
    detal = KlineInfo.get_detal(kline=kline)
    table_name = 'MACD_A_' + kline
    day_interval = KlineInfo.get_day_interval(kline)
    print(table_name)
    for sc in stocks:
        # end_time = dt.datetime(2018, 8, 1)
        # start_time = dt.datetime(2018, 7, 16)
        end_time = Calendar.today()
        start_time = Calendar.calc(end_time, -day_interval)['date']
        data = KlineData.read_data(code=sc,
                                   start_date=Calendar.calc(start_time,
                                                            -203)['date'],
                                   end_date=end_time,
                                   kline=kline,
                                   timemerge=True)
        if len(data) <= 200:
            continue
        data = CalMacd.cal_macd(data=data, interval=interval, detal=detal)
        data = data.dropna()
        # data = data[0:len(data) - interval]
        print(sc)
        while end_time > start_time:
            # print(sc,dt.datetime.now())
            data0 = data.tail(pixel)
            data0 = data0.reset_index(drop=True)
            profit = data0['profit']
            profit_self = data0['profit_self']

            date = data0['date']
            data0 = CalMacd.data_normalization(data0, pixel=pixel)
            # print(sc, dt.datetime.now())
            data0['date'] = date
            data0['profit'] = profit
            data0['profit_self'] = profit_self
            # print(len(data0))
            if len(data0) < pixel:
                break
            data0 = data0.reset_index(drop=True)
            profit = data0.profit.iloc[pixel - 1]
            profitself = data0.profit_self.iloc[pixel - 1]
            date = data0.date.iloc[pixel - 1]
            if 'min' in kline:
                if 'A' in table_name:
                    if date.hour != 15:
                        data = data[data.date < dt.datetime(
                            date.year, date.month, date.day)]
                        break
                if abs(profit) > 0.11 or abs(profitself) > 0.097:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]

                    continue
            else:
                if abs(profit) > 0.1 * interval:
                    data = data[data.date < dt.datetime(
                        date.year, date.month, date.day)]
                    continue
                if 'A' in table_name:
                    if abs(profitself) > 0.097:
                        data = data[data.date < dt.datetime(
                            date.year, date.month, date.day)]
                        print(sc, str(profitself) + '_' + str(date))
                        continue

            try:
                visualization.draw_macd_line(data=data0,
                                             profits=profit,
                                             date=date,
                                             code=sc,
                                             table_name=table_name,
                                             pixel=pixel)
                pass
            except Exception as e:
                print(e)
                pass
            data = data[
                data.date < dt.datetime(date.year, date.month, date.day)]
            end_time = date

    return 1