示例#1
0
def add_strategies(symbols, strategies):
    """ 一个组合中的策略

    Args:
        algos (list): 一个策略组合

    Returns:
        Profile. 组合结果
    """
    simulator = ExecuteUnit(symbols, "1980-1-1", "2100-1-1", None, {})
    profiles = list(simulator.add_strategies(strategies))
    simulator.run()

    return profiles
示例#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
示例#3
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
示例#4
0
文件: qd.py 项目: wocclyl/quantdigger
def set_symbols(pcontracts,
                dt_start="1980-1-1",
                dt_end="2100-1-1",
                n=None,
                spec_date={}):  # 'symbol':[,]
    """ 
    Args:
        pcontracts (list): list of pcontracts(string)
        dt_start (datetime/str): start time of all pcontracts
        dt_end (datetime/str): end time of all pcontracts
        n (int): last n bars
        spec_date (dict): time range for specific pcontracts
    """
    global _simulator
    _simulator = ExecuteUnit(pcontracts, dt_start, dt_end, n, spec_date)
    return _simulator
示例#5
0
def set_symbols(pcons, window_size=0,
                    dt_start=datetime.datetime(1980,1,1),
                    dt_end=datetime.datetime(2100,1,1)):
    """ 添加数据

    Args:
        pcons ([str,]): 周期合约数组

        dt_start (str): 开始时间

        dt_end (str): 结束

        window_size (int): 序列数据的窗口大小
    
    """
    global g_simulator
    ## @TODO pcon格式验证
    g_simulator = ExecuteUnit(pcons, window_size, dt_start, dt_end)
    return g_simulator
示例#6
0
                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:
        for trans in algo.blotter.transactions:
            deals.update_positions(a, b, trans)
    except Exception, e:
示例#7
0
文件: main.py 项目: ntvis/quantdigger
            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:
        pcon = pcontract('IF000.SHFE', '10.Minute')
        begin_dt, end_dt = None, None
        #begin_dt, end_dt = '2015-05-25', '2015-06-01'
        #pcon = stock('600848','10.Minute')  # 通过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())

        # 显示回测结果
        a = {}
示例#8
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) 

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

if __name__ == '__main__':
    try:
        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])
        algo = DemoStrategy(simulator)
        #algo1 = DemoStrategy(simulator)
        #algo2 = DemoStrategy(simulator)
        simulator.run()


        # 显示回测结果
        from quantdigger.datastruct import TradeSide
        ping = 0
        kai = 0
        for t in algo.blotter.transactions:
            if t.side == TradeSide.PING:
                ping += t.quantity
            elif t.side == TradeSide.KAI:
                kai += t.quantity
示例#9
0
        elif self.position(
        ) > 0 and self.ma10[1] > self.ma20[1] and self.ma10 < self.ma20:
            self.sell('long', self.open, 1)

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


if __name__ == '__main__':
    try:
        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 = {}
示例#10
0
        ) > 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:
        pcon = pcontract('IF000.SHFE', '10.Minute')
        begin_dt, end_dt = None, None
        #begin_dt, end_dt = '2015-05-25', '2015-06-01'
        #pcon = stock('600848','10.Minute')  # 通过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())

        # 显示回测结果
        a = {}