Exemplo n.º 1
0
def run(TheStrategy, code, datasource=_default_datasource):
    print 'code: ' + code
    pcon = stock(code)
    #dt_start = '20130101'
    #dt_end = '20150819'
    dt_start = None
    dt_end = None
    simulator = ExecuteUnit([pcon], dt_start, dt_end, datasource=datasource)
    algo = TheStrategy(simulator)
    simulator.run()
    a = {}
    b = []
    try:
        for trans in algo.blotter.transactions:
            deals.update_positions(a, b, trans)
    except Exception, e:
        print e
Exemplo n.º 2
0
def run(TheStrategy, code, datasource=_default_datasource):
    print 'code: ' + code
    pcon = stock(code)
    #dt_start = '20130101'
    #dt_end = '20150819'
    dt_start = None
    dt_end = None
    simulator = ExecuteUnit([pcon], dt_start, dt_end, datasource=datasource)
    algo = TheStrategy(simulator)
    simulator.run()
    a = {}
    b = []
    try:
        for trans in algo.blotter.transactions:
            deals.update_positions(a, b, trans);
    except Exception, e:
        print e
Exemplo n.º 3
0
            self.sell('long', price, self.position())
            #six.print_('sel', self.datetime[0].date(), price, self.position())
            #six.print_('---')
            if price > self.buy_price:
                self.num_win += 1


if __name__ == '__main__':
    pcon = stock(code)
    simulator = ExecuteUnit(
        [pcon],
        None,  #'2015-08-02',
        # 使用自定义的数据源
        datasource=ds163.CachedStock163Source('163cache'))
    algo = DemoStrategy(simulator)
    simulator.run()
    #six.print_('close: ', algo.close.data)
    #six.print_('close length: ', algo.close.length_history)
    six.print_('total: %s, win: %s' % (algo.num_cont, algo.num_win))

    # 显示回测结果
    a = {}
    b = []
    try:
        for trans in algo.blotter.transactions:
            deals.update_positions(a, b, trans)
    except Exception, e:
        six.print_(e)
    plotting.plot_result(simulator.data[pcon], algo._indicators, b,
                         algo.blotter)
Exemplo n.º 4
0
        #algo2 = DemoStrategy(simulator)
        simulator.run()

        #for deal in algo.blotter.deal_positions:
            ## code...
            #print("----------------")
            #print("开仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;") % \
                #(deal.open_datetime, deal.open_price, Direction.type_to_str(deal.direction), deal.quantity)
            #print("平仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;盈亏: %f;") % \
                #(deal.close_datetime, deal.close_price, Direction.type_to_str(deal.direction), deal.quantity, deal.profit())

        # 显示回测结果
        a = {}
        b = []
        try:
            for trans in algo.blotter.transactions:
                deals.update_positions(a, b, trans);
        except Exception, e:
            print e
        plotting.plot_result(simulator.data[pcon],
                                    algo._indicators,
                                    b,
                                    algo.blotter)

        
    except Exception, e:
        import traceback
        print traceback.format_exc()
        #print e

Exemplo n.º 5
0
        #algo2 = DemoStrategy(simulator)
        simulator.run()

        #for deal in algo.blotter.deal_positions:
            ## code...
            #print("----------------")
            #print("开仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;") % \
                #(deal.open_datetime, deal.open_price, Direction.type_to_str(deal.direction), deal.quantity)
            #print("平仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;盈亏: %f;") % \
                #(deal.close_datetime, deal.close_price, Direction.type_to_str(deal.direction), deal.quantity, deal.profit())

        # 显示回测结果
        positions = {}
        signals = [] 
        for trans in algo.blotter.transactions:
            deals.update_positions(positions, signals, trans);
        #d =  simulator.data[pcon]['close']
        #for i in d:
            #print i
        #assert False
        plotting.plot_result(simulator.data[pcon],
                                    algo._indicators,
                                    signals,
                                    algo.blotter)

        
    except Exception, e:
        import traceback
        print e
        print traceback.format_exc()
        #print e
Exemplo n.º 6
0
        algo = DemoStrategy(simulator)
        #algo1 = DemoStrategy(simulator)
        #algo2 = DemoStrategy(simulator)
        simulator.run()

        #for deal in algo.blotter.deal_positions:
        ## code...
        #print("----------------")
        #print("开仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;") % \
        #(deal.open_datetime, deal.open_price, Direction.type_to_str(deal.direction), deal.quantity)
        #print("平仓时间: %s;成交价格: %f;买卖方向: %s;成交量: %d;盈亏: %f;") % \
        #(deal.close_datetime, deal.close_price, Direction.type_to_str(deal.direction), deal.quantity, deal.profit())

        # 显示回测结果
        positions = {}
        signals = []
        for trans in algo.blotter.transactions:
            deals.update_positions(positions, signals, trans)
        #d =  simulator.data[pcon]['close']
        #for i in d:
        #print i
        #assert False
        plotting.plot_result(simulator.data[pcon], algo._indicators, signals,
                             algo.blotter)

    except Exception, e:
        import traceback
        print e
        print traceback.format_exc()
        #print e