예제 #1
0
            elif (len(st.split()[0]) == 1 and st.split()[0].isdigit()) or st.split()[0].startswith('x'):
                st_l=st.split()
                st_k=st_l[0]
                if st_k in list(ct.Market_sort_idx.keys()) and len(top_all) > 0:
                    st_key_sort=st
                    market_sort_value, market_sort_value_key=ct.get_market_sort_value_key(
                        st_key_sort, top_all=top_all)
                else:
                    log.error("market_sort key error:%s" % (st))
                    cct.sleeprandom(5)

            elif st.lower() == 'g' or st.lower() == 'go':
                status=True
            elif st.lower() == 'clear' or st.lower() == 'c':
                top_all=pd.DataFrame()
                cct.GlobalValues().setkey('lastbuylogtime', 1)
                # cct.set_clear_logtime()
                status=False
            elif st.startswith('w') or st.startswith('a'):
                args=cct.writeArgmain().parse_args(st.split())
                codew=stf.WriteCountFilter(top_temp, writecount=args.dl)
                if args.code == 'a':
                    cct.write_to_blocknew(block_path, codew)
                    # cct.write_to_blocknew(all_diffpath,codew)
                else:
                    cct.write_to_blocknew(block_path, codew, False)
                    # cct.write_to_blocknew(all_diffpath,codew,False)
                print("wri ok:%s" % block_path)
                cct.sleeprandom(ct.duration_sleep_time / 2)
                # cct.sleep(5)
            elif st.lower() == 'r':
