Example #1
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))
                #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 #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 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)