예제 #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)
예제 #2
0
파일: mongotest.py 프로젝트: amozie/amozie
    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))
예제 #3
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)
예제 #4
0
    def on_exit(self, ctx):
        return


if __name__ == '__main__':
    #set_config({ 'source': 'csv' })
    set_symbols(['BB.SHFE-1.Minute'], 0)
    profile = add_strategy(
        [DemoStrategy('A1'), DemoStrategy2('A2')], {
            'captial': 50000.0,
            'ratio': [0.5, 0.5]
        })
    run()
    # 绘制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), 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])
    # 打印统计信息
    print finance.summary_stats(curve, 252 * 4 * 60)
예제 #5
0
    set_config({'source': 'tushare'})
    set_symbols(['300333.SZ-1.Day'])
    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(), profile.technicals(0),
                           profile.deals(0), curve0.equity.values,
                           profile.marks(0))
    #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)
    ## @TODO 直接单击的时候只有数直线
예제 #6
0
            if ctx.ma5[1] < ctx.ma10[1] and ctx.ma5 > ctx.ma10:
                ctx.buy(ctx.close, 1) 
            elif ctx.position() > 0 and ctx.ma5[1] > ctx.ma10[1] and \
                 ctx.ma5 < ctx.ma10:
                ctx.sell(ctx.close, 1) 
        return

    def on_exit(self, ctx):
        return

if __name__ == '__main__':
    set_symbols(['BB.SHFE-1.Minute'], 0)
    profile = add_strategy([DemoStrategy('A1'), DemoStrategy2('A2')], { 'captial': 50000,
                              'ratio': [0.2, 0.8] })
    run()

    # 绘制k线,交易信号线
    from quantdigger.digger import finance, plotting
    plotting.plot_strategy(profile.data(0), profile.technicals(1), profile.deals(1))
    # 绘制策略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_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)
예제 #7
0
    start = timeit.default_timer()
    #set_symbols(['BB.SHFE-1.Minute']) 
    #set_symbols(['BB.SHFE']) 
    set_config({ 'source': 'csv' })
    set_symbols(['BB.SHFE-1.Day'])
    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(), profile.technicals(0),
                            profile.deals(0), curve0.equity.values,
                            profile.marks(0))
    #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)
    ## @TODO 直接单击的时候只有数直线
예제 #8
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))
예제 #9
0
    def on_bar(self, ctx):
        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")], {"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)
예제 #10
0
        'source': 'mongodb',
        'dbname': 'quantdigger'
    })
    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()
    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), 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))
예제 #11
0
        if ctx.curbar > 10:
            if ctx.ma5[1] < ctx.ma10[1] and ctx.ma5 > ctx.ma10:
                ctx.buy(ctx.close, 1) 
                six.print_('策略%s, 买入%s'%(ctx.strategy, ctx.symbol))
            elif ctx.position() is not None and ctx.ma5[1] > ctx.ma10[1] and \
                 ctx.ma5 < ctx.ma10:
                ctx.sell(ctx.close, 1) 
                six.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())
    six.print_('组合A', finance.summary_stats(curve1, 252*4*60))
    # 打印组合2的统计信息
    curve2 = finance.create_equity_curve(comb2.all_holdings())
    six.print_('组合B', finance.summary_stats(curve2, 252*4*60))