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))
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.indicators(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)
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 直接单击的时候只有数直线
def on_bar(self, ctx): if ctx.curbar == 1: ctx.buy(ctx.close, 1) elif ctx.curbar == 50: ctx.sell(ctx.close, 1) def on_exit(self, ctx): pass if __name__ == '__main__': start = timeit.default_timer() #ConfigUtil.set(source='tushare') ConfigUtil.set(source='cached-tushare', cache_path='E:/_cache_tushare') set_symbols(['600096.SH-1.Day'], '2000-1-1', '2016-4-1') # set_symbols(['BB.SHFE-1.Minute']) profile = add_strategy([Stg2('S1')], {'capital': 500000.0}) run() stop = timeit.default_timer() six.print_('using time: %d seconds' % (stop - start)) from quantdigger.digger import finance, plotting s = 0 curve0 = finance.create_equity_curve(profile.all_holdings(0)) AnalyzeFrame(profile) plotting.plot_strategy(profile.data(0), {1: profile.technicals(0)}, profile.deals(0), curve0.equity.values, profile.marks(0)) plt.show()
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': 5000000, '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)
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)
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), 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)
elif ctx.position() > 0 and ctx.ma5[1] > ctx.ma10[1] and \ ctx.ma5 < ctx.ma10: ctx.sell('long', ctx.close, 1) def on_final(self, ctx): 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.indicators(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)
def on_exit(self, ctx): pass if __name__ == '__main__': start = timeit.default_timer() # ConfigUtil.set(source='tushare') # ConfigUtil.set(source='cached-tushare', # cache_path='E:/_cache_tushare') # set_symbols(['600056.SH-1.Day'], '2016-01-04', '2016-01-08') ConfigUtil.set(source='csv', data_path='E:/_cache_tushare') set_symbols(['600096.SH-1.Day'], '2015-01-04', '2016-01-08') profile = add_strategy([Stg2('Stg2'), Stg1('Stg1')], {'capital': 100000.0}) run() stop = timeit.default_timer() six.print_('using time: %d seconds' % (stop - start)) curve0 = finance.create_equity_curve(profile.all_holdings(0)) curve = finance.create_equity_curve(profile.all_holdings()) AnalyzeFrame(profile) plotting.plot_strategy(profile.data(0), { # 1:[profile.technicals(0)], 3: [profile.technicals(0)] }, profile.deals(0), curve.equity.values, profile.marks(0)) plotting.plot_curves([curve.networth]) six.print_(finance.summary_stats(curve, 252)) plt.show()
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))