Esempio n. 1
0
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)
    ma5.plot(axes=ax1, legend_on=True)
    
    sg = SG_Cross(OP(MA(n=ma1_n, type=ma_type)), OP(MA(n=ma2_n, type=ma_type)))
    sg.setTO(kdata)
    sg.plot(axes=ax1, kdata=kdata)
    
    vol = VOL(kdata)
    total = len(kdata)
    
    engine = get_current_draw_engine()
    if engine == 'matplotlib':
        rg = range(total)
        x = [i-0.2 for i in rg]
        x1 = [x[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
        y1 = [vol[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
        x2 = [x[i] for i in rg if kdata[i].closePrice <= kdata[i].openPrice]
        y2 = [vol[i] for i in rg if kdata[i].closePrice <= kdata[i].openPrice]
        ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
        ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')
    
    elif engine == 'echarts':
        vol.bar(axes=ax2, color='r')
    else:
        pass
    
    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)
    
    if query.kType == Query.WEEK and stock.market == 'SH' and stock.code=='000001':
        CVAL(0.16e+009, total, color='b',linestyle='--')
        #ax2.hlines(0.16e+009,0,len(kdata),color='b',linestyle='--')

    ax_set_locator_formatter(ax1, kdata.getDatetimeList(), kdata.getQuery().kType)
    adjust_axes_show([ax1, ax2])
    return show_gcf()
Esempio n. 2
0
def draw2(stock,
          query=Query(-130),
          ma1_n=7,
          ma2_n=20,
          ma3_n=30,
          ma4_n=42,
          ma5_n=100,
          vma1_n=5,
          vma2_n=10):
    """绘制普通K线图 + 成交量(成交金额)+ MACD"""
    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, ax3 = create_figure(3)
    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)
    ma5.plot(axes=ax1, legend_on=True)

    vol = VOL(kdata)
    total = len(kdata)
    rg = range(total)
    x = [i - 0.2 for i in rg]
    x1 = [x[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
    y1 = [vol[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
    x2 = [x[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
    y2 = [vol[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
    ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
    ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')
    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)

    ax_draw_macd(ax3, kdata)

    ax1.set_xlim((0, len(kdata)))
    ax_set_locator_formatter(ax1, kdata.getDatetimeList(),
                             kdata.getQuery().kType)
    adjust_axes_show([ax1, ax2, ax3])
    return show_gcf()
Esempio n. 3
0
def draw2(stock, query=Query(-130), ma1_n=7, ma2_n=20, ma3_n=30, 
          ma4_n=42, ma5_n=100, vma1_n=5, vma2_n=10):
    """绘制普通K线图 + 成交量(成交金额)+ MACD"""
    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, ax3 = create_figure(3)
    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)
    ma5.plot(axes=ax1, legend_on=True)
    
    vol = VOL(kdata)
    total = len(kdata)
    
    engine = get_current_draw_engine()
    if engine == 'matplotlib':
        rg = range(total)
        x = [i-0.2 for i in rg]
        x1 = [x[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
        y1 = [vol[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
        x2 = [x[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
        y2 = [vol[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
        ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
        ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')
   
    elif engine == 'echarts':
        vol.bar(axes=ax2, color='r', legend_on=True)
    else:
        pass
        
    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)
    
    ax_draw_macd(ax3, kdata)

    ax1.set_xlim((0, len(kdata)))
    ax_set_locator_formatter(ax1, kdata.getDatetimeList(), kdata.getQuery().kType)
    adjust_axes_show([ax1, ax2, ax3])
    return show_gcf()
    
Esempio n. 4
0
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)
    ma5.plot(axes=ax1, legend_on=True)

    sg = SG_Cross(OP(MA(n=ma1_n, type=ma_type)), OP(MA(n=ma2_n, type=ma_type)))
    sg.setTO(kdata)
    sg.plot(axes=ax1, kdata=kdata)

    vol = VOL(kdata)
    total = len(kdata)
    rg = range(total)
    x = [i - 0.2 for i in rg]
    x1 = [x[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
    y1 = [vol[i] for i in rg if kdata[i].closePrice > kdata[i].openPrice]
    x2 = [x[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
    y2 = [vol[i] for i in rg if kdata[i].closePrice < kdata[i].openPrice]
    ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
    ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')
    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)

    if query.kType == Query.WEEK and stock.market == 'SH' and stock.code == '000001':
        ax2.hlines(0.16e+009, 0, len(kdata), color='b', linestyle='--')

    ax_set_locator_formatter(ax1, kdata.getDatetimeList(),
                             kdata.getQuery().kType)
    adjust_axes_show([ax1, ax2])
    return show_gcf()
Esempio n. 5
0
def draw2(stock,
          query=Query(-130),
          ma1_n=7,
          ma2_n=20,
          ma3_n=30,
          ma4_n=42,
          ma5_n=100,
          vma1_n=5,
          vma2_n=10):
    """绘制普通K线图 + 成交量(成交金额)+ MACD"""
    kdata = stock.get_kdata(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, ax3 = create_figure(3)
    kdata.plot(axes=ax1)
    ma1.plot(axes=ax1, legend_on=True, kref=kdata)
    ma2.plot(axes=ax1, legend_on=True, kref=kdata)
    ma3.plot(axes=ax1, legend_on=True, kref=kdata)
    ma4.plot(axes=ax1, legend_on=True, kref=kdata)
    ma5.plot(axes=ax1, legend_on=True, kref=kdata)

    vol = VOL(kdata)
    x1 = IF(kdata.close > kdata.open, vol, 0)
    x2 = IF(kdata.close <= kdata.open, vol, 0)
    x1.bar(axes=ax2, width=0.4, color='r', edgecolor='r', kref=kdata)
    x2.bar(axes=ax2, width=0.4, color='g', edgecolor='g', kref=kdata)

    vol.bar(axes=ax2, color='r', legend_on=True)

    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)

    ax_draw_macd(ax3, kdata)

    ax1.set_xlim((0, len(kdata)))
    ax_set_locator_formatter(ax1, kdata.get_datetime_list(),
                             kdata.get_query().ktype)
    adjust_axes_show([ax1, ax2, ax3])
    return show_gcf()
Esempio n. 6
0
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.get_kdata(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, kref=kdata)
    ma2.plot(axes=ax1, legend_on=True, kref=kdata)
    ma3.plot(axes=ax1, legend_on=True, kref=kdata)
    ma4.plot(axes=ax1, legend_on=True, kref=kdata)
    ma5.plot(axes=ax1, legend_on=True, kref=kdata)

    sg = SG_Cross(MA(n=ma1_n), MA(n=ma2_n))
    sg.to = kdata
    sg.plot(axes=ax1, kdata=kdata)

    vol = VOL(kdata)
    total = len(kdata)

    x1 = IF(kdata.close > kdata.open, vol, 0)
    x2 = IF(kdata.close <= kdata.open, vol, 0)
    x1.bar(axes=ax2, width=0.4, color='r', edgecolor='r', kref=kdata)
    x2.bar(axes=ax2, width=0.4, color='g', edgecolor='g', kref=kdata)

    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True, kref=kdata)
    vma2.plot(axes=ax2, legend_on=True, kref=kdata)

    if query.ktype == Query.WEEK and stock.market == 'SH' and stock.code == '000001':
        CVAL(0.16e+009, total, color='b', linestyle='--', kref=kdata)
        #ax2.hlines(0.16e+009,0,len(kdata),color='b',linestyle='--')

    ax_set_locator_formatter(ax1, kdata.get_datetime_list(),
                             kdata.get_query().ktype)
    adjust_axes_show([ax1, ax2])
    return show_gcf()
Esempio n. 7
0
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.get_kdata(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)
    ma5.plot(axes=ax1, legend_on=True)

    sg = SG_Cross(MA(n=ma1_n), MA(n=ma2_n))
    sg.to = kdata
    sg.plot(axes=ax1, kdata=kdata)

    vol = VOL(kdata)
    total = len(kdata)

    engine = get_current_draw_engine()
    if engine == 'matplotlib':
        rg = range(total)
        x = [i - 0.2 for i in rg]
        x1 = [x[i] for i in rg if kdata[i].close > kdata[i].open]
        y1 = [vol[i] for i in rg if kdata[i].close > kdata[i].open]
        x2 = [x[i] for i in rg if kdata[i].close <= kdata[i].open]
        y2 = [vol[i] for i in rg if kdata[i].close <= kdata[i].open]
        ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
        ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')

    elif engine == 'echarts':
        vol.bar(axes=ax2, color='r')
    else:
        pass

    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)

    if query.ktype == Query.WEEK and stock.market == 'SH' and stock.code == '000001':
        CVAL(0.16e+009, total, color='b', linestyle='--')
        #ax2.hlines(0.16e+009,0,len(kdata),color='b',linestyle='--')

    ax_set_locator_formatter(ax1, kdata.get_datetime_list(), kdata.get_query().ktype)
    adjust_axes_show([ax1, ax2])
    return show_gcf()
Esempio n. 8
0
def draw2(
    stock,
    query=Query(-130),
    ma1_n=7,
    ma2_n=20,
    ma3_n=30,
    ma4_n=42,
    ma5_n=100,
    vma1_n=5,
    vma2_n=10
):
    """绘制普通K线图 + 成交量(成交金额)+ MACD"""
    kdata = stock.get_kdata(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, ax3 = create_figure(3)
    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)
    ma5.plot(axes=ax1, legend_on=True)

    vol = VOL(kdata)
    total = len(kdata)

    engine = get_current_draw_engine()
    if engine == 'matplotlib':
        rg = range(total)
        x = [i - 0.2 for i in rg]
        x1 = [x[i] for i in rg if kdata[i].close > kdata[i].open]
        y1 = [vol[i] for i in rg if kdata[i].close > kdata[i].open]
        x2 = [x[i] for i in rg if kdata[i].close < kdata[i].open]
        y2 = [vol[i] for i in rg if kdata[i].close < kdata[i].open]
        ax2.bar(x1, y1, width=0.4, color='r', edgecolor='r')
        ax2.bar(x2, y2, width=0.4, color='g', edgecolor='g')

    elif engine == 'echarts':
        vol.bar(axes=ax2, color='r', legend_on=True)
    else:
        pass

    vma1 = MA(vol, vma1_n)
    vma2 = MA(vol, vma2_n)
    vma1.plot(axes=ax2, legend_on=True)
    vma2.plot(axes=ax2, legend_on=True)

    ax_draw_macd(ax3, kdata)

    ax1.set_xlim((0, len(kdata)))
    ax_set_locator_formatter(ax1, kdata.get_datetime_list(), kdata.get_query().ktype)
    adjust_axes_show([ax1, ax2, ax3])
    return show_gcf()