How to use the hikyuu.Query function in hikyuu

To help you get started, we’ve selected a few hikyuu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fasiondog / hikyuu / hikyuu / data_driver / jqdata_data_driver.py View on Github external
def _trans_ktype(self, ktype): #此处的周月季年数据只是近似的,目前jqdata未提供聚宽网络平台上的get_bar函数,不能直接取,需要自行用日线数据拼装
        ktype_map = {Query.MIN: '1m',
                     Query.MIN5: '5m',
                     Query.MIN15: '15m',
                     Query.MIN30: '30m',
                     Query.MIN60: '60m',
                     Query.DAY: '1d',
                     Query.WEEK: '7d',
                     Query.MONTH: '30d',
                     Query.QUARTER: '90d',
                     Query.YEAR: '365d'}
        return ktype_map.get(ktype)
github fasiondog / hikyuu / tools / hikyuu / interactive / volume.py View on Github external
def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60, 
         ma5_n=100, ma_type="SMA", vma1_n=5, vma2_n=10):
    """绘制普通K线图 + 成交量(成交金额)"""
    kdata = stock.getKData(query)
    close = CLOSE(kdata,)
    ma1 = MA(close, ma1_n, ma_type)
    ma2 = MA(close, ma2_n, ma_type)
    ma3 = MA(close, ma3_n, ma_type)
    ma4 = MA(close, ma4_n, ma_type)
    ma5 = MA(close, ma5_n, ma_type)

    ax1, ax2 = create_figure(2)
    kdata.plot(axes=ax1)
    ma1.plot(axes=ax1, legend_on=True)
    ma2.plot(axes=ax1, legend_on=True)
    ma3.plot(axes=ax1, legend_on=True)
    ma4.plot(axes=ax1, legend_on=True)
github fasiondog / hikyuu / hikyuu / data_driver / pytdx_data_driver.py View on Github external
def _trans_ktype(self, ktype):
        ktype_map = {Query.MIN: TDXParams.KLINE_TYPE_1MIN,
                     Query.MIN5: TDXParams.KLINE_TYPE_5MIN,
                     Query.MIN15: TDXParams.KLINE_TYPE_15MIN,
                     Query.MIN30: TDXParams.KLINE_TYPE_30MIN,
                     Query.MIN60: TDXParams.KLINE_TYPE_1HOUR,
                     Query.DAY: TDXParams.KLINE_TYPE_RI_K,
                     Query.WEEK: TDXParams.KLINE_TYPE_WEEKLY,
                     Query.MONTH: TDXParams.KLINE_TYPE_MONTHLY,
                     Query.QUARTER: TDXParams.KLINE_TYPE_3MONTH,
                     Query.YEAR: TDXParams.KLINE_TYPE_YEARLY}
        return ktype_map.get(ktype)
github fasiondog / hikyuu / hikyuu / interactive / volume.py View on Github external
def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60, 
         ma5_n=100, vma1_n=5, vma2_n=10):
    """绘制普通K线图 + 成交量(成交金额)"""
    kdata = stock.getKData(query)
    close = CLOSE(kdata,)
    ma1 = MA(close, ma1_n)
    ma2 = MA(close, ma2_n)
    ma3 = MA(close, ma3_n)
    ma4 = MA(close, ma4_n)
    ma5 = MA(close, ma5_n)

    ax1, ax2 = create_figure(2)
    kdata.plot(axes=ax1)
    ma1.plot(axes=ax1, legend_on=True)
    ma2.plot(axes=ax1, legend_on=True)
    ma3.plot(axes=ax1, legend_on=True)
    ma4.plot(axes=ax1, legend_on=True)
