Example #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
Example #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
Example #3
0
                price = self.close[0]
                self.buy('long', price, quantity, contract=code)
                self.buy_price = price
                self.num_cont += 1
                #six.print_('buy', self.datetime[0].date(), price, quantity)
        elif self.position() > 0 and self.masmall < self.mabig:
            price = self.close[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:
Example #4
0
            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)

        # 夸品种数据引用
        print self.open_(1)[1], self.open
        #print self.position(), self.cash()
        #print self.datetime, self.b_upper, self.b_middler, self.b_lower


if __name__ == '__main__':
    try:
        begin_dt, end_dt = None, None
        pcon = pcontract('IF000.SHFE', '10.Minute')
        pcon = stock('600848')  # 通过tushare下载股票数据
        simulator = ExecuteUnit([pcon, pcon], begin_dt, end_dt)
        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())

        # 显示回测结果
Example #5
0
        #self.ma2.update(average(self.open, 10))
        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)

        # 夸品种数据引用
        print self.open_(1)[1], self.open
        #print self.position(), self.cash()
        #print self.datetime, self.b_upper, self.b_middler, self.b_lower

if __name__ == '__main__':
    try:
        begin_dt, end_dt = None, None
        pcon = pcontract('IF000.SHFE', '10.Minute')
        pcon = stock('600848')  # 通过tushare下载股票数据
        simulator = ExecuteUnit([pcon, pcon], begin_dt, end_dt)
        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())

        # 显示回测结果
            if quantity > 0:
                price = self.close[0]
                self.buy('long', price, quantity, contract = code)
                self.buy_price = price
                self.num_cont += 1
                #print 'buy', self.datetime[0].date(), price, quantity
        elif self.position() > 0 and self.masmall < self.mabig:
            price = self.close[0]
            self.sell('long', price, self.position())
            #print 'sel', self.datetime[0].date(), price, self.position()
            #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()
    #print 'close: ', algo.close.data
    #print 'close length: ', algo.close.length_history
    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);