{ "info": { "author": "bopo.wang", "author_email": "ibopo@126.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "\nPyAlgoTrade tushare module\n==============================\n\n.. image:: https://img.shields.io/pypi/v/pyalgotrade_tushare.svg\n :target: https://pypi.python.org/pypi/pyalgotrade_tushare\n\n.. image:: https://img.shields.io/travis/bopo/pyalgotrade_tushare.svg\n :target: https://travis-ci.org/bopo/pyalgotrade_tushare\n\n.. image:: https://readthedocs.org/projects/pyalgotrade_tushare/badge/?version=latest\n :target: https://pyalgotrade_tushare.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\n.. image:: https://pyup.io/repos/github/bopo/pyalgotrade_tushare/shield.svg\n :target: https://pyup.io/repos/github/bopo/pyalgotrade_tushare/\n :alt: Updates\n\n\n\n* \u5f00\u6e90\u534f\u8bae: MIT license\n* \u5728\u7ebf\u6587\u6863: https://pyalgotrade_tushare.readthedocs.io.\n\n\u5b89\u88c5\u65b9\u6cd5\n--------\n\n::\n\n\t# PIP \u81ea\u52a8\u5b89\u88c5\u65b9\u6cd5\n\tpip install pyalgotrade_tushare\n\n\t# \u624b\u52a8\u4e0b\u8f7d\u6e90\u7801\u5b89\u88c5\n\tgit clone https://github.com/bopo/pyalgotrade_tushare.git \n\tcd pyalgotrade_tushare\n\tpython setup.py install\n\n\n\u4f7f\u7528\u8bf4\u660e\n--------\n\n\u4e0d\u591a\u8bdd\uff0c\u7b80\u5355\u4e00\u4e2a\u4f8b\u5b50\n\n::\n\n\tfrom pyalgotrade import plotter, strategy\n\tfrom pyalgotrade.stratanalyzer import sharpe\n\tfrom pyalgotrade.technical import ma\n\n\tfrom pyalgotrade_tushare import tools\n\n\n\tclass MyStrategy(strategy.BacktestingStrategy):\n\t def __init__(self, feed, instrument):\n\t super().__init__(feed)\n\n\t self.__position = None\n\t self.__sma = ma.SMA(feed[instrument].getCloseDataSeries(), 150)\n\t self.__instrument = instrument\n\t self.getBroker()\n\n\t def onEnterOk(self, position):\n\t execInfo = position.getEntryOrder().getExecutionInfo()\n\t self.info(\"\u4e70\u5165 %.2f\" % (execInfo.getPrice()))\n\n\t def onEnterCanceled(self, position):\n\t self.__position = None\n\n\t def onExitOk(self, position):\n\t execInfo = position.getExitOrder().getExecutionInfo()\n\t self.info(\"\u5356\u51fa %.2f\" % (execInfo.getPrice()))\n\t self.__position = None\n\n\t def onExitCanceled(self, position):\n\t # If the exit was canceled, re-submit it.\n\t self.__position.exitMarket()\n\n\t def getSMA(self):\n\t return self.__sma\n\n\t def onBars(self, bars):\n\t # \u6bcf\u4e00\u4e2a\u6570\u636e\u90fd\u4f1a\u62b5\u8fbe\u8fd9\u91cc\uff0c\u5c31\u50cfbecktest\u4e2d\u7684next\n\t # Wait for enough bars to be available to calculate a SMA.\n\t if self.__sma[-1] is None:\n\t return\n\n\t # bar.getTyoicalPrice = (bar.getHigh() + bar.getLow() + bar.getClose())/ 3.0\n\t bar = bars[self.__instrument]\n\n\t # If a position was not opened, check if we should enter a long position.\n\t if self.__position is None:\n\t if bar.getPrice() > self.__sma[-1]:\n\t # \u5f00\u591a\u5934.\n\t self.__position = self.enterLong(self.__instrument, 100, True)\n\n\t # \u5e73\u6389\u591a\u5934\u5934\u5bf8.\n\t elif bar.getPrice() < self.__sma[-1] and not self.__position.exitActive():\n\t self.__position.exitMarket()\n\n\n\tif __name__ == '__main__':\n\t instruments = [\"600036\"]\n\n\t feeds = tools.build_feed(instruments, 2013, 2018, \"histdata\")\n\n\t # 3.\u5b9e\u4f8b\u5316\u7b56\u7565\n\t strat = MyStrategy(feeds, instruments[0])\n\n\t # 4.\u8bbe\u7f6e\u6307\u6807\u548c\u7ed8\u56fe\n\t ratio = sharpe.SharpeRatio()\n\t strat.attachAnalyzer(ratio)\n\t plter = plotter.StrategyPlotter(strat)\n\n\t # 5.\u8fd0\u884c\u7b56\u7565\n\t strat.run()\n\t strat.info(\"\u6700\u7ec8\u6536\u76ca: %.2f\" % strat.getResult())\n\n\t # 6.\u8f93\u51fa\u590f\u666e\u7387\u3001\u7ed8\u56fe\n\t strat.info(\"\u590f\u666e\u6bd4\u7387: \" + str(ratio.getSharpeRatio(0)))\n\t plter.plot()\n\n\n\n\n\u7248\u672c\u66f4\u65b0\n--------\n* \u4fee\u6539\u4e86 PIP \u5b89\u88c5\u7a0b\u5e8f\u95ee\u9898\n* \u672c\u7a0b\u5e8f\u53ea\u652f\u6301 python3.\n\n\u8d21\u732e\u540d\u5355\n---------\n\n- bopo.wang\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bopo/pyalgotrade_tushare", "keywords": "pyalgotrade_tushare", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "pyalgotrade_tushare", "package_url": "https://pypi.org/project/pyalgotrade_tushare/", "platform": "", "project_url": "https://pypi.org/project/pyalgotrade_tushare/", "project_urls": { "Homepage": "https://github.com/bopo/pyalgotrade_tushare" }, "release_url": "https://pypi.org/project/pyalgotrade_tushare/0.1.0/", "requires_dist": null, "requires_python": "", "summary": "pyalgotrade tushare module", "version": "0.1.0" }, "last_serial": 4623762, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "8c1daa0621b62458887f4f959e6743cc", "sha256": "2249544a50e0452bb3ddbb90b7e2d0ec4a883547b0d2920107b15f44383ae288" }, "downloads": -1, "filename": "pyalgotrade_tushare-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8c1daa0621b62458887f4f959e6743cc", "packagetype": "bdist_wheel", "python_version": "3.7", "requires_python": null, "size": 7058, "upload_time": "2018-12-21T07:00:13", "url": "https://files.pythonhosted.org/packages/53/55/23985f217e878775a933fa92f0c9bcfd88c89d691f0bccd161447c963915/pyalgotrade_tushare-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ad64e0939fcf67245b76550fe3182146", "sha256": "e1fab86c51585f709211405006021e7a1cd3cf221e54182c2c6a37e3214f44b1" }, "downloads": -1, "filename": "pyalgotrade_tushare-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ad64e0939fcf67245b76550fe3182146", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6199, "upload_time": "2018-12-21T07:00:09", "url": "https://files.pythonhosted.org/packages/b8/05/8072c65afae857a2c09c19460776a51f7a80866160a7bbe0f95040e51247/pyalgotrade_tushare-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8c1daa0621b62458887f4f959e6743cc", "sha256": "2249544a50e0452bb3ddbb90b7e2d0ec4a883547b0d2920107b15f44383ae288" }, "downloads": -1, "filename": "pyalgotrade_tushare-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8c1daa0621b62458887f4f959e6743cc", "packagetype": "bdist_wheel", "python_version": "3.7", "requires_python": null, "size": 7058, "upload_time": "2018-12-21T07:00:13", "url": "https://files.pythonhosted.org/packages/53/55/23985f217e878775a933fa92f0c9bcfd88c89d691f0bccd161447c963915/pyalgotrade_tushare-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ad64e0939fcf67245b76550fe3182146", "sha256": "e1fab86c51585f709211405006021e7a1cd3cf221e54182c2c6a37e3214f44b1" }, "downloads": -1, "filename": "pyalgotrade_tushare-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ad64e0939fcf67245b76550fe3182146", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6199, "upload_time": "2018-12-21T07:00:09", "url": "https://files.pythonhosted.org/packages/b8/05/8072c65afae857a2c09c19460776a51f7a80866160a7bbe0f95040e51247/pyalgotrade_tushare-0.1.0.tar.gz" } ] }