github fasiondog / hikyuu / hikyuu / data_driver / pytdx_data_driver.py View on Github external
def _trans_ktype(self, ktype):
        ktype_map = {Query.MIN: TDXParams.KLINE_TYPE_1MIN,
                     Query.MIN5: TDXParams.KLINE_TYPE_5MIN,
                     Query.MIN15: TDXParams.KLINE_TYPE_15MIN,
                     Query.MIN30: TDXParams.KLINE_TYPE_30MIN,
                     Query.MIN60: TDXParams.KLINE_TYPE_1HOUR,
                     Query.DAY: TDXParams.KLINE_TYPE_RI_K,
                     Query.WEEK: TDXParams.KLINE_TYPE_WEEKLY,
                     Query.MONTH: TDXParams.KLINE_TYPE_MONTHLY,
                     Query.QUARTER: TDXParams.KLINE_TYPE_3MONTH,
                     Query.YEAR: TDXParams.KLINE_TYPE_YEARLY}
        return ktype_map.get(ktype)
github fasiondog / hikyuu / hikyuu / data_driver / jqdata_data_driver.py View on Github external
def _trans_ktype(self, ktype): #此处的周月季年数据只是近似的,目前jqdata未提供聚宽网络平台上的get_bar函数,不能直接取,需要自行用日线数据拼装
        ktype_map = {Query.MIN: '1m',
                     Query.MIN5: '5m',
                     Query.MIN15: '15m',
                     Query.MIN30: '30m',
                     Query.MIN60: '60m',
                     Query.DAY: '1d',
                     Query.WEEK: '7d',
                     Query.MONTH: '30d',
                     Query.QUARTER: '90d',
                     Query.YEAR: '365d'}
        return ktype_map.get(ktype)
github fasiondog / hikyuu / hikyuu / trade_manage / trade.py View on Github external
def PositionList_to_np(pos_list):
        """转化为numpy结构数组"""
        t_type = np.dtype({'names':['证券代码', '证券名称', '买入日期', 
                                    '已持仓天数', '持仓数量', '投入金额', 
                                    '当前市值', '盈亏金额', '盈亏比例'], 
                'formats':['U10','U20', 'datetime64[D]', 'i', 'i', 'd',
                           'd', 'd', 'd']})
        
        sm = StockManager.instance()
        query = Query(-1)
        data = []
        for pos in pos_list:
            invest = pos.buyMoney - pos.sellMoney + pos.totalCost
            k = pos.stock.getKData(query)
            cur_val = k[0].closePrice * pos.number
            bonus = cur_val - invest
            date_list = sm.getTradingCalendar(QueryByDate(Datetime(pos.takeDatetime.date())))
            data.append((pos.stock.market_code, pos.stock.name, 
                         pos.takeDatetime, len(date_list), pos.number, 
                         invest, cur_val, bonus,
                         100 * bonus / invest))
        
        return np.array(data, dtype=t_type)
github fasiondog / hikyuu / hikyuu / data_driver / jqdata_data_driver.py View on Github external
def _trans_ktype(self, ktype): #此处的周月季年数据只是近似的,目前jqdata未提供聚宽网络平台上的get_bar函数,不能直接取,需要自行用日线数据拼装
        ktype_map = {Query.MIN: '1m',
                     Query.MIN5: '5m',
                     Query.MIN15: '15m',
                     Query.MIN30: '30m',
                     Query.MIN60: '60m',
                     Query.DAY: '1d',
                     Query.WEEK: '7d',
                     Query.MONTH: '30d',
                     Query.QUARTER: '90d',
                     Query.YEAR: '365d'}
        return ktype_map.get(ktype)
github fasiondog / hikyuu / hikyuu / interactive / kaufman.py View on Github external
def draw2(block, query = Query(-130), 
         ama1 = AMA(n=10, fast_n=2, slow_n=30),
         ama2 = None,
         n = 10, filter_n = 20, filter_p = 0.1,
         sg_type = 'CROSS',
         show_high_low = True,
         arrow_style = 1):
    """绘制佩里.J.考夫曼(Perry J.Kaufman) 自适应移动平均系统(AMA)"""
    sm = StockManager.instance()
    if block.name == 'SZ':
        kdata = sm['sz000001'].getKData(query)
    elif block.name == 'GEM':
        kdata = sm['sz399006'].getKData(query)
    else:
        kdata = sm['sh000001'].getKData(query)
    
    ax1, ax2, ax3 = create_figure(3)