예제 #2
0
def get_hot_countNew(changepercent, rzrq, fibl=None, fibc=10):
    global fibcount
    INDEX_LIST_TDX = {'999999': 'sh', '399001': 'sz', '399006': 'cyb'}
    # {v: k for k, v in m.items()}
    # >>> zip(m.values(), m.keys())
    # mi = dict(zip(m.values(), m.keys()))
    if fibcount == 0 or fibcount >= fibc:
        if fibcount >= fibc:
            fibcount = 1
        else:
            fibcount += 1
        if fibl is not None:
            int = 0
            for f in fibl:
                code, op, ra, daysData, fib, st = f[0], f[1], f[2], f[3], f[
                    4], f[5]
                # cumin_index[INDEX_LIST_TDX[code]]=cumin
                int += 1
                if int % 2 != 0:
                    print "%s op:%s ra:%s d:%s fib:%s m5:%s  %s" % (
                        code, f_print(3, op), f_print(
                            5, ra), f_print(2, daysData[0]), f_print(
                                3, fib), f_print(4, daysData[1]), st),
                else:
                    print "%s op:%s ra:%s d:%s fib:%s m5:%s " % (
                        st, f_print(3, op), f_print(
                            5, ra), f_print(2, daysData[0]), f_print(
                                3, fib), f_print(4, daysData[1]))

    else:
        fibcount += 1
    allTop = pd.DataFrame()
    indexKeys = ['sh', 'sz', 'cyb']
    # ffindex = ffu.get_dfcfw_fund_flow('all')
    ffindex = ffu.get_dfcfw_fund_flow2020('all')

    ffall = {}
    topTen_all = 0
    crashTen_all = 0
    ffall['zlr'] = 0
    ffall['zzb'] = 0

    for market in indexKeys:
        # market = ct.SINA_Market_KEY()
        #        df = rd.get_sina_Market_json(market, False)
        df = sina_data.Sina().market(market)
        # count=len(df.index)
        # log.info("market:%s" % df[:1])
        df = df.dropna()
        df = df[df.close > 0]
        if 'percent' not in df.columns:
            df['percent'] = map(lambda x, y: round((x - y) / y * 100, 1),
                                df.close.values, df.llastp.values)

        if 'percent' in df.columns.values:
            # and len(df[:20][df[:20]['percent']>0])>3:
            # if 'code' in df.columns:
            #     top = df[df['percent'] > changepercent]
            #     topTen = df[df['percent'] > 9.9]
            #     crashTen = df[df['percent'] < -9.8]
            #     crash = df[df['percent'] < -changepercent]
            # else:
            top = df[df['percent'] > changepercent]
            topTen = df[df['percent'] > 9.9]
            # dropcode = [ x for x in topTen.index.tolist() if x not in top_Ten_Dropcxg]
            # if len(dropcode) >0:
            #     topT_l = tdd.get_tdx_exp_all_LastDF_DL(dropcode, dt=ct.duration_date_l,newdays=10,showRunTime=False)
            #     if isinstance(topT_l, pd.DataFrame):
            #         top_Ten_Dropcxg.extend(topT_l.index.tolist())
            crashTen = df[df['percent'] < -9.8]
            crash = df[df['percent'] < -changepercent]
        else:
            log.info("market No Percent:%s" % df[:1])
            top = '0'
            topTen = '0'
            crashTen = '0'
            crash = '0'
        topTen_all += len(topTen)
        crashTen_all += len(crashTen)
        # top=df[ df['changepercent'] <6]
        # print("\033[1;31;40m您输入的帐号或密码错误!\033[0m")
        print("%s topT: %s top>%s: %s" %
              (f_print(4, market), f_print(
                  3, len(topTen)), changepercent, f_print(4, len(top)))),
        # url = ct.DFCFW_FUND_FLOW_URL % ct.SINA_Market_KEY_TO_DFCFW[market]
        # log.debug("ffurl:%s" % url)
        print(u"crashT:%s crash<-%s:%s" % (f_print(
            4, len(crashTen)), changepercent, f_print(4, len(crash)))),
        # print(u"-5:%s" %
        #       (f_print(4, len(crash[crash < -5])))),
        ff = ffindex[market]
        if len(ff) > 0:
            zlr = float(ff['zlr'])
            zzb = float(ff['zzb'])
            ffall['zlr'] = ffall['zlr'] + zlr
            ffall['zzb'] = ffall['zzb'] + zzb
            # zt=str(ff['time'])
            # modfprint=lambda x:f_print(4,x) if x>0 else "-%s"%(f_print(4,str(x).replace('-','')))
            # print modfprint(zlr)
            # print (u"流入: %s亿 比: %s%%" % (modfprint(zlr), modfprint(zzb))),
            print(u"流入: %s亿 比: %s%% " %
                  (f_print(6, zlr, 32), f_print(4, zzb, 32))),
            if 'close' in ff.keys():
                if ff['close'] == 0:
                    _percent = 0
                else:
                    _percent = round(
                        (ff['close'] - ff['lastp']) * 100 / ff['close'], 2)
            else:
                _percent = 0
                ff['close'] = 0.0
                ff['open'] = 0.0
                ff['lastp'] = 0.0
            # print (u" %s"%(f_print(2,cumin_index[market],31))),
            print(
                u"%s %s%% %s%s" %
                (f_print(7, ff['close']), f_print(4, _percent, 31),
                 f_print(1, '!' if ff['open'] > ff['lastp'] else '?'),
                 f_print(2, '!!' if ff['close'] > ff['lastp'] else '??', 32)))
        allTop = allTop.append(df.reset_index(), ignore_index=True)
        allTop = allTop.drop_duplicates()
    df = allTop
    df = tdd.get_single_df_lastp_to_df(df.set_index('code'), resample='d')
    count = len(df.index)
    top = df[df['percent'] > changepercent]

    topTen = df[df['percent'] >= 9.9]
    if 'max5' in df.columns:
        top_Max = (df[(df.close >= df.hmax) & (df.close >= df.max5)])

        # top_low = len(df[df.low < df.min5])
        top_min = (df[(df.close <= df.lmin) & (df.close <= df.min5)])
        cct.GlobalValues().setkey('top_max', top_Max)
        cct.GlobalValues().setkey('top_min', top_min)

    else:
        top_Max = []
        top_low = 0
        top_min = []

    # topTen = str(len(topTen)) +'('+str(len(top_Ten_Dropcxg))+')' +'(H:'+str(len(top_Max))+')'
    topTen = str(topTen_all) + '(' + str(len(topTen)) + ')' + \
        '(H:' + str(len(top_Max)) + ')'
    # print "top_Ten_Dropcxg:%s",top_Ten_Dropcxg
    # crashTen = df[df['percent'] < -9.8]
    crashTen = str(crashTen_all) + '(L:' + str(len(top_min)) + ')'

    crash = df[df['percent'] < -changepercent]

    print(u"AL:%s topT:%s top>%s:%s" %
          (f_print(4, count), f_print(
              3, (topTen), 31), changepercent, f_print(4, len(top), 31))),
    print(
        u"crashT:%s crash<-%s:%s" %
        (f_print(3,
                 (crashTen), 32), changepercent, f_print(4, len(crash), 31))),
    print(u"-5:%s" % (f_print(4, len(crash[crash.percent < -5]), 32))),
    # ff = ffu.get_dfcfw_fund_flow(ct.DFCFW_FUND_FLOW_ALL)
    ffall['time'] = ff['time']
    ff = ffall
    zzb = 0
    if len(ff) > 0:
        zlr = round(float(ff['zlr']), 1)
        zzb = round(float(ff['zzb']) / 3, 1)
        zt = str(ff['time'])
        print(u"流入: %s亿 占比: %s%% %s" %
              (f_print(4, zlr, 31), f_print(4, zzb, 31), f_print(4, zt)))

    ff = ffu.get_dfcfw_fund_SHSZ()
    # hgt = ffu.get_dfcfw_fund_HGT()
    # szt = ffu.get_dfcfw_fund_HGT(url=ct.DFCFW_FUND_FLOW_SZT)
    hgt = ffu.get_dfcfw_fund_HGSZ2021('bei')
    szt = ffu.get_dfcfw_fund_HGSZ2021('nan')
    log.debug("shzs:%s hgt:%s" % (ff, hgt))
    # if len(ff) > 0:
    #     print ("\tSH: %s u:%s vo: %s sz: %s u:%s vo: %s" % (
    #         f_print(4, ff['scent']), f_print(4, ff['sup']), f_print(5, ff['svol']), f_print(4, ff['zcent']),
    #         f_print(4, ff['zup']),
    #         f_print(5, ff['zvol']))),
    bigcount = rd.getconfigBigCount(count=None, write=True)

    if len(ff) > 0:
        print(u"\tSh: %s Vr:%s Sz: %s Vr:%s " %
              (f_print(4, ff['scent']), f_print(5, ff['svol'], 31),
               f_print(4, ff['zcent']), f_print(5, ff['zvol'], 31))),
        print(u'B:%s-%s V:%s' %
              (bigcount[0], bigcount[2], f_print(4, bigcount[1])))
    else:
        print(u"\tSh: \t%s Vr:  \t%s Sz: \t%s Vr: \t%s ") % (0, 0, 0, 0),
        print(u'B:%s-%s V:%s' %
              (bigcount[0], bigcount[2], f_print(4, bigcount[1])))

    if len(hgt) > 0:
        print("\tSgt: %s Gst: %s Hgt: %s Ggt: %s SSVol:%s" %
              (hgt['ggt'], szt['ggt'], hgt['hgt'], szt['hgt'],
               f_print(10, ff['allvol'], 31)))
    else:
        print("\t%s Sgt: %s Gst: %s \tHgt: \t%s Ggt: " % (0, 0, 0, 0))

    if len(rzrq) > 0:
        if 'shrz' not in rzrq.keys() and 'szrz' not in rzrq.keys():
            rzrq['shrz'] = 0
            rzrq['szrz'] = 0
        shpcent = round(
            (rzrq['shrz'] / rzrq['sh'] * 100), 1) if rzrq['sh'] > 0 else '?'
        szpcent = round(
            (rzrq['szrz'] / rzrq['sz'] * 100), 1) if rzrq['sz'] > 0 else '?'
        print(u"\tSh: %s rz:%s :%s%% sz: %s rz:%s :%s%% All: %s diff: %s亿" %
              (f_print(5, rzrq['sh']), f_print(4, rzrq['shrz']), shpcent,
               f_print(5, rzrq['sz']), f_print(4, rzrq['szrz']), szpcent,
               f_print(4, rzrq['all'], 31), f_print(5, rzrq['dff'], 31)))
    # print "bigcount:",bigcount

    cct.set_console(width,
                    height,
                    title=[
                        'B:%s-%s V:%s' %
                        (bigcount[0], bigcount[2], bigcount[1]),
                        'ZL: %s' % (zlr if len(ff) > 0 else 0),
                        'To:%s' % len(topTen),
                        'D:%s' % len(crash),
                        'Sh: %s ' % ff['scent'] if len(ff) > 0 else '?',
                        'Vr:%s%% ' % ff['svol'] if len(ff) > 0 else '?',
                        'MR: %s' % zzb,
                        'ZL: %s' % (zlr if len(ff) > 0 else '?')
                    ],
                    closeTerminal=True)

    log.debug("set_console:bigcount[0]%s  bigcount[2]:%s" %
              (bigcount[0], bigcount[2]))

    return allTop
