Ejemplo n.º 1
0
def min60(time):
    min60_times = [1030, 1130, 1400, 1500]
    if time in min60_times:
        temp = time // 100 * 60 + time % 100 - 60
        temp = temp // 60 * 100 + temp % 60
        print(temp)
        sql = {'time': {'$gt': temp, '$lte': time}, 'date': Calendar.today()}
        curror = BaseModel('real_kline_min5').query(sql=sql)
        if curror.count():
            data = pd.DataFrame(list(curror))

            data = data.sort_values(by=['time'], ascending=True)
            data = data.groupby(by=['stock_code'], as_index=False).agg({
                'volume':
                'sum',
                'amount':
                'sum',
                'open':
                'first',
                'close':
                'last',
                'high':
                'max',
                'low':
                'min'
            })

            data['time'] = time
            data['date'] = Calendar.today()
            BaseModel('real_kline_min60').insert_batch(
                data.to_dict(orient='records'))
            print('min60 ok')


# min60(time=1030)
Ejemplo n.º 2
0
 def is_trade_day(cls, date):
     curror = BaseModel('calendar').query(dict(date=Calendar.today()))
     return True if curror.count() else False
Ejemplo n.º 3
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