Ejemplo n.º 1
0
def plot_result(price_data, indicators, signals, blotter):
    """ 
        显示回测结果。
    """
    try:
        curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
        print finance.output_summary_stats(curve)

        fig = plt.figure()
        frame = widgets.MultiWidgets(fig,
                                    price_data,
                                    50          # 窗口显示k线数量。
                                    )

        # 添加k线
        kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
        frame.add_widget(0, kwindow, True)
        # 交易信号。
        signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
        frame.add_indicator(0, signal)

        # 添加指标
        k_axes, = frame
        for indic in indicators:
            indic.plot(k_axes)
        frame.draw_widgets()

        fig2 = plt.figure()
        ax = fig2.add_axes((0.1, 0.1, 0.9, 0.9))
        ax.plot(curve.equity)
        plt.show()

    except Exception, e:
        print(e)
Ejemplo n.º 2
0
def plot_result(price_data, indicators, signals,
        blotter):
    """ 
        显示回测结果。
    """
    try:
        curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
        print finance.output_summary_stats(curve)

        fig = plt.figure()
        frame = widgets.MultiWidgets(fig,
                                    price_data,
                                    50          # 窗口显示k线数量。
                                    )

        # 添加k线
        kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
        frame.add_widget(0, kwindow, True)
        # 交易信号。
        signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
        frame.add_indicator(0, signal)

        # 添加指标
        k_axes, = frame
        for indic in indicators:
            indic.plot(k_axes)
        frame.draw_widgets()

        fig2 = plt.figure()
        ax = fig2.add_axes((0.1, 0.1, 0.9, 0.9))
        ax.plot(curve.equity)
        plt.show()

    except Exception, e:
        print(e)
Ejemplo n.º 3
0
def plot_result(price_data, indicators, signals,
        blotter):
    """ 
        显示回测结果。
    """
    try:
        print "summary.." 
        dts = map(lambda x : datetime.fromtimestamp(x / 1000), price_data.index)
        price_data.index = dts
        print dts[-1]
        curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
        print finance.output_summary_stats(curve)

        print "plotting.."
        fig = plt.figure()
        frame = widgets.MultiWidgets(fig,
                                    price_data,
                                    50          # 窗口显示k线数量。
                                    )

        # 添加k线
        kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
        frame.add_widget(0, kwindow, True)
        # 交易信号。
        signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
        frame.add_indicator(0, signal)

        # 添加指标
        k_axes, = frame
        for indic in indicators:
            indic.plot(k_axes)
        frame.draw_widgets()
        
        # 画资金曲线
        #print curve.equity
        fig2 = plt.figure()
        ax = fig2.add_axes((0.1, 0.1, 0.8, 0.8))
        ax.xaxis.set_major_formatter(TimeFormatter(curve.index, '%Y-%m-%d' ))
        ax.get_yaxis().get_major_formatter().set_useOffset(False)
        #ax.get_yaxis().get_major_formatter().set_scientific(False)
        ax.set_xticks(xticks_to_display(len(curve)))
        ax.plot(curve.equity)
        plt.show()

    except Exception, e:
        print(e)
Ejemplo n.º 4
0
def plot_result(price_data, indicators, signals, blotter):
    """ 
        显示回测结果。
    """
    print "summary.."
    dts = map(lambda x: datetime.fromtimestamp(x / 1000), price_data.index)
    price_data.index = dts
    print dts[-1]
    curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
    print finance.output_summary_stats(curve)

    print "plotting.."
    fig = plt.figure()
    frame = widgets.MultiWidgets(
        fig,
        price_data,
        50  # 窗口显示k线数量。
        #4, 1     # 两个1:1大小的窗口
    )

    # 添加k线
    kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
    frame.add_widget(0, kwindow, True)
    ## 交易信号。
    signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
    frame.add_indicator(0, signal)
    ## @bug indicators导致的双水平线!
    ## @todo 完mplot_demo上套。
    #frame.add_indicator(0, Volume(None, price_data.open, price_data.close, price_data.volume))

    ## 添加指标
    for indic in indicators:
        frame.add_indicator(0, indic)

    frame.draw_widgets()

    # 画资金曲线
    #print curve.equity
    #fig2 = plt.figure()
    #ax = fig2.add_axes((0.1, 0.1, 0.8, 0.8))
    #ax.xaxis.set_major_formatter(TimeFormatter(curve.index, '%Y-%m-%d' ))
    #ax.get_yaxis().get_major_formatter().set_useOffset(False)
    ##ax.get_yaxis().get_major_formatter().set_scientific(False)
    #ax.set_xticks(xticks_to_display(len(curve)))
    #ax.plot(curve.equity)
    plt.show()
