Exemple #1
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)
Exemple #2
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

Exemple #3
0
        if self.ma10[1] < self.ma20[1] and self.ma10 > self.ma20:
            self.buy('long', self.open, 1, contract = 'IF000.SHFE')
        elif self.position() > 0 and self.ma10[1] > self.ma20[1] and self.ma10 < self.ma20:
            self.sell('long', self.open, 1)

        # 输出pcon1的当前K线开盘价格。
        print(self.open)

        # 夸品种数据引用
        # pcon2的前一根K线开盘价格。
        print(self.open_(1)[1])

if __name__ == '__main__':
    try:
        # 策略的运行对象周期合约
        pcon1 = pcontract('IF000.SHFE', '10.Minute')
        pcon2 = pcontract('IF000.SHFE', '10.Minute')
        # 创建模拟器,这里假设策略要用到两个不同的数据,比如套利。
        simulator = ExecuteUnit([pcon1, pcon2]);
        # 创建策略。
        algo = DemoStrategy(simulator)
        # 运行模拟器,这里会开始事件循环。
        simulator.run()

        # 显示回测结果
        plotting.plot_result(simulator.data[pcon], algo._indicators,
                            algo.blotter.deal_positions, algo.blotter)

    except Exception, e:
        print(e)
def plot_reslist(l_bases_tests):
    import plotting as pl
    for base,rtest in l_bases_tests:
        pl.plot_result(rtest)
Exemple #5
0
        pcon = pcontract('BB.SHFE', '1.Minute')
        #begin_dt, end_dt = '2015-05-25', '2015-06-01'
        #pcon = stock('600848','10.Minute')  # 通过tushare下载股票数据
        simulator = ExecuteUnit([pcon, pcon], '2013-12-12', '2013-12-25')
        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)
        plotting.plot_result(simulator.data[pcon], algo._indicators, signals,
                             algo.blotter.all_holdings)

    except Exception, e:
        import traceback
        print e
        print traceback.format_exc()
        #print e
Exemple #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);
        plotting.plot_result(simulator.data[pcon],
                                    algo._indicators,
                                    signals,
                                    algo.blotter.all_holdings)

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