{"id":238,"date":"2018-07-09T10:24:54","date_gmt":"2018-07-09T10:24:54","guid":{"rendered":""},"modified":"2018-07-09T10:24:54","modified_gmt":"2018-07-09T10:24:54","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=238","title":{"rendered":"\u5e03\u6797\u7ebf\u8ba1\u7b97"},"content":{"rendered":"<p>\n\t<span style=\"font-size:14px;\">\u5e03\u6797\u7ebfWIKI\uff1a<\/span><a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6\" target=\"_blank\"><span style=\"font-size:14px;\">https:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6<\/span><\/a>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\">\u6807\u51c6\u5deeWIKI\uff1a<\/span><a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE\" target=\"_blank\"><span style=\"font-size:14px;\">https:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE<\/span><\/a>\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\">\u5e03\u6797\u7ebf\u8ba1\u7b97\u516c\u5f0f\uff1a<\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\">1\uff0e\u8ba1\u7b97MA&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">MA = \u6700\u8fd1N\u65e5\u6536\u76d8\u4ef7\u4e4b\u548c \/ N\u65e5&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">2\uff0e\u8ba1\u7b97MD&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">MD = \u5e73\u65b9\u6839 ((\u6700\u8fd1N\u65e5(\u6536\u76d8\u4ef7 &#8211; MA)\u5e73\u65b9\u4e4b\u548c\uff09\/N)&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">3\uff0e\u8ba1\u7b97MB\u3001UP\u3001DN&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">MB = \u6536\u76d8\u4ef7\u7684N\u65e5\u7b80\u5355\u79fb\u52a8\u5e73\u5747\u503c<\/span><br \/>\n<span style=\"font-size:14px;\">UP = MB + P * MD&nbsp;<\/span><br \/>\n<span style=\"font-size:14px;\">DN = MB &#8211; P * MD&nbsp;<\/span><\/p>\n<p><span style=\"font-size:14px;\">\u5e03\u6797\u5e26\u5929\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a20\uff0cP\u51b3\u5b9a\u5e03\u6797\u5e26\u7684\u5bbd\u5ea6\uff0c\u9ed8\u8ba4\u503c\u4e3a2\u3002<\/span>\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\">\u4e0b\u9762\u662f\u4e00\u4e2aStorm\u8282\u70b9\u8ba1\u7b97BOLL\u6307\u6807\u7684\u4ee3\u7801\u7247\u6bb5\uff1a<\/span>\n<\/p>\n<p>\n\t\n<\/p>\n<pre class=\"prettyprint lang-py linenums\">class MarketCandleIndicatorCalcBOLL(Bolt):\r\n    outputs = [\"exchange_symbol\", \"exchange\", \"symbol\", \"update_candle_period_list\", \"market_cache_json\"]\r\n\r\n    def initialize(self, storm_conf, context):\r\n        pass\r\n\r\n    ########################################################################################\r\n    def _calc_boll(self, marketDict, calcPeriod, width):\r\n        indiStr = \"boll_\" + str(calcPeriod) + \"_\" + str(width)\r\n        maIndiStr = \"ma\" + str(calcPeriod)\r\n        for period in marketDict[\"candle\"]:\r\n            for idx, candleDict in enumerate(marketDict[\"candle\"][period]):\r\n                if idx &lt; calcPeriod - 1:\r\n                    continue\r\n                if \"ma\" not in marketDict[\"indicator\"][period][idx]:\r\n                    continue\r\n                if maIndiStr not in marketDict[\"indicator\"][period][idx][\"ma\"]:\r\n                    continue\r\n                if \"boll\" not in marketDict[\"indicator\"][period][idx]:\r\n                    marketDict[\"indicator\"][period][idx][\"boll\"] = dict()\r\n                if indiStr in marketDict[\"indicator\"][period][idx][\"boll\"]:\r\n                    continue\r\n                currMa = marketDict[\"indicator\"][period][idx][\"ma\"][maIndiStr]\r\n                closeStdDevSum = 0.0\r\n                for beforeIdxDev in xrange(calcPeriod):\r\n                    closeStdDevSum += (marketDict[\"candle\"][period][idx - beforeIdxDev][\"close\"] - currMa) ** 2\r\n\r\n                closeMd = math.sqrt(closeStdDevSum \/ calcPeriod)\r\n                bollMb = currMa\r\n                bollUp = bollMb + width * closeMd\r\n                bollDn = bollMb - width * closeMd\r\n                if bollUp - bollDn != 0:\r\n                    bollPb = round((candleDict[\"close\"] - bollDn) \/ (bollUp - bollDn) * 100, 2)\r\n                else:\r\n                    bollPb = 50.0\r\n                if bollMb != 0:\r\n                    bollBw = round((bollUp - bollDn) \/ bollMb * 100, 2)\r\n                else:\r\n                    bollBw = 0.0\r\n                marketDict[\"indicator\"][period][idx][\"boll\"][indiStr] = {\r\n                    \"up\": bollUp,\r\n                    \"middle\": bollMb,\r\n                    \"down\": bollDn,\r\n                    \"pb\": bollPb,\r\n                    \"bw\": bollBw\r\n                }\r\n\r\n    ########################################################################################\r\n    def process(self, tup):\r\n        routerField = tup.values[0]\r\n        exchange = tup.values[1]\r\n        symbol = tup.values[2]\r\n        updatePeriodListStr = tup.values[3]\r\n        marketJson = tup.values[4]\r\n\r\n        try:\r\n            marketDict = json.loads(marketJson)\r\n        except Exception, e:\r\n            self.logger.error(\"Market cache json loads failed. Exception: \" + str(e))\r\n            return\r\n\r\n        self._calc_boll(marketDict, 20, 2)\r\n\r\n        try:\r\n            marketIndicatorJson = json.dumps(marketDict, ensure_ascii=False)\r\n        except Exception, e:\r\n            self.logger.error(\"Dumps json of market BOLL indicator failed. Exception: \" + str(e))\r\n            marketIndicatorJson = marketJson\r\n\r\n        self.emit([routerField, exchange, symbol, updatePeriodListStr, marketIndicatorJson])\r\n\r\n<\/pre>\n<p>\n\t\n<\/p>\n<p>\n\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\n\t<span style=\"font-size:16px;\">\u5e03\u6797\u7ebfWIKI\uff1a<\/span><a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6\" target=\"_blank\"><span style=\"font-size:16px;\">https:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6<\/span><\/a>\n<\/p>\n<p>\n\t<span style=\"font-size:16px;\">\u6807\u51c6\u5deeWIKI\uff1a<\/span><a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE\" target=\"_blank\"><span style=\"font-size:16px;\">https:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE<\/span><\/a>\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<span style=\"font-size:16px;\">\u5e03\u6797\u7ebf\u8ba1\u7b97\u516c\u5f0f\uff1a<\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px;\">1\uff0e\u8ba1\u7b97MA&nbsp;<\/span><br \/>\n<span style=\"font-size:16px;\">MA = \u6700\u8fd1N\u65e5\u6536\u76d8\u4ef7\u4e4b\u548c \/ N\u65e5&nbsp;<\/span><br \/>\n<span style=\"font-size:16px;\">2\uff0e\u8ba1\u7b97MD&nbsp;<\/span><br \/>\n<span style=\"font-size:16px;\">MD = \u5e73\u65b9\u6839 ((\u6700\u8fd1&#8230;<\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[338],"tags":[],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5e03\u6797\u7ebf\u8ba1\u7b97 - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=238\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5e03\u6797\u7ebf\u8ba1\u7b97 - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"\u5e03\u6797\u7ebfWIKI\uff1ahttps:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6    \u6807\u51c6\u5deeWIKI\uff1ahttps:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE        \u5e03\u6797\u7ebf\u8ba1\u7b97\u516c\u5f0f\uff1a    1\uff0e\u8ba1\u7b97MA&nbsp; MA = \u6700\u8fd1N\u65e5\u6536\u76d8\u4ef7\u4e4b\u548c \/ N\u65e5&nbsp; 2\uff0e\u8ba1\u7b97MD&nbsp; MD = \u5e73\u65b9\u6839 ((\u6700\u8fd1...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=238\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-09T10:24:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"zinan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=238#webpage\",\"url\":\"http:\/\/weizn.net\/?p=238\",\"name\":\"\\u5e03\\u6797\\u7ebf\\u8ba1\\u7b97 - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"datePublished\":\"2018-07-09T10:24:54+00:00\",\"dateModified\":\"2018-07-09T10:24:54+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=238#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=238\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=238#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\\u5e03\\u6797\\u7ebf\\u8ba1\\u7b97\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=238#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=238#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"\\u5e03\\u6797\\u7ebf\\u8ba1\\u7b97\",\"datePublished\":\"2018-07-09T10:24:54+00:00\",\"dateModified\":\"2018-07-09T10:24:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=238#webpage\"},\"wordCount\":60,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"articleSection\":[\"\\u91cf\\u5316\\u4ea4\\u6613\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=238#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5e03\u6797\u7ebf\u8ba1\u7b97 - Wayne&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/weizn.net\/?p=238","og_locale":"zh_CN","og_type":"article","og_title":"\u5e03\u6797\u7ebf\u8ba1\u7b97 - Wayne&#039;s Blog","og_description":"\u5e03\u6797\u7ebfWIKI\uff1ahttps:\/\/zh.wikipedia.org\/wiki\/%E5%B8%83%E6%9E%97%E5%B8%A6    \u6807\u51c6\u5deeWIKI\uff1ahttps:\/\/zh.wikipedia.org\/wiki\/%E6%A8%99%E6%BA%96%E5%B7%AE        \u5e03\u6797\u7ebf\u8ba1\u7b97\u516c\u5f0f\uff1a    1\uff0e\u8ba1\u7b97MA&nbsp; MA = \u6700\u8fd1N\u65e5\u6536\u76d8\u4ef7\u4e4b\u548c \/ N\u65e5&nbsp; 2\uff0e\u8ba1\u7b97MD&nbsp; MD = \u5e73\u65b9\u6839 ((\u6700\u8fd1...","og_url":"http:\/\/weizn.net\/?p=238","og_site_name":"Wayne&#039;s Blog","article_published_time":"2018-07-09T10:24:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=238#webpage","url":"http:\/\/weizn.net\/?p=238","name":"\u5e03\u6797\u7ebf\u8ba1\u7b97 - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"datePublished":"2018-07-09T10:24:54+00:00","dateModified":"2018-07-09T10:24:54+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=238#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=238"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=238#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"\u5e03\u6797\u7ebf\u8ba1\u7b97"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=238#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=238#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"\u5e03\u6797\u7ebf\u8ba1\u7b97","datePublished":"2018-07-09T10:24:54+00:00","dateModified":"2018-07-09T10:24:54+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=238#webpage"},"wordCount":60,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"articleSection":["\u91cf\u5316\u4ea4\u6613"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=238#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=238"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}