Example #1
0
        if ctx.curbar > 10:
            if ctx.ma5[1] < ctx.ma10[1] and ctx.ma5 > ctx.ma10:
                ctx.buy(ctx.close, 1) 
                print('策略%s, 买入%s'%(ctx.strategy, ctx.symbol))
            elif ctx.position() > 0 and ctx.ma5[1] > ctx.ma10[1] and \
                 ctx.ma5 < ctx.ma10:
                ctx.sell(ctx.close, 1) 
                print('策略%s, 卖出%s'%(ctx.strategy, ctx.symbol))

    def on_symbol(self, ctx):
        return

    def on_exit(self, ctx):
        return

if __name__ == '__main__':
    from quantdigger.digger import finance

    set_symbols(['BB.SHFE-1.Minute'], 0)
    comb1 = add_strategy([DemoStrategy('A1'), DemoStrategy2('A2')],
                            { 'captial': 10000, 'ratio': [0.5, 0.5] })
    comb2 = add_strategy([DemoStrategy('B1'), DemoStrategy2('B2')],
                            { 'captial': 20000, 'ratio': [0.4, 0.6] })
    run()
    # 打印组合1的统计信息
    curve1 = finance.create_equity_curve(comb1.all_holdings())
    print '组合A', finance.summary_stats(curve1, 252*4*60)
    # 打印组合2的统计信息
    curve2 = finance.create_equity_curve(comb2.all_holdings())
    print '组合B', finance.summary_stats(curve2, 252*4*60)
Example #2
0
    ConfigUtil.set(source='cached-tushare', cache_path='E:/_cache_tushare')
    set_symbols(['600096.SH-1.Day'], '2015-01-04', '2016-01-08')
    #set_symbols(['BB.SHFE'])
    #set_symbols(['BB'])
    profile = add_strategy(
        [DemoStrategy('A1'), DemoStrategy2('A2')], {
            'capital': 50000.0,
            'ratio': [0.5, 0.5]
        })

    run()
    stop = timeit.default_timer()
    six.print_("运行耗时: %d秒" % ((stop - start)))

    # 绘制k线,交易信号线
    from quantdigger.digger import finance, plotting
    s = 0
    # 绘制策略A1, 策略A2, 组合的资金曲线
    curve0 = finance.create_equity_curve(profile.all_holdings(0))
    curve1 = finance.create_equity_curve(profile.all_holdings(1))
    curve = finance.create_equity_curve(profile.all_holdings())
    plotting.plot_strategy(profile.data(0), {1: profile.technicals(0)},
                           profile.deals(0), curve.equity)
    plotting.plot_curves([curve0.equity, curve1.equity, curve.equity],
                         colors=['r', 'g', 'b'],
                         names=[profile.name(0),
                                profile.name(1), 'A0'])
    # 绘制净值曲线
    plotting.plot_curves([curve.networth])
    # 打印统计信息
    six.print_(finance.summary_stats(curve, 252 * 4 * 60))
Example #3
0
        for symbol in self.candicates:
            if ctx.pos('long', symbol) == 0:
                ctx.buy(ctx[symbol].close, 1, symbol) 
                #six.print_("buy:", symbol)


        self.candicates = []
        self.to_sell = []
        return

    def on_exit(self, ctx):
        six.print_("策略运行结束.")
        return



if __name__ == '__main__':
    # 
    set_symbols(['*.SH'])
    algo = DemoStrategy('A1')
    profile = add_strategy([algo], { 'capital': 500000000.0 })

    run()

    from quantdigger.digger import finance, plotting
    curve = finance.create_equity_curve(profile.all_holdings())
    #plotting.plot_strategy(profile.data('AA.SHFE-1.Minute'), profile.technicals(0),
                            #profile.deals(0), curve.equity.values)
    ## 绘制净值曲线
    plotting.plot_curves([curve.networth])
Example #4
0
if __name__ == '__main__':
    import timeit
    start = timeit.default_timer()
    #set_symbols(['BB.SHFE-1.Minute']) 
    #set_symbols(['BB.SHFE']) 
    set_symbols(['BB'])
    profile = add_strategy([DemoStrategy('A1'), DemoStrategy2('A2')],
                            { 'capital': 50000.0, 'ratio': [0.5, 0.5] })

    run()
    stop = timeit.default_timer()
    print "运行耗时: %d秒" % ((stop - start ))

    # 绘制k线,交易信号线
    from quantdigger.digger import finance, plotting
    s = 0
    # 绘制策略A1, 策略A2, 组合的资金曲线
    curve0 = finance.create_equity_curve(profile.all_holdings(0))
    curve1 = finance.create_equity_curve(profile.all_holdings(1))
    curve = finance.create_equity_curve(profile.all_holdings())
    plotting.plot_strategy(profile.data(0), profile.technicals(0),
                            profile.deals(0), curve0.equity.values)
    #plotting.plot_curves([curve0.equity, curve1.equity, curve.equity],
                        #colors=['r', 'g', 'b'],
                        #names=[profile.name(0), profile.name(1), 'A0'])
    ## 绘制净值曲线
    #plotting.plot_curves([curve.networth])
    ## 打印统计信息
    #print finance.summary_stats(curve, 252*4*60)
    ## @TODO 直接单击的时候只有数直线
