{"id":94,"date":"2021-10-30T11:23:54","date_gmt":"2021-10-30T03:23:54","guid":{"rendered":"http:\/\/www.qddlh.com\/?p=94"},"modified":"2021-10-30T11:23:55","modified_gmt":"2021-10-30T03:23:55","slug":"backtrader-%e5%bf%ab%e9%80%9f%e5%bc%80%e5%a7%8b%ef%bc%88%e5%ae%9e%e7%8e%b0%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.qddlh.com\/?p=94","title":{"rendered":"Backtrader-\u5feb\u901f\u5f00\u59cb\uff08\u5b9e\u73b0\u6570\u636e\u53ef\u89c6\u5316\uff09"},"content":{"rendered":"\n<p>\u867d\u7136\u5728\u4ea4\u6613\u65e5\u6253\u5370\u65e5\u5fd7\u8f93\u51fa\u662f\u53ef\u4ee5\u8ddf\u8e2a\u7cfb\u7edf\u7684\u64cd\u4f5c\u6d41\u7a0b\uff0c\u4f46\u662f\u4eba\u4eec\u66f4\u4e50\u610f\u770b\u56fe\u7247\uff0c\u4ea4\u6613\u548c\u64cd\u4f5c\u6570\u636e\u53ef\u89c6\u5316\u66f4\u597d\u7406\u89e3\u4ea4\u6613\u8fc7\u7a0b\u3002\u589e\u52a0\u56fe\u5f62\u5c55\u793a\u6570\u636e\u4e5f\u5f88\u5bb9\u6613\uff0c\u53ea\u9700\u8981\u589e\u52a0\u4e00\u884c\u4ee3\u7801\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cerebro.plot()<\/code><\/pre>\n\n\n\n<p>\u56fe\u5f62\u5c55\u793a\u6570\u636e\u65b9\u6cd5\u8981\u5728cerebro.run()\u6267\u884c<\/p>\n\n\n\n<p>\u4e3a\u4e86\u80fd\u66f4\u597d\u7684\u5c55\u793a\u81ea\u52a8\u6570\u636e\u53ef\u89c6\u5316\uff0c\u589e\u52a0\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u6307\u6807\u3002\u6307\u6807\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>EMA \u6307\u6570\u5e73\u6ed1\u79fb\u52a8\u5e73\u5747\u7ebf<\/li><li>WMA \u52a0\u6743\u79fb\u52a8\u5e73\u5747\u7ebf<\/li><li>SLOWKD KD\u5feb\u6162\u6307\u6807<\/li><li>MACD \u6307\u6570\u5e73\u6ed1\u5f02\u540c\u79fb\u52a8\u5e73\u5747\u7ebf<\/li><li>RSI \u76f8\u5bf9\u76f8\u82e5\u6307\u6807<\/li><li>SMA \u7b80\u5355\u79fb\u52a8\u5e73\u5747\u7ebf<\/li><li>ART \u5e73\u5747\u771f\u5b9e\u6ce2\u5e45<\/li><\/ul>\n\n\n\n<p>\u5728Strategy\u7c7b\u7684init\u65b9\u6cd5\u4e2d\u589e\u52a0\u5bf9\u5e94\u7684\u6307\u6807<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Indicators for the plotting show\r\nbt.indicators.ExponentialMovingAverage(self.datas&#91;0], period=25)\r\nbt.indicators.WeightedMovingAverage(self.datas&#91;0], period=25).subplot = True\r\nbt.indicators.StochasticSlow(self.datas&#91;0])\r\nbt.indicators.MACDHisto(self.datas&#91;0])\r\nrsi = bt.indicators.RSI(self.datas&#91;0])\r\nbt.indicators.SmoothedMovingAverage(rsi, period=10)\r\nbt.indicators.ATR(self.datas&#91;0]).plot = False<\/code><\/pre>\n\n\n\n<p>\u5168\u4ee3\u7801<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>qtbt\\data\\stockinfo.csv.tmp removed!\r\nStarting Portfolio Value: 100000.00\r\n2020-02-26, Close, 11.20\r\n2020-02-26, BUY CREATE, 11.20\r\n2020-02-27, BUY EXECUTED, Price: 11.20, Cost: 1120.00, Comm 1.12 \r\n2020-02-27, Close, 11.21\r\n2020-02-28, Close, 10.85\r\n2020-02-28, SELL CREATE, 10.85\r\n2020-03-02, SELL EXECUTED, Price: 10.95, Cost: 1120.00, Comm 1.09\r\n2020-03-02, OPERATION PROFIT, GROSS -25.00, NET -27.21\r\n2020-03-02, Close, 11.04\n......\n2021-09-15, OPERATION PROFIT, GROSS 1.00, NET -0.84\r\n2021-09-15, Close, 9.19\r\n2021-09-16, Close, 9.12\r\n2021-09-17, Close, 9.11\r\n2021-09-22, Close, 9.03\r\n2021-09-23, Close, 9.03\r\n2021-09-24, Close, 9.02\r\n2021-09-27, Close, 9.02\r\n2021-09-28, Close, 9.03\r\n2021-09-29, Close, 9.02\r\n2021-09-30, Close, 9.00\r\nFinal Portfolio Value: 99758.50<\/code><\/pre>\n\n\n\n<p>\u751f\u6210\u56fe\u7247<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"628\" src=\"http:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0-1024x628.png\" alt=\"\" class=\"wp-image-100\" srcset=\"https:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0-1024x628.png 1024w, https:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0-300x184.png 300w, https:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0-768x471.png 768w, https:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0-1536x942.png 1536w, https:\/\/www.qddlh.com\/wp-content\/uploads\/2021\/10\/Figure_0.png 1620w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u867d\u7136\u5728\u4ea4\u6613\u65e5\u6253\u5370\u65e5\u5fd7\u8f93\u51fa\u662f\u53ef\u4ee5\u8ddf\u8e2a\u7cfb\u7edf\u7684\u64cd\u4f5c\u6d41\u7a0b\uff0c\u4f46\u662f\u4eba\u4eec\u66f4\u4e50\u610f\u770b\u56fe\u7247\uff0c\u4ea4\u6613\u548c\u64cd\u4f5c\u6570\u636e\u53ef\u89c6\u5316\u66f4\u597d\u7406\u89e3\u4ea4\u6613\u8fc7\u7a0b\u3002\u589e\u52a0\u56fe\u5f62\u5c55\u793a\u6570\u636e\u4e5f\u5f88\u5bb9\u6613\uff0c\u53ea\u9700\u8981\u589e\u52a0\u4e00\u884c\u4ee3\u7801\u5373\u53ef\uff1a \u56fe\u5f62\u5c55\u793a\u6570\u636e\u65b9\u6cd5\u8981\u5728cerebro.run()\u6267\u884c \u4e3a\u4e86\u80fd\u66f4\u597d\u7684\u5c55\u793a\u81ea\u52a8\u6570\u636e\u53ef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":30,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[11],"class_list":["post-94","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-btuserguide","tag-backtrader"],"_links":{"self":[{"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":4,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=\/wp\/v2\/media\/30"}],"wp:attachment":[{"href":"https:\/\/www.qddlh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qddlh.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}