在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:quantdigger开源软件地址:https://gitee.com/easonq/quantdigger开源软件介绍:QuantDigger 0.4.4QuantDigger是一个基于python的量化回测框架。它借鉴了主流商业软件(比如TB, 金字塔)简洁的策略语法,同时避免了它们内置编程语言的局限性,使用通用语言python做为策略开发工具。和 zipline , pyalgotrade 相比,QuantDigger的策略语法更接近策略开发人员的习惯。目前的功能包括:股票回测,期货回测。 支持选股,套利,择时, 组合策略。自带了一个基于matplotlib编写的简单的策略和k线显示界面,能满足广大量化爱好者 基本的回测需求。设计上也兼顾了实盘交易,未来如果有时间,也会加入交易接口。开发人员都是量化爱好者,也欢迎感兴趣的新朋友加入开发, 我的QQ交流群:334555399。 除了开发人员,也特别感谢以下朋友给的建议: 北京的 vodkabuaa 国元证券的王林峰 深大的邓志浩 安装--- 克隆github代码后本地安装(推荐) git clone https://github.com/QuantFans/quantdigger.gitpython setupscripts\install.py (会根据情况安装pip, 及依赖包) 依赖库
如果出现pypi源超时情况,可以通过命令方式进行安装依赖库: pip2 -r requirements/requirements.txt --upgrade -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 策略组合DEMO源码#from quantdigger.engine.series import NumberSeries#from quantdigger.indicators.common import MA#from quantdigger.util import pcontractfrom quantdigger import *class DemoStrategy(Strategy): """ 策略A1 """ def on_init(self, ctx): """初始化数据""" ctx.ma10 = MA(ctx.close, 10, 'ma10', 'y', 2) ctx.ma20 = MA(ctx.close, 20, 'ma20', 'b', 2) def on_symbol(self, ctx): """ 选股 """ return def on_bar(self, ctx): if ctx.curbar > 20: if ctx.ma10[2] < ctx.ma20[2] and ctx.ma10[1] > ctx.ma20[1]: ctx.buy(ctx.close, 1) elif ctx.pos() > 0 and ctx.ma10[2] > ctx.ma20[2] and \ ctx.ma10[1] < ctx.ma20[1]: ctx.sell(ctx.close, ctx.pos()) def on_exit(self, ctx): returnclass DemoStrategy2(Strategy): """ 策略A2 """ def on_init(self, ctx): """初始化数据""" ctx.ma5 = MA(ctx.close, 5, 'ma5', 'y', 2) ctx.ma10 = MA(ctx.close, 10, 'ma10', 'black', 2) def on_symbol(self, ctx): """ 选股 """ return def on_bar(self, ctx): if ctx.curbar > 10: if ctx.ma5[2] < ctx.ma10[2] and ctx.ma5[1] > ctx.ma10[1]: ctx.buy(ctx.close, 1) elif ctx.pos() > 0 and ctx.ma5[2] > ctx.ma10[2] and \ ctx.ma5[1] < ctx.ma10[1]: ctx.sell(ctx.close, ctx.pos()) def on_exit(self, ctx): returnif __name__ == '__main__': set_symbols(['BB.SHFE-1.Minute'], 0) # 创建组合策略 # 初始资金5000, 两个策略的资金配比为0.2:0.8 profile = add_strategy([DemoStrategy('A1'), DemoStrategy2('A2')], { 'captial': 5000, '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) 策略结果
k线显示使用了系统自带的一个联动窗口控件,由蓝色的滑块控制显示区域,可以通过鼠标拖拽改变显示区域。上下方向键 来进行缩放。
>>> [('Total Return', '-0.99%'), ('Sharpe Ratio', '-5.10'), ('Max Drawdown', '1.72%'), ('Drawdown Duration', '3568')] 界面控制其它~~~
版本~~~ TODO
0.3.0 版本 2015-12-09
0.2.0 版本 2015-08-18
0.15版本 2015-06-16
|
请发表评论