예제 #1
0
def recog_history_boll(pl, x, p, code):
    """在历史数据中找到相似的曲线
    x : np.ndarray 基准曲线
    p : float pearson相似度
    """
    df = stock.getFiveHisdatDf(code, method='local')
    upper, middle, lower = stock.TDX_BOLL(df['c'].values)
    df['upper'] = upper
    df = df[-1000:]
    #upper = upper[np.isnan(upper) == False]
    upper = df['upper'].values
    n = 30
    report_list = []
    x = stock.GuiYiHua(x - np.min(x))
    for i in range(0, len(upper) - 30, 2):
        y = upper[i:i + n]
        assert (len(y) == 30)
        y = stock.GuiYiHua(y - np.min(y))
        pearson_v = pearson(x, y)
        if pearson_v > p:
            df2 = pd.DataFrame(x)
            df2['2'] = y
            df2.plot()
            pl.show()
            pl.close()
            fimg = pl.get_CurImgFname()
            report_list.append([code, pearson_v, df.index[i], fimg])
    return report_list
예제 #2
0
def get_boll_up_base():
    """获取一个用来作为标准的曲线
    return : np.ndarray
    """
    code = jx.HCGD
    t = '2018-12-3 10:30:00'
    t = '2018-11-30 10:00:00'
    key = myredis.gen_keyname(__file__, get_boll_up_base)
    df = myredis.createRedisVal(
        key, lambda: stock.getFiveHisdatDf(code, method='tdx')).get()
    upper, middle, lower = stock.TDX_BOLL(df['c'].values)
    df['upper'] = upper
    df = df[t:]
    df = df[df.index[20]:]
    df = df[:df.index[29]]
    #ui.DrawTs(pl, df['upper'].values)
    #pl.show()
    return df['upper'].values
예제 #3
0
    def _test_AsynDrawKline(self):
        code = '300033'
        start_day = '2017-8-25'
        #df = stock.getHisdatDataFrameFromRedis(code, start_day)
        df = stock.getFiveHisdatDf(code, start_day=start_day)
        import account
        account = account.LocalAcount(account.BackTesting())
        #随机找三个交易点
        indexs = agl.GenRandomArray(len(df), 3)
        trade_bSell = [0, 1, 0]
        df_trades = df[df.index.map(lambda x: x in df.index[indexs])]
        df_trades = df_trades.copy()
        df_trades[AsynDrawKline.enum.trade_bSell] = trade_bSell

        plt.ion()
        for i in range(10):
            AsynDrawKline.drawKline(df[i * 10:], df_trades)

        plt.ioff()
예제 #4
0
 def _test_horizontal(self):
     code = jx.THS
     df = stock.getFiveHisdatDf(code)
     df = df['2017-5-1':]
     df = df['2017-11-1':]
     rects = []
     bHit = False
     for i in range(100, len(df), 5):
         cur_df = df[:i]
         #bFind, (h,l,left,right) = horizontal(cur_df)
         bFind, (h, l, left, right) = Combo(cur_df)
         if bFind:
             bHit = True
             print(cur_df.index[-1], bFind, (h, l, left, right))
             left = i + left
             right = i
             rects.append((h, l, left, right))
     if bHit:
         ui.drawKlineUseDf(pl, df, rects)
예제 #5
0
 def _test_drawKline2(self):
     code = jx.CYJM
     start_day = '2017-8-25'
     df = stock.getFiveHisdatDf(code, start_day=start_day)
     drawKlineUseDf(pl, df)
예제 #6
0
 def _test_DrawZZ(self):
     code = '300033'
     df_five_hisdat = stock.getFiveHisdatDf(code)
     closes = df_five_hisdat['c'][-500:]
     zz = stock.ZigZag(closes, percent=1)
     DrawDvsAndZZ(pl, closes, zz)
예제 #7
0
def getData(code):
    df = stock.getFiveHisdatDf(code)
    upper, middle, lower = stock.TDX_BOLL(df['c'].values)
    return upper, middle, lower, df