{"id":13488634,"url":"https://github.com/QuantFans/quantdigger","last_synced_at":"2025-03-28T01:36:54.962Z","repository":{"id":23911039,"uuid":"27291222","full_name":"QuantFans/quantdigger","owner":"QuantFans","description":"基于python的量化交易平台","archived":false,"fork":false,"pushed_at":"2020-05-02T09:52:06.000Z","size":17793,"stargazers_count":1562,"open_issues_count":19,"forks_count":646,"subscribers_count":215,"default_branch":"master","last_synced_at":"2024-10-01T00:56:01.221Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QuantFans.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-29T04:26:59.000Z","updated_at":"2024-09-20T18:53:49.000Z","dependencies_parsed_at":"2022-07-12T16:07:42.557Z","dependency_job_id":null,"html_url":"https://github.com/QuantFans/quantdigger","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantFans%2Fquantdigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantFans%2Fquantdigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantFans%2Fquantdigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantFans%2Fquantdigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QuantFans","download_url":"https://codeload.github.com/QuantFans/quantdigger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222333976,"owners_count":16968058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:01:19.277Z","updated_at":"2025-03-28T01:36:54.955Z","avatar_url":"https://github.com/QuantFans.png","language":"Python","readme":"QuantDigger 0.6.0\n==================\n    \nQuantDigger是一个基于python的量化回测框架。它借鉴了主流商业软件（比如TB, 金字塔）简洁的策略语法，同时\n避免了它们内置编程语言的局限性，使用通用语言python做为策略开发工具。和 zipline_ , pyalgotrade_ 相比，\nQuantDigger的策略语法更接近策略开发人员的习惯。目前的功能包括：股票回测，期货回测。 支持选股，套利，择时, 组合策略。自带了一个基于matplotlib编写的简单的策略和k线显示界面，能满足广大量化爱好者 基本的回测需求。设计上也兼顾了实盘交易，未来如果有时间，也会加入交易接口。\n\n\n**由于个人时间和工作的关系，本项目不再维护。**\n\n\n\n文档\n-----\nwiki文档_\n\n\n依赖库\n-------\n* matplotlib \n* numpy\n* logbook\n* pandas \n* progressbar2\n* zmq\n* BeautifulSoup4 (tushare需要)\n* lxml (tushare需要)\n* tushare_ (一个非常强大的股票信息抓取工具)\n* python-dateutil(可选)\n* IPython\n* TA-Lib\n\n* 可以用pip安装依赖库:\n    \u003e\u003e\u003e pip install -r requirements/requirements.txt\n* 如果出现pypi源超时情况:\n    \u003e\u003e\u003e pip install -r requirements/requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com\n\n* TA-Lib 通过pip直接安装可能会出错，\n    * 到 http://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib 下载相应版本然后通过命令安装，如\n        \u003e\u003e\u003e pip install TA_Lib-0.4.10-cp36-cp36m-win_amd64.whl\n    * Anaconda用户可以用\n        \u003e\u003e\u003e conda install -c quantopian ta-lib\n\n* finance依赖\n    * 安装 https://github.com/matplotlib/mpl_finance\n\n\n策略组合DEMO\n-----------\n\n源码\n~~~~\n\n.. code:: py\n\n\n   from quantdigger import (\n      Strategy,\n      MA,\n      DateTimeSeries,\n      NumberSeries,\n      set_config,\n      add_strategies,\n      Profile\n   )\n\n\n   class DemoStrategy(Strategy):\n      \"\"\" 策略A1 \"\"\"\n\n      def on_init(self, ctx):\n         \"\"\"初始化数据\"\"\"\n         ctx.ma10 = MA(ctx.close, 10, 'ma10', 'y', 1)\n         ctx.ma20 = MA(ctx.close, 20, 'ma20', 'b', 1)\n         ctx.dt = DateTimeSeries()\n         ctx.month_price = NumberSeries()\n\n      def on_bar(self, ctx):\n         ctx.dt.update(ctx.datetime)\n         if ctx.dt[1].month != ctx.dt[0].month:\n               ctx.month_price.update(ctx.close)\n         if ctx.curbar \u003e 20:\n               if ctx.pos() == 0 and ctx.ma10[2] \u003c ctx.ma20[2] and ctx.ma10[1] \u003e ctx.ma20[1]:\n                  ctx.buy(ctx.close, 1)\n                  ctx.plot_text(\"buy\", 1, ctx.curbar, ctx.close, \"buy\", 'black', 15)\n               elif ctx.pos() \u003e 0 and ctx.ma10[2] \u003e ctx.ma20[2] and \\\n                     ctx.ma10[1] \u003c ctx.ma20[1]:\n                  ctx.plot_text(\"sell\", 1, ctx.curbar, ctx.close, \"sell\", 'blue', 15)\n                  ctx.sell(ctx.close, ctx.pos())\n         ctx.plot_line(\"month_price\", 1, ctx.curbar, ctx.month_price, 'y--', lw=2)\n         return\n\n      def on_exit(self, ctx):\n         return\n\n\n   class DemoStrategy2(Strategy):\n      \"\"\" 策略A2 \"\"\"\n\n      def on_init(self, ctx):\n         \"\"\"初始化数据\"\"\"\n         ctx.ma50 = MA(ctx.close, 50, 'ma50', 'y', 2)\n         ctx.ma100 = MA(ctx.close, 100, 'ma100', 'black', 2)\n\n      def on_symbol(self, ctx):\n         pass\n\n      def on_bar(self, ctx):\n         if ctx.curbar \u003e 100:\n               if ctx.pos() == 0 and ctx.ma50[2] \u003c ctx.ma100[2] and ctx.ma50[1] \u003e ctx.ma100[1]:\n                  ctx.buy(ctx.close, 1)\n               elif ctx.pos() \u003e 0 and ctx.ma50[2] \u003e ctx.ma100[2] and \\\n                     ctx.ma50[1] \u003c ctx.ma100[1]:\n                  ctx.sell(ctx.close, ctx.pos())\n\n         return\n\n      def on_exit(self, ctx):\n         return\n\n\n   if __name__ == '__main__':\n      import timeit\n      start = timeit.default_timer()\n      set_config({'source': 'csv'})\n      profiles = add_strategies(['BB.SHFE-1.Day'], [\n         {\n               'strategy': DemoStrategy('A1'),\n               'capital': 50000.0 * 0.5,\n         },\n         {\n               'strategy': DemoStrategy2('A2'),\n               'capital': 50000.0 * 0.5,\n         }\n      ])\n      stop = timeit.default_timer()\n      print(\"运行耗时: %d秒\" % ((stop - start)))\n\n      # 绘制k线，交易信号线\n      from quantdigger.digger import finance, plotting\n      s = 0\n      # 绘制策略A1, 策略A2, 组合的资金曲线\n      curve0 = finance.create_equity_curve(profiles[0].all_holdings())\n      curve1 = finance.create_equity_curve(profiles[1].all_holdings())\n      curve = finance.create_equity_curve(Profile.all_holdings_sum(profiles))\n      plotting.plot_strategy(profiles[0].data(), profiles[0].technicals(),\n                              profiles[0].deals(), curve0.equity.values,\n                              profiles[0].marks())\n      # 绘制净值曲线\n      plotting.plot_curves([curve.networth])\n      # 打印统计信息\n      print(finance.summary_stats(curve, 252))\n\n\n策略结果\n~~~~~~~\n\n* k线和信号线\n\nk线显示使用了系统自带的一个联动窗口控件，由蓝色的滑块控制显示区域，可以通过鼠标拖拽改变显示区域。\n`上下方向键` 来进行缩放。 \n\n  .. image:: doc/images/plot.png\n     :width: 500px\n\n* 2个策略和组合的资金曲线。\n  \n  .. image:: doc/images/figure_money.png\n     :width: 500px\n\n* 组合的历史净值\n  \n  .. image:: doc/images/figure_networth.png\n     :width: 500px\n\n* 统计结果\n\n::\n       \n    \u003e\u003e\u003e [('Total Return', '-0.99%'), ('Sharpe Ratio', '-5.10'), ('Max Drawdown', '1.72%'), ('Drawdown Duration', '3568')]\n\n\n.. _TeaEra: https://github.com/TeaEra\n.. _deepfish: https://github.com/deepfish\n.. _wondereamer: https://github.com/wondereamer\n.. _HonePhy: https://github.com/HonePhy\n.. _tushare: https://github.com/waditu/tushare\n.. _Jimmy: https://github.com/jimmysoa\n.. _vodkabuaa: https://github.com/vodkabuaa\n.. _ongbe: https://github.com/ongbe\n.. _pyalgotrade: https://github.com/gbeced/pyalgotrade\n.. _zipline: https://github.com/quantopian/zipline\n.. _wiki文档: https://github.com/QuantFans/quantdigger/wiki\n\n\n版本\n~~~~\n\n**0.6.0 版本 2019-05-28**\n\n* 重构回测引擎，使其设计更合理和简洁。\n\n**0.5.1 版本 2017-07-13**\n\n* 在原来0.5.0版的基础上改为支持Python3.6\n\n**0.5.0 版本 2017-01-08**\n\n* 完善文档\n* 数据源可配置\n* 添加shell, 界面，回测引擎三则间的交互框架\n\n**0.3.0 版本 2015-12-09**\n\n* 重新设计回测引擎, 支持组合回测，选股\n* 重构数据模块\n\n**0.2.0 版本 2015-08-18**\n\n* 修复股票回测的破产bug\n* 修复回测权益计算bug\n* 交易信号对的计算从回测代码中分离\n* 把回测金融指标移到digger/finace\n* 添加部分数据结构，添加部分数据结构字段\n* 添加几个mongodb相关的函数\n    \n**0.1.0 版本 2015-06-16**\n\n* 夸品种的策略回测功能\n* 简单的交互\n* 指标，k线绘制\n","funding_links":[],"categories":["Python","回测"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQuantFans%2Fquantdigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FQuantFans%2Fquantdigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQuantFans%2Fquantdigger/lists"}