Example #5
0
                print('策略%s, 卖出%s' % (ctx.strategy, ctx.symbol))

    def on_symbol(self, ctx):
        return

    def on_exit(self, ctx):
        return


if __name__ == '__main__':
    from quantdigger.digger import finance

    set_symbols(['BB.SHFE-1.Minute'])
    comb1 = add_strategy(
        [DemoStrategy('A1'), DemoStrategy2('A2')], {
            'capital': 10000000,
            'ratio': [0.5, 0.5]
        })
    comb2 = add_strategy(
        [DemoStrategy('B1'), DemoStrategy2('B2')], {
            'capital': 20000000,
            'ratio': [0.4, 0.6]
        })
    run()
    # 打印组合1的统计信息
    curve1 = finance.create_equity_curve(comb1.all_holdings())
    print '组合A', finance.summary_stats(curve1, 252 * 4 * 60)
    # 打印组合2的统计信息
    curve2 = finance.create_equity_curve(comb2.all_holdings())
    print '组合B', finance.summary_stats(curve2, 252 * 4 * 60)
                #six.print_("sell:", symbol)

        for symbol in self.candicates:
            if ctx.pos('long', symbol) == 0:
                ctx.buy(ctx[symbol].close, 1, symbol)
                #six.print_("buy:", symbol)

        self.candicates = []
        self.to_sell = []
        return

    def on_exit(self, ctx):
        six.print_("策略运行结束.")
        return


if __name__ == '__main__':
    #
    set_symbols(['*.SH'])
    algo = DemoStrategy('A1')
    profile = add_strategy([algo], {'capital': 500000000.0})

    run()

    from quantdigger.digger import finance, plotting
    curve = finance.create_equity_curve(profile.all_holdings())
    #plotting.plot_strategy(profile.data('AA.SHFE-1.Minute'), profile.technicals(0),
    #profile.deals(0), curve.equity.values)
    ## 绘制净值曲线
    plotting.plot_curves([curve.networth])
Example #7
0
if __name__ == '__main__':
    from quantdigger.digger import finance

    comb1 = add_strategies(['BB.SHFE-1.Minute'], [
        {
            'strategy': DemoStrategy('A1'),
            'capital': 10000000.0 * 0.5,
        },
        {
            'strategy': DemoStrategy('A2'),
            'capital': 10000000.0 * 0.5,
        }
    ])
    # 打印组合1的统计信息
    curve1 = finance.create_equity_curve(Profile.all_holdings_sum(comb1))
    six.print_('组合A', finance.summary_stats(curve1, 252*4*60))

    comb2 = add_strategies(['BB.SHFE-1.Minute'], [
        {
            'strategy': DemoStrategy('B1'),
            'capital': 20000000 * 0.4,
        },
        {
            'strategy': DemoStrategy('B2'),
            'capital': 20000000 * 0.6,
        }
    ])
    # 打印组合2的统计信息
    curve2 = finance.create_equity_curve(Profile.all_holdings_sum(comb2))
    six.print_('组合B', finance.summary_stats(curve2, 252*4*60))
Example #8
0
if __name__ == '__main__':
    import timeit
    start = timeit.default_timer()
    set_config({'source': 'csv'})
    profiles = add_strategies(['BB.SHFE-1.Day'],
                              [{
                                  'strategy': DemoStrategy('A1'),
                                  'capital': 50000.0 * 0.5,
                              }, {
                                  'strategy': DemoStrategy2('A2'),
                                  'capital': 50000.0 * 0.5,
                              }])
    stop = timeit.default_timer()
    print("运行耗时: %d秒" % ((stop - start)))

    # 绘制k线,交易信号线
    from quantdigger.digger import finance, plotting
    s = 0
    # 绘制策略A1, 策略A2, 组合的资金曲线
    curve0 = finance.create_equity_curve(profiles[0].all_holdings())
    curve1 = finance.create_equity_curve(profiles[1].all_holdings())
    curve = finance.create_equity_curve(Profile.all_holdings_sum(profiles))
    plotting.plot_strategy(profiles[0].data(), profiles[0].technicals(),
                           profiles[0].deals(), curve0.equity.values,
                           profiles[0].marks())
    # 绘制净值曲线
    plotting.plot_curves([curve.networth])
    # 打印统计信息
    print(finance.summary_stats(curve, 252))
Example #9
0
            if ctx.pos('long', symbol) == 0:
                ctx.buy(ctx[symbol].close, 1, symbol)


        self.candicates = []
        self.to_sell = []
        return

    def on_exit(self, ctx):
        print("策略运行结束.")
        return



if __name__ == '__main__':
    #
    profiles = add_strategies(['*.SH'], [
        {
            'strategy': DemoStrategy('A1'),
            'capital': 500000000.0
        }
    ])


    from quantdigger.digger import finance, plotting
    curve = finance.create_equity_curve(Profile.all_holdings_sum(profiles))
    #plotting.plot_strategy(profile.data('AA.SHFE-1.Minute'), profile.technicals(0),
                            #profile.deals(0), curve.equity.values)
    ## 绘制净值曲线
    plotting.plot_curves([curve.networth])