Skip to main content

量化交易PYTHON回测系统

Project description

QuantDigger是由一群量化交易爱好者一起开发的开源的股票/期货回测框架 主要用于学习和研究。欢迎大家提供宝贵意见,贡献代码^_^. 或者加入我们的python量化交易群–334555399.

除了开发人员,还要特别感谢 vodkabuaa 给出的意见, ongbe 帮忙修复代码bug, tushare库的作者 Jimmy ,以及所有朋友的支持.

主要代码贡献者:

deepfish

TeaEra

wondereamer

HonePhy

安装

你可以选择pip安装

python install_pip.py  (如果已经安装了pip,略过这一步。)
pip install QuantDigger
python install_dependency.py

或者克隆github代码后本地安装

git clone https://github.com/QuantFans/quantdigger.git
python install.py  (会根据情况安装pip, 及依赖包)

依赖库

  • Python

  • pandas

  • python-dateutil

  • matplotlib

  • numpy

  • TA-Lib

  • logbook

  • pyqt (可选)

  • tushare (可选, 一个非常强大的股票信息抓取工具)

策略DEMO

源码

from quantdigger.kernel.engine.execute_unit import ExecuteUnit
from quantdigger.kernel.indicators.common import MA, BOLL
from quantdigger.kernel.engine.strategy import TradingStrategy, pcontract, stock
import plotting


class DemoStrategy(TradingStrategy):
    """ 策略类 """
    def __init__(self, pcontracts, exe):
        """ 初始化指标变量 """
        super(DemoStrategy, self).__init__(pcontracts, exe)

        self.ma20 = MA(self, self.close, 20,'ma20', 'b', '1')
        self.ma10 = MA(self, self.close, 10,'ma10', 'y', '1')
        self.b_upper, self.b_middler, self.b_lower = BOLL(self, self.close, 10,'boll10', 'y', '1')
        #self.ma2 = NumberSeries(self)

    def on_tick(self):
        """ 策略函数,对每根Bar运行一次。"""
        #self.ma2.update(average(self.open, 10))
        if self.ma10[1] < self.ma20[1] and self.ma10 > self.ma20:
            self.buy('d', self.open, 1)
        elif self.position() > 0 and self.ma10[1] > self.ma20[1] and self.ma10 < self.ma20:
            self.sell('d', self.open, 1)

        print self.position(), self.cash()
        print self.datetime, self.b_upper, self.b_middler, self.b_lower


# 运行策略
begin_dt, end_dt = None, None
pcon = pcontract('SHFE', 'IF000', 'Minutes', 10)
#pcon = stock('600848')  利用tushare远程加载股票数据
simulator = ExecuteUnit(begin_dt, end_dt)
algo = DemoStrategy([pcon], simulator)
simulator.run()

# 显示回测结果
plotting.plot_result(simulator.data[pcon],
            algo._indicators,
            algo.blotter.deal_positions,
            algo.blotter)

策略结果

main.py

  • k线和信号线

    figure_signal.png
  • 资金曲线。

    figure_money.png

其它

mplot_demo.py matplotlib画k线,指标线的demo。
plot.png
pyquant.py 基于pyqt, 集成了ipython和matplotlib的demo。
pyquant.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

QuantDigger-0.13.zip (8.2 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page