Ejemplo n.º 5
0
def plot_result(price_data, indicators, signals,
        blotter):
    """ 
        显示回测结果。
    """
    print "summary.." 
    dts = map(lambda x : datetime.fromtimestamp(x / 1000), price_data.index)
    price_data.index = dts
    print dts[-1]
    curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
    print finance.output_summary_stats(curve)

    print "plotting.."
    fig = plt.figure()
    frame = widgets.MultiWidgets(fig, price_data,
                                50         # 窗口显示k线数量。
                                #4, 1     # 两个1:1大小的窗口
                                )

    # 添加k线
    kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
    frame.add_widget(0, kwindow, True)
    ## 交易信号。
    signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
    frame.add_indicator(0, signal)
    ## @bug indicators导致的双水平线!
    ## @todo 完mplot_demo上套。
    #frame.add_indicator(0, Volume(None, price_data.open, price_data.close, price_data.volume))

    ## 添加指标
    for indic in indicators:
        frame.add_indicator(0, indic)

    frame.draw_widgets()
    
    # 画资金曲线
    #print curve.equity
    #fig2 = plt.figure()
    #ax = fig2.add_axes((0.1, 0.1, 0.8, 0.8))
    #ax.xaxis.set_major_formatter(TimeFormatter(curve.index, '%Y-%m-%d' ))
    #ax.get_yaxis().get_major_formatter().set_useOffset(False)
    ##ax.get_yaxis().get_major_formatter().set_scientific(False)
    #ax.set_xticks(xticks_to_display(len(curve)))
    #ax.plot(curve.equity)
    plt.show()
Ejemplo n.º 6
0
def plot_result(price_data, indicators, signals, blotter):
    """ 
        显示回测结果。
    """
    try:
        curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
        print finance.output_summary_stats(curve)

        fig = plt.figure()
        frame = widgets.MultiWidgets(
            fig,
            price_data,
            50  # 窗口显示k线数量。
        )

        # 添加k线
        kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
        frame.add_widget(0, kwindow, True)
        # 交易信号。
        signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
        frame.add_indicator(0, signal)

        # 添加指标
        k_axes, = frame
        for indic in indicators:
            indic.plot(k_axes)
        frame.draw_widgets()

        fig2 = plt.figure()
        ax = fig2.add_axes((0.1, 0.1, 0.8, 0.8))
        delta = curve.index[1] - curve.index[0]
        ax.xaxis.set_major_formatter(TimeFormatter(curve.index, '%Y-%m-%d'))
        ax.set_xticks(xticks_to_display(len(curve)))
        ax.plot(curve.equity)
        plt.show()

    except Exception, e:
        print(e)
Ejemplo n.º 7
0
def plot_result(price_data, indicators, signals,
        blotter):
    """ 
        显示回测结果。
    """
    try:
        curve = finance.create_equity_curve_dataframe(blotter.all_holdings)
        print finance.output_summary_stats(curve)

        fig = plt.figure()
        frame = widgets.MultiWidgets(fig,
                                    price_data,
                                    50          # 窗口显示k线数量。
                                    )

        # 添加k线
        kwindow = widgets.CandleWindow("kwindow", price_data, 100, 50)
        frame.add_widget(0, kwindow, True)
        # 交易信号。
        signal = mplots.TradingSignalPos(None, price_data, signals, lw=2)
        frame.add_indicator(0, signal)

        # 添加指标
        k_axes, = frame
        for indic in indicators:
            indic.plot(k_axes)
        frame.draw_widgets()

        fig2 = plt.figure()
        ax = fig2.add_axes((0.1, 0.1, 0.8, 0.8))
        delta = curve.index[1] - curve.index[0]
        ax.xaxis.set_major_formatter(TimeFormatter(curve.index, '%Y-%m-%d' ))
        ax.set_xticks(xticks_to_display(len(curve)))
        ax.plot(curve.equity)
        plt.show()

    except Exception, e:
        print(e)