예제 #3
0
def getBollFilter(df=None,
                  boll=ct.bollFilter,
                  duration=ct.PowerCountdl,
                  filter=True,
                  ma5d=True,
                  dl=14,
                  percent=True,
                  resample='d',
                  ene=False,
                  upper=False,
                  down=False,
                  indexdff=True,
                  cuminTrend=False,
                  top10=True):

    # drop_cxg = cct.GlobalValues().getkey('dropcxg')
    # if len(drop_cxg) >0:
    # log.info("stf drop_cxg:%s"%(len(drop_cxg)))
    # drop_cxg = list(set(drop_cxg))
    # drop_t = [ co for co in drop_cxg if co in df.index]
    # if len(drop_t) > 0:
    # df = df.drop(drop_t,axis=0)top
    # log.error("stf drop_cxg:%s"%(len(drop_t)))

    # hvdu max量天数  lvdu  min天数  hv max量  lv 量
    # fib < 2 (max) fibl > 2   lvdu > 3  (hvdu > ? or volume < 5)? ene
    time_s = time.time()
    # df['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1), df.ma10d)
    # df['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1), df.ma10d)
    # df['ene'] = map(lambda x, y: round((x + y) / 2, 1), df.upper, df.lower)
    '''
    df = df[(df.close > df.ma20d) | (df.close > df.ene)]
    if filter:
        if 'boll' in df.columns:
            df = df[(df.boll >= boll) | (df.buy > df.upper)]
    '''

    # if 'nlow' in df.columns:
    # df = df[ ((df.nlow >= df.llastp) & (df.nlow >= df.low)) | ((df.nlow <= df.low) & (df.open == df.nlow))]
    # if cct.get_work_time() and 'df2' in df.columns:
    #     if 915 < cct.get_now_time_int() < 930:
    #         df['cumnow'] =  map(lambda x, y: 1 if x - y > 0 else 0, df.close, df.cumaxe)
    #     else:
    #         df['cumnow'] =  map(lambda x, y: 1 if x - y > 0 else 0, df.high, df.cumaxe)
    #     df['df2'] = (df['df2'] + df['cumnow']).map(lambda x: int(x))
    # df = df[df.df2 > 1]
    # else:
    # df = df[df.df2 > 0]
    radio_t = cct.get_work_time_ratio()
    df['lvolr%s' % (resample)] = df['volume']
    # df['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df.nvol.values, df.lvolume.values))
    if cct.get_now_time_int() > 1530:
        df['volume'] = (map(
            lambda x, y, z: round((x / y / radio_t)
                                  if z < 9.9 else (x / y), 1), df.nvol.values,
            df.ma5vol.values, df.percent.values))
    else:
        df['volume'] = (map(
            lambda x, y, z: round((x / y / radio_t)
                                  if z < 9.9 else (x / y), 1), df.nvol.values,
            df.lvol.values, df.percent.values))
    # df['volume'] = (map(lambda x, y,z: round((x / y / radio_t) if z < 9.9 else (x / y) , 1), df.nvol.values, df.ma5vol.values,df.percent.values))
    # df['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df.nvol.values, df.lastv1d.values))

    indexfibl = cct.GlobalValues().getkey('indexfibl')
    sort_value = cct.GlobalValues().getkey('market_sort_value')
    market_key = cct.GlobalValues().getkey('market_key')
    market_value = cct.GlobalValues().getkey('market_value')

    # if int(market_value) > 1 and 930 < cct.get_now_time_int():

    df = compute_perd_value(df, market_value, 'perc')
    df = compute_perd_value(df, market_value, 'per')

    if sort_value <> 'percent' and (market_key in ['2', '3']
                                    and market_value not in ['1']):
        # print("sort_value:%s,market_key:%s ,market_value:%s" %
        #       (sort_value, market_key, market_value))
        if market_key is not None and market_value is not None:
            # if market_key == '3':

            if market_key == '3':
                market_value = int(market_value)
                log.info("stf market_key:%s" % (market_key))
                idx_k = cct.get_col_in_columns(df, 'perc%sd', market_value)
                # filter percd > idx
                # df= df[(df[("perc%sd" % (idx_k))] >= idx_k) | (df[("perc%sd" % (idx_k))]< -idx_k)]

                # if int(market_value) > 1 and 930 < cct.get_now_time_int():
                #     df= compute_perd_value(df, market_value, 'perc')
                #     df= compute_perd_value(df, market_value, 'per')

            # elif market_key == '2':
            #     if int(market_value) > 1 and 915 < cct.get_now_time_int():
            #         # df['per%d'%(market_value)] = compute_perd_value(df,market_value)
            #         df= compute_perd_value(df, market_value,'per')
            #         df= compute_perd_value(df, market_value, 'perc')

    # if sort_value <> 'percent' and (market_key in ['2','3'] and market_value not in ['1'] ):
    #     if indexfibl is not None:
    #         df = df[df.fibl >= (indexfibl - 1)]
    #     else:
    #         indexfibl = 1
    #     if cuminTrend:
    #         cuminfibl = cct.GlobalValues().getkey('cuminfibl')
    #         if cuminfibl is None:
    #             cuminfibl = cct.get_index_fibl()
    # if cuminfibl > 1:
    #     df = df[df.df2 >= cuminfibl]

    #    print df.loc['300107'][['close','cumine','llastp','cumaxe','cumaxc']]
    #     df = df[ (df.cumine == df.cumaxc) | (df.close >= df.cumine) | (df.llastp >=df.cumaxc) | (df.close >= df.cumaxe) ]
    # else:
    #     upper = True

    if not down:
        if upper:
            # upper_count = len( df[ ( ( df.buy > df.upper)| ( df.lastp0d > df.upper) | ( df.lastp1d > df.upper) | ( df.lastp2d > df.upper) | ( df.lastp3d > df.upper))])
            # # ene_count = len(df[df.buy > df.upper])
            # if upper_count > 30:
            #     df = df[ (  ( df.buy > df.upper)| ( df.lastp0d > df.upper) | ( df.lastp1d > df.upper) | ( df.lastp2d > df.upper) | ( df.lastp3d > df.upper))]
            # else:
            #     df = df[ ( (( df.buy > df.ene ) ) | ( df.buy > df.upper)| ( df.lasth0d > df.upper) | ( df.lasth1d > df.upper) | ( df.lasth2d > df.upper) | ( df.lasth3d > df.upper))]
            df = df[(df.low >= df.upper) | (df.close >= df.upper) |
                    (df.per1d >= 9.5) | (df.lastp1d == df.hmax) |
                    ((df.lastp1d <> df.hmax) & (df.high > df.hmax))]
        else:
            if 935 < cct.get_now_time_int() < 1400:
                df = df[((df.buy > df.ene) | (df.llastp > df.ene) |
                         (df.llastp >= df.max5) | (df.high >= df.max5) |
                         (df.max5 >= df.upper))]
            else:
                df = df[((df.buy > df.ene) | (df.llastp > df.ene) |
                         (df.llastp >= df.max5) | (df.high >= df.max5) |
                         (df.max5 >= df.upper))]

    # df['cumins'] = round(cum_counts.index[0], 2)
    # df['cumine'] = round(cumdf[-1], 2)
    # df['cumax']
    # df.rename(columns={'cumin': 'df2'}, inplace=True)
    if df is None:
        print "dataframe is None"
        return None
    else:
        # top10 = df[ (df.percent >= 9.99) & (df.b1_v > df.a1_v)]

        if resample in ['d', 'w']:
            # if not top10 or (cct.get_now_time_int() < 950 or cct.get_now_time_int() > 1502):
            #     df.loc[((df.b1_v > df.a1_v) & (df.percent > 9)), 'percent'] = 10.1
            #     df.loc[((df.percent >= 9.97) & (df.percent < 10.1)), 'percent'] = 10

            # else:
            #     df.loc[((df.b1_v > df.a1_v) & (df.percent > 9)), 'percent'] = 10.1
            #     df.loc[((df.percent >= 9.97) & (df.percent < 10.1)), 'percent'] = 10

            # df.loc[df.per1d >= 9.99, 'per1d'] = 10
            df['percent'] = df['percent'].apply(lambda x: round(x, 2))
            # time_ss = time.time()
            perc_col = [co for co in df.columns if co.find('perc') == 0]
            per_col = [co for co in df.columns if co.find('per') == 0]
            # per_col = list(set(per_col) - set(perc_col) - set(['per1d', 'perlastp']))
            per_col = list(
                set(per_col) - set(perc_col) - set(['per1d', 'perlastp']))

            perc_col.remove('percent')

            for co in perc_col:
                df[co] = df[co].apply(lambda x: round(x, 2))

            # da, down_zero, down_dn, percent_l = 1, 0, 0, 2
            # da, down_zero, down_dn, percent_l = 1, 0, -1, 1
            # df['perc_n'] = map((lambda h, lh, l, ll, c, lc: (1 if (h - lh) > 0 else down_dn) + (1 if c - lc > 0 else down_dn) + (1 if (l - ll) > 0 else down_dn) + (2 if (c - lh) > 0 else down_zero) + (2 if (l - lc) > 0 else down_zero) + (0 if (h - lc) > 0 else down_dn)), df['high'], df['lasth%sd' % da], df['low'], df['lastl%sd' % da], df['close'],df['lastp%sd' % da])
            # df['perc_n'] = map((lambda c, lc: (1 if (c - lc) > 0 else down_zero) + (1 if (c - lc) / lc * 100 > 3 else down_zero) +
            # (down_dn if (c - lc) / lc * 100 < -3 else down_zero)), df['close'], df['lastp%sd' % da])

            # idx_rnd = random.randint(0, len(df) - 10) if len(df) > 10 else 0

            # print "idx_rnd",idx_rnd,df.ix[idx_rnd].lastp0d ,df.ix[idx_rnd].close,df.ix[idx_rnd].lastp0d != df.ix[idx_rnd].close

            # if not upper:
            #     if cct.get_work_time() or df.ix[idx_rnd].lastp0d <> df.ix[idx_rnd].close:
            #         nowd, per1d = 0, 1
            #         if 'nlow' in df.columns:
            #             df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                                   (nowd)], df['lastl%sd' % (nowd)], df['nhigh'], df['nlow'],df['nvol']/radio_t,df['lastv%sd'%(nowd)], df['hmax'],df['df2'])
            #         else:
            #             df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                                   (nowd)], df['lastl%sd' % (nowd)], df['high'], df['low'],df['nvol']/radio_t,df['lastv%sd'%(nowd)], df['hmax'],df['df2'])
            #     else:
            #         nowd, per1d = 1, 2
            #         # print  df['per%sd' % da+1], df['lastp%sd' % (da)], df['lasth%sd' % (da)], df['lastl%sd' % (da)], df['high'], df['low']
            #         df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                               (nowd)], df['lastl%sd' % (nowd)], df['high'], df['low'], df['hmax'])
            '''
            idx_rnd = random.randint(0, len(df) - 10) if len(df) > 10 else 0
            if not upper:
               # if cct.get_work_time() or df.ix[idx_rnd].lastp1d <> df.ix[idx_rnd].close:
               if cct.get_work_time() :
                   nowd, per1d=1, 1
                   if 'nlow' in df.columns:
                       df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['nhigh'], df['nlow'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])
                   else:
                       df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['high'], df['low'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])
               else:
                   nowd, per1d=1, 1
                   # print  df['per%sd' % da+1], df['lastp%sd' % (da)], df['lasth%sd' % (da)], df['lastl%sd' % (da)], df['high'], df['low']
                   df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['high'], df['low'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])

            for co in perc_col:
                df[co] = (df[co] + df['perc_n']).map(lambda x: int(x))
            '''

            # for co in per_col:
            # df[co] = (df[co] + df['percent']).map(lambda x: int(x))

            # print "percT:%.2f"%(time.time()-time_ss)
        else:
            df['percent'] = (map(
                lambda x, y: round((x - y) / y * 100, 1)
                if int(y) > 0 else 0, df.buy, df.lastp1d))
            # df.loc['002204'].percent
            # -15.4
            # ipdb> df.loc['002204'].ma10d
            # 3.2000000000000002
            # ipdb> df.loc['002204'].ma5d
            # 3.2999999999999998
    if 'fib' not in df.columns:
        df['fib'] = 0
    # else:

    co2int = ['boll', 'op', 'ratio', 'fib', 'fibl', 'df2']
    # co2int.extend([co for co in df.columns.tolist()
    #                if co.startswith('perc') and co.endswith('d')])
    co2int.extend(['top10', 'topR'])
    co2int = [inx for inx in co2int if inx in df.columns]

    for co in co2int:
        df[co] = df[co].astype(int)

    # if down:
    #     # if 'nlow' in df.columns:
    #     #     if 'max5' in df.columns:
    #     #         # df = df[(df.hmax >= df.ene) & (df.nlow >= df.low) & (df.low <> df.high) & (((df.low < df.hmax) & (df.high > df.cmean)) | (df.high > df.max5))]
    #     #         df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) ) |  (((df.lastv1d > df.lvol * 1.5) & (df.lastv1d > df.lvol * 1.5)) & (df.lastp1d > df.ene) )]
    #     #     else:
    #     #         df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) ) |  (((df.lastv1d > df.lvol * 1.5) )  )]
    #     # else:
    #     #     # df = df[ (df.max5 >= df.ene) & (df.low <> df.high) & (((df.low < df.hmax) & (df.close > df.cmean)) | (df.high > df.cmean))]
    #     #     df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) )  | (((df.lastp1d > df.ene) ) | ((df.buy > df.max5)|(df.buy > df.ene)) | (df.max5 >= df.ene)  | (df.high > df.cmean) )]
    #     return df

    if cct.get_work_time() and 'b1_v' in df.columns and 'nvol' in df.columns:
        df = df[(df.b1_v > 0) | (df.nvol > 0)]

    if (cct.get_now_time_int() > 915 and cct.get_now_time_int() < 926):
        df['b1_v'] = df['volume']
    else:
        dd = df[df.percent < 10]
        dd['b1_v'] = dd['volume']
        df = cct.combine_dataFrame(df, dd.loc[:, ['b1_v']])
        # print "t:%0.2f"%(time.time()-time_ss)

        # if int(market_value) < 3 and 930 < cct.get_now_time_int():
        #     if 'nlow' in df.columns:
        #         # df = df[((df.per1d < 3) & (df.nlow >= df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]
        #         df = df[((df.per1d < 3) & (df.nlow >= df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]
        #     else:
        #         df = df[((df.per1d < 3) & (df.open > df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]

    # else:
    #     if 'fib' in df.columns:
    #         df = df[df.fib <= 5]

    # log.error("perc%sd"%(market_value))

    # elif market_key is not None and market_key == '2':
    #     if market_value in ['1', '2']:
    #         df['dff'] = (map(lambda x, y, z: round((x + (y if z > 20 else 3 * y)), 1), df.dff.values, df.volume.values, df.ratio.values))

    # df['df2'] = (map(lambda x, y, z: w=round((x - y) / z * 100, 1), df.high.values, df.low.values, df.llastp.values))
    # df['df2'] = (map(func_compute_df2, df.close.values, df.llastp.values,df.high.values, df.low.values,df.ratio.values))
    # df['df2'] = (map(func_compute_df2, df.close.values, df.llastp.values,df.high.values, df.low.values))
    '''
    filter_up= 'ma5d'
    filter_dn= 'ma10d'
    if ma5d and filter_up in df.columns:
        if filter_dn in df.columns:
            if market_key is not None and market_key == '3':
                df= df[(df.buy >= df[filter_up]) & (
                    df.buy * 1.02 >= df[filter_dn] * ct.changeRatio)]
            else:
                df= df[(df.buy >= df[filter_up])]
        else:
            df= df[df.buy >= df[filter_up] * ct.changeRatio]
    '''

    # df = df[(df.lvolume > df.lvol * 0.9) & (df.lvolume > df.lowvol * 1.1)]

    # if 'nlow' in df.columns and 932 < cct.get_now_time_int() < 1030:

    if ene:
        pass
        if 'nclose' in df.columns:
            # df = df[ ((df.buy > df.ene) ) | ((df.buy > df.upper) & ( df.nclose > df.cmean))]
            df = df[((df.buy > df.llastp)) |
                    ((df['nclose'] > df['ene'] * ct.changeRatio) &
                     (df['percent'] > -3) & (df.volume > 1.5)) |
                    ((df['nclose'] > df['upper'] * ct.changeRatio) &
                     (df['buy'] > df['upper'] * ct.changeRatioUp)) |
                    ((df['llastp'] > df['upper']) &
                     (df['nclose'] > df['upper']))]
        else:
            df = df[((df.buy > df.llastp)) | ((df.buy > df.ene)) |
                    ((df.buy > df.upper) & (df.close > df.cmean))]

        if 'nlow' in df.columns and 930 < cct.get_now_time_int():
            # for col in ['nhigh', 'nclose', 'nlow','nstd']:
            #     df[col] = df[col].apply(lambda x: round(x, 2))
            if 'nhigh' in df.columns and 'nclose' in df.columns:
                # ncloseRatio = map(lambda x, y: x * ct.changeRatio if x * ct.changeRatio > y else y, df.nclose, df.nlow)
                df['ncloseRatio'] = map(lambda x: x * 0.99, df.nclose)
                df['nopenRatio'] = map(lambda x: x * 0.99, df.open)
                # nhighRatio = map(lambda x, y: x * ct.changeRatio if x * ct.changeRatio > y else y, df.nhigh, df.nclose)
                # if cct.get_now_time_int() > ct.nlow_limit_time:

                #           name   open    low   high  close  nclose   nlow  nhigh  nstd  ticktime
                # code
                # 601899  紫金矿业   4.25   4.24   4.69   4.69    4.52   4.24   4.42  0.12  15:00:00
                # 603917  合力科技  27.95  27.69  31.54  31.54   30.46  27.69  30.00  0.70  15:00:00
                # 300713   英可瑞  81.00  81.00  89.82  89.77   87.53  80.90  86.36  1.75  15:02:03
                # 000933  神火股份   9.07   9.02  10.00  10.00    9.71   9.02   9.44  0.24  15:02:03
                # 600050  中国联通   6.49   6.37   6.51   6.41    6.44   6.44   6.51  0.02  15:00:00
                # 002350  北京科锐  10.17  10.17  10.75  10.23   10.31  10.17  10.75  0.07  15:02:03
                # 603363  傲农生物  17.49  16.91  18.35  18.35   17.35  17.18  18.00  0.34  15:00:00
                # 000868  安凯客车   8.77   8.53   8.82   8.82    8.82   8.53   8.82  0.01  15:02:03
                # 002505  大康农业   2.91   2.86   2.99   2.89    2.91   2.90   2.99  0.02  15:02:03
                # 601939  建设银行   7.50   7.41   7.61   7.55    7.50   7.43   7.52  0.05  15:00:00
                # 600392  盛和资源  16.85  16.81  18.63  18.63   17.84  16.81  17.51  0.69  15:00:00 (11, 41)
                # 603676   卫信康  17.44  16.95  17.96  17.82   17.34  17.03  17.77  0.18  15:00:00
                if 'nstd' in df.columns:
                    df['stdv'] = map(lambda x, y: round(x / y * 100, 1),
                                     df.nstd, df.open)

                # top_temp[:40][['nstd','stdv','name','volume','dff','percent']]
                # top_temp.loc['603363'][['nstd','stdv','name','volume','high','nhigh','percent','open','nclose']]

                # df['stdv'] = map(lambda x, y, z: round(z / (x / y * 100), 1), df.nstd, df.open, df.volume)

                # df.loc['002906'][['open','nclose','close','ncloseRatio','nopenRatio','low','nlow']]

                df = df[(df.low > df.upper) |
                        (((df.nopenRatio <= df.nclose) & (df.low >= df.nlow) &
                          (df.close >= df.ncloseRatio)) |
                         ((df.nopenRatio <= df.nclose) &
                          (df.close >= df.ncloseRatio) &
                          (df.high >= df.nhigh)))]
                # else:
                # df = df[(((df.low >= df.nlow) & (df.close >= ncloseRatio)) | ((df.close >= ncloseRatio) & (df.close > nhighRatio)))]
            else:
                df = df[((df.low >= df.nlow) &
                         (df.close > df.llastp * ct.changeRatio))]
            # if 'nhigh' in df.columns and 'nclose' in df.columns:
            #     if cct.get_now_time_int() > ct.nlow_limit_time:
            #         df = df[(df.low >= df.nlow) & ((df.open > df.llastp * ct.changeRatio) & (df.nclose > df.llastp * ct.changeRatio)) &
            #                 (((df.low >= df.nlow) & (df.close >= df.nclose)) | ((df.close >= df.nclose) & (df.close > df.nhigh * ct.changeRatio) & (df.high >= df.nhigh)))]
            #     else:
            #         df = df[((df.open > df.llastp * ct.changeRatio) & (df.close > df.llastp * ct.changeRatio)) &
            #                 (((df.low >= df.nlow) & (df.close >= df.nclose)) | ((df.close >= df.nclose) & (df.close > df.nhigh * ct.changeRatio)))]
            # else:
            #     df = df[((df.low >= df.nlow) & (df.close > df.llastp))]

        if filter:

            if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 1000:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]
                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]

            elif cct.get_now_time_int() > 1000 and cct.get_now_time_int(
            ) <= 1430:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) | (df.low > df.llastp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]

                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]
            else:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]

                # df = df[(df.buy > df.hmax * ct.changeRatio) | (df.low > df.llastp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]

                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]

            if 'vstd' in df.columns:
                # df = df[(df.lvol * df.volume > (df.vstd + df.lvol)) | ((df.percent > -10) & (df.hv / df.lv > 1.5))]
                # dd = df.loc['000760'] dd.hv/dd.lv,dd.volume
                df['hvRatio'] = map(
                    lambda x, y: round(x / y / cct.get_work_time_ratio(), 1),
                    df.hv, df.lv)
                df['volRatio'] = (map(lambda x, y: round(x / y / radio_t, 1),
                                      df.nvol.values, df.lv.values))

                # df = df[(df.lvol * df.volume > (df.vstd + df.lvol)) | ((df.percent > -5) & (df.hv / df.lv > 3))]

                # if 1000 < cct.get_now_time_int() < 1450:
                #     df = df[ (3 < df.ratio) & (df.ratio < 20)]
                if 'nclose' in df.columns:
                    # df = df[((df.hvRatio > df.volRatio) & ((df.buy > df.lastp) & (df.nclose > df.lastp))) | ((
                    df = df[(((df.buy > df.lastp) & (df.nclose > df.lastp))) |
                            (((df.percent > -5) &
                              ((df.vstd + df.lvol) * 1.2 < df.nvol) &
                              (df.nvol > (df.vstd + df.lvol))))]
                else:
                    # df = df[((df.hvRatio > df.volRatio) & ((df.buy > df.lastp))) | ((
                    df = df[(((df.buy > df.lastp))) |
                            (((df.percent > -5) &
                              ((df.vstd + df.lvol) * 1.2 < df.nvol) &
                              (df.nvol > (df.vstd + df.lvol))))]
                # [dd.lvol * dd.volume > (dd.vstd + dd.lvol) | dd.lvol * dd.volume >(dd.ldvolume + dd.vstd]
            # print df.loc['000801']

            if percent:
                pass
                '''
                if 'stdv' in df.columns and 926 < cct.get_now_time_int():
                    # df = df[((df.volume > 2 * cct.get_work_time_ratio()) & (df.percent > -3)) | ((df.stdv < 1) &
                    #                (df.percent > 2)) | ((df.lvolume > df.lvol * 0.9) & (df.lvolume > df.lowvol * 1.1))]
                    
                    df_index = tdd.getSinaIndexdf()
                    if isinstance(df_index, type(pd.DataFrame())):
                        df_index['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df_index.nvol.values, df_index.lastv1d.values))
                        index_vol = df_index.loc['999999'].volume
                        if 'percent' in df_index.columns and '999999' in df_index.index:
                            index_percent = df_index.loc['999999'].percent
                        else:
                            # import ipdb;ipdb.set_trace()
                            log.error("index_percent" is None)
                            index_percent = 0

                        index_boll = df_index.loc['999999'].boll
                        index_op = df_index.loc['999999'].op
                        # df = df[((df.percent > -3) | (df.volume > index_vol)) & (df.percent > index_percent)]
                        # df = df[((df.percent > -1) | (df.volume > index_vol * 1.5)) & (df.percent > index_percent)  & (df.boll >= index_boll)]
                        df = df[((df.percent > -1) | (df.volume > index_vol * 1.5)) & (df.percent > index_percent)]
                    else:
                        print ("df_index is Series",df_index.T)
                else:
                    df = df[((df.volume > 1.2 * cct.get_work_time_ratio()) & (df.percent > -3))]
                '''
                # df = df[((df['buy'] >= df['ene'])) | ((df['buy'] < df['ene']) & (df['low'] > df['lower'])) | ((df['buy'] > df['upper']) & (df['low'] > df['upper']))]
                # df = df[(( df['ene'] * ct.changeRatio < df['open']) & (df['buy'] > df['ene'] * ct.changeRatioUp)) | ((df['low'] > df['upper']) & (df['close'] > df['ene']))]

                # df = df[(( df['ene'] < df['open']) & (df['buy'] < df['ene'] * ct.changeRatioUp))]

                # df = df[(df.per1d > 9) | (df.per2d > 4) | (df.per3d > 6)]
                # df = df[(df.per1d > 0) | (df.per2d > 4) | (df.per3d > 6)]
            # time_ss=time.time()
            # codel = df.index.tolist()
            # dm = tdd.get_sina_data_df(codel)
            # results = cct.to_mp_run_async(getab.Get_BBANDS, codel,'d',5,duration,dm)
            # bolldf = pd.DataFrame(results, columns=['code','boll'])
            # bolldf = bolldf.set_index('code')
            # df = cct.combine_dataFrame(df, bolldf)
            # print "bollt:%0.2f"%(time.time()-time_ss),
            per3d_l = 2
            percent_l = -1
            op_l = 3
            # if 'boll' in df.columns:
            #     if 915 < cct.get_now_time_int() < 950:
            #         # df = df[(df.boll >= boll) | ((df.percent > percent_l) & (df.op > 4)) | ((df.percent > percent_l) & (df.per3d > per3d_l))]
            #         # df = df[((df.percent > percent_l) & (df.op > 4)) | ((df.percent > percent_l) & (df.per3d > per3d_l))]
            #         pass
            #     elif 950 < cct.get_now_time_int() < 1501:
            #         # df = df[(df.boll >= boll) | ((df.low <> 0) & (df.open == df.low) & (((df.percent > percent_l) & (df.op > op_l)) | ((df.percent > percent_l) & (df.per3d > per3d_l))))]
            #         # df = df[(df.boll >= boll) & ((df.low <> 0) & (df.open >= df.low *
            #         # ct.changeRatio) & (((df.percent > percent_l)) | ((df.percent >
            #         # percent_l) & (df.per3d > per3d_l))))]
            #         df = df[(df.boll >= boll)]
            #     # else:
            # df = df[(df.boll >= boll) | ((df.low <> 0) & (df.open == df.low) &
            # (((df.percent > percent_l) & (df.op > op_l)) | ((df.percent > percent_l)
            # & (df.per3d > per3d_l))))]

        # if 945 < cct.get_now_time_int() and market_key is None:
        #     df.loc[df.percent >= 9.94, 'percent'] = -10

    # else:
    #     # df['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1), df.ma10d)
    #     # df['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1), df.ma10d)
    #     # df['ene'] = map(lambda x, y: round((x + y) / 2, 1), df.upper, df.lower)
    #     # df = df[((df['buy'] >= df['ene'])) | ((df['buy'] < df['ene']) & (df['low'] > df['lower'])) | ((df['buy'] > df['upper']) & (df['low'] > df['upper']))]
    #     # df = df[(( df['ene'] * ct.changeRatio < df['open']) & (df['buy'] > df['ene'] * ct.changeRatioUp)) | ((df['low'] > df['upper']) & (df['close'] > df['ene']))]
    #     if 'nclose' in df.columns:
    #         # df = df[((df['nclose'] > df['ene'] * ct.changeRatio) & (df['percent'] > -3) & (df.volume > 1.5)) |
    #         #         ((df['nclose'] > df['upper'] * ct.changeRatio) & (df['buy'] > df['upper'] * ct.changeRatioUp)) | ((df['llastp'] > df['upper']) & (df['nclose'] > df['upper']))]
    #         df = df[(df.nclose > df.cmean)]
    #     else:
    #         df = df[(df.buy > df.cmean)]

    print("bo:%0.1f" % (time.time() - time_s)),

    df['ral'] = (map(lambda x, y: round((x + y), 1), df.percent, df.ral))
    df['ra'] = (map(lambda x, y: round((x + y), 1), df.percent, df.ra))
    return df
예제 #4
0
            else:
                log.debug('into clean_duration:%s' % (int_time))
                if (cct.get_now_time_int() > 1502
                        and cct.get_now_time_int() < 2400):
                    while 1:
                        if cct.get_now_time_int(
                        ) > 1502 and cct.get_now_time_int() < 1510:
                            print ".",
                            cct.sleep(60)
                        elif cct.get_now_time_int() < 2400:
                            print ".",
                            print "write dm to file"
                            if cct.get_work_day_status():
                                tdd.Write_market_all_day_mp('all')
                                top_temp = cct.GlobalValues().getkey('top_max')
                                codew = stf.WriteCountFilter(top_temp,
                                                             writecount='all')
                                cct.write_to_blocknew(block_path,
                                                      codew,
                                                      append=False,
                                                      doubleFile=False)
                            break
                        else:
                            print "."

                raise KeyboardInterrupt("Stop Time")
                # st = cct.cct_raw_input("status:[go(g),clear(c),quit(q,e)]:")
                # if len(st) == 0:
                #     status = False
                # elif st.lower() == 'g' or st.lower() == 'go':