{"id":6222,"date":"2025-05-31T14:42:25","date_gmt":"2025-06-04T07:26:25","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6222"},"modified":"2025-06-04T14:42:25","modified_gmt":"2025-06-04T07:26:25","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8%e8%82%a1%e7%a5%a8%e5%b8%82%e5%80%bc%e6%af%94%e9%80%9a%e9%81%93stock-to-marketratiochannel%e4%ba%a4%e6%98%93%e6%8c%87%e6%a8%99","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8%e8%82%a1%e7%a5%a8%e5%b8%82%e5%80%bc%e6%af%94%e9%80%9a%e9%81%93stock-to-marketratiochannel%e4%ba%a4%e6%98%93%e6%8c%87%e6%a8%99\/","title":{"rendered":"\u638c\u63e1\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053(Stock-to-Market Ratio Channel)\u4ea4\u6613\u6307\u6a19\uff1a2025 Python \u5b8c\u6574\u6559\u5b78\u8207\u5be6\u4f5c\u7bc4\u4f8b"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, \u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053, Stock-to-Market Ratio Channel, \u4ea4\u6613\u6307\u6a19, \u4f7f\u7528\u6642\u6a5f, \u80a1\u7968\u5206\u6790, \u6295\u8cc7\u7b56\u7565\"><\/p>\n<h1>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053(Stock-to-Market Ratio Channel) \u4ea4\u6613\u6307\u6a19\u4f7f\u7528\u6642\u6a5f\u4ee5\u53caPython\u7bc4\u4f8b<\/h1>\n<p>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053(Stock-to-Market Ratio Channel)\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u6280\u8853\u5206\u6790\u6307\u6a19\uff0c\u5e6b\u52a9\u6295\u8cc7\u8005\u5224\u65b7\u80a1\u7968\u7684\u50f9\u683c\u8d70\u52e2\uff0c\u4e26\u63d0\u4f9b\u6295\u8cc7\u8005\u66f4\u591a\u7684\u4ea4\u6613\u6a5f\u6703\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u7684\u4f7f\u7528\u6642\u6a5f\uff0c\u4e26\u63d0\u4f9b2025\u6700\u65b0\u7684Python\u7bc4\u4f8b\uff0c\u8b93\u6295\u8cc7\u8005\u80fd\u5920\u66f4\u6709\u6548\u5730\u5229\u7528\u9019\u500b\u6307\u6a19\u4f86\u505a\u51fa\u660e\u667a\u7684\u6295\u8cc7\u6c7a\u7b56\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\uff1f<\/h2>\n<p>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u662f\u4e00\u7a2e\u6280\u8853\u5206\u6790\u6307\u6a19\uff0c\u57fa\u65bc\u80a1\u7968\u5e02\u503c\u6bd4\u7387\u8a08\u7b97\u3002\u5b83\u80fd\u5e6b\u52a9\u6295\u8cc7\u8005\u5224\u65b7\u80a1\u7968\u7684\u50f9\u683c\u662f\u5426\u8655\u65bc\u5408\u7406\u7bc4\u570d\uff0c\u4e26\u6c7a\u5b9a\u4f55\u6642\u9032\u884c\u8cb7\u5165\u6216\u8ce3\u51fa\u64cd\u4f5c\u3002\u6b64\u6307\u6a19\u901a\u5e38\u820720\u65e5\u79fb\u52d5\u5e73\u5747\u7dda\u7d50\u5408\u4f7f\u7528\uff0c\u63d0\u4f9b\u66f4\u6e96\u78ba\u7684\u5e02\u5834\u5165\u5834\u548c\u9000\u51fa\u4fe1\u865f\u3002<\/p>\n<h2>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u7684\u4f7f\u7528\u6642\u6a5f<\/h2>\n<p>\u4f7f\u7528\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u6642\uff0c\u6295\u8cc7\u8005\u9700\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u500b\u95dc\u9375\u9ede\uff1a<br \/>\n&#8211; \u7576\u80a1\u7968\u7684\u5e02\u503c\u6bd4\u7387\u8d85\u904e\u4e0a\u9650\u6642\uff0c\u901a\u5e38\u610f\u5473\u8457\u80a1\u7968\u50f9\u683c\u904e\u9ad8\uff0c\u61c9\u8003\u616e\u8ce3\u51fa\u3002<br \/>\n&#8211; \u7576\u5e02\u503c\u6bd4\u7387\u4f4e\u65bc\u4e0b\u9650\u6642\uff0c\u5247\u986f\u793a\u80a1\u7968\u50f9\u683c\u904e\u4f4e\uff0c\u53ef\u80fd\u662f\u8cb7\u5165\u7684\u597d\u6642\u6a5f\u3002<br \/>\n&#8211; \u89c0\u5bdf\u5e02\u503c\u6bd4\u7387\u7684\u6ce2\u52d5\u53ef\u4ee5\u5e6b\u52a9\u6295\u8cc7\u8005\u66f4\u597d\u5730\u628a\u63e1\u5e02\u5834\u52d5\u614b\u3002<\/p>\n<h2>Python\u7bc4\u4f8b\uff1a\u8a08\u7b97\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u8a08\u7b97\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u7684\u5be6\u4f5c\u7bc4\u4f8b\uff0c\u5305\u542b\u6578\u64da\u8b80\u53d6\u3001\u8a08\u7b97\u5e02\u503c\u6bd4\u7387\u8207\u7e6a\u88fd\u5716\u8868\u7684\u5b8c\u6574\u6b65\u9a5f\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u8f09\u5165\u6240\u9700\u7684\u51fd\u5f0f\u5eab<br \/>\nimport pandas as pd<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<\/p>\n<p># \u8b80\u53d6\u80a1\u7968\u8cc7\u6599<br \/>\ndf = pd.read_csv(&#8216;stock_data.csv&#8217;)<\/p>\n<p># \u8a08\u7b9720\u65e5\u79fb\u52d5\u5e73\u5747<br \/>\ndf[&#8217;20ma&#8217;] = df[&#8216;Close&#8217;].rolling(window=20).mean()<\/p>\n<p># \u8a08\u7b97\u5e02\u503c\u6bd4<br \/>\ndf[&#8216;mkt_ratio&#8217;] = df[&#8216;Close&#8217;] \/ df[&#8217;20ma&#8217;]\n<p># \u8a08\u7b97\u5e02\u503c\u6bd4\u901a\u9053<br \/>\ndf[&#8216;upper_channel&#8217;] = df[&#8216;mkt_ratio&#8217;] + 0.1<br \/>\ndf[&#8216;lower_channel&#8217;] = df[&#8216;mkt_ratio&#8217;] &#8211; 0.1<\/p>\n<p># \u7e6a\u88fd\u5716\u8868<br \/>\nplt.figure(figsize=(12, 6))<br \/>\nplt.plot(df[&#8216;Date&#8217;], df[&#8216;mkt_ratio&#8217;], label=&#8217;Market Ratio&#8217;, color=&#8217;blue&#8217;)<br \/>\nplt.plot(df[&#8216;Date&#8217;], df[&#8216;upper_channel&#8217;], label=&#8217;Upper Channel&#8217;, color=&#8217;red&#8217;, linestyle=&#8217;&#8211;&#8216;)<br \/>\nplt.plot(df[&#8216;Date&#8217;], df[&#8216;lower_channel&#8217;], label=&#8217;Lower Channel&#8217;, color=&#8217;green&#8217;, linestyle=&#8217;&#8211;&#8216;)<br \/>\nplt.title(&#8216;\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u5206\u6790&#8217;)<br \/>\nplt.xlabel(&#8216;\u65e5\u671f&#8217;)<br \/>\nplt.ylabel(&#8216;\u5e02\u503c\u6bd4&#8217;)<br \/>\nplt.legend()<br \/>\nplt.xticks(rotation=45)<br \/>\nplt.tight_layout()<br \/>\nplt.show()<br \/>\n&#8220;`<\/p>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u5c07\u8b80\u53d6\u80a1\u7968\u6578\u64da\uff0c\u8a08\u7b97\u5e02\u503c\u6bd4\u901a\u9053\uff0c\u4e26\u7e6a\u88fd\u51fa\u6e05\u6670\u7684\u5716\u8868\uff0c\u5e6b\u52a9\u6295\u8cc7\u8005\u76f4\u89c0\u5730\u4e86\u89e3\u80a1\u7968\u50f9\u683c\u7684\u8b8a\u5316\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u57f7\u884c\u4e0a\u8ff0\u7a0b\u5f0f\u78bc\u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e38\u898b\u932f\u8aa4\uff1a<br \/>\n&#8211; **\u6a94\u6848\u672a\u627e\u5230**\uff1a\u78ba\u4fdd`stock_data.csv`\u6587\u4ef6\u5b58\u5728\u65bc\u6b63\u78ba\u7684\u8def\u5f91\u4e2d\u3002<br \/>\n&#8211; **NaN\u503c**\uff1a\u5728\u8a08\u7b97\u79fb\u52d5\u5e73\u5747\u6642\uff0c\u524d\u5e7e\u500b\u503c\u6703\u662fNaN\uff0c\u9019\u662f\u6b63\u5e38\u7684\uff0c\u9700\u8981\u6ce8\u610f\u6578\u64da\u7684\u5b8c\u6574\u6027\u3002<br \/>\n&#8211; **\u5716\u8868\u986f\u793a\u554f\u984c**\uff1a\u78ba\u4fdd\u5b89\u88dd\u4e86`matplotlib`\u5eab\u4e26\u6b63\u78ba\u4f7f\u7528`plt.show()`\u4f86\u986f\u793a\u5716\u8868\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u4e0d\u50c5\u9069\u7528\u65bc\u55ae\u4e00\u80a1\u7968\uff0c\u4e5f\u53ef\u4ee5\u61c9\u7528\u65bc\u80a1\u7968\u7d44\u5408\u7684\u5206\u6790\uff0c\u5e6b\u52a9\u6295\u8cc7\u8005\u591a\u6a23\u5316\u6295\u8cc7\u7b56\u7565\u3002\u6b64\u5916\uff0c\u5c07\u6b64\u6307\u6a19\u8207\u5176\u4ed6\u6280\u8853\u6307\u6a19\u7d50\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u63d0\u5347\u4ea4\u6613\u7b56\u7565\u7684\u6709\u6548\u6027\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3Python\u5728\u91d1\u878d\u5206\u6790\u4e2d\u7684\u61c9\u7528\uff0c\u5efa\u8b70\u53c3\u8003[\u9019\u7bc7\u6559\u5b78\u6587\u7ae0](https:\/\/vocus.cc\/article\/5f4b4c8d4c0e2e001cd8cb9f)\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u662f\u4e00\u7a2e\u5e38\u7528\u7684\u4ea4\u6613\u6307\u6a19\uff0c\u53ef\u4ee5\u5e6b\u52a9\u6295\u8cc7\u8005\u66f4\u597d\u5730\u5224\u65b7\u80a1\u7968\u7684\u50f9\u683c\u8d70\u52e2\uff0c\u4e26\u63d0\u4f9b\u66f4\u591a\u7684\u4ea4\u6613\u6a5f\u6703\u3002\u672c\u6587\u4ecb\u7d39\u4e86\u6b64\u6307\u6a19\u7684\u4f7f\u7528\u6642\u6a5f\u53ca\u5b8c\u6574\u7684Python\u7bc4\u4f8b\uff0c\u8b93\u6295\u8cc7\u8005\u80fd\u5920\u66f4\u597d\u5730\u5236\u5b9a\u6295\u8cc7\u6c7a\u7b56\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: \u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u7684\u8a08\u7b97\u516c\u5f0f\u662f\u4ec0\u9ebc\uff1f**<br \/>\nA1: \u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u7684\u8a08\u7b97\u516c\u5f0f\u70ba\uff1a\u5e02\u503c\u6bd4 = \u80a1\u7968\u7576\u524d\u50f9\u683c \/ 20\u65e5\u79fb\u52d5\u5e73\u5747\u50f9\u683c\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u9078\u64c7\u5408\u9069\u7684\u4e0a\u4e0b\u9650\u503c\uff1f**<br \/>\nA2: \u4e0a\u4e0b\u9650\u503c\u901a\u5e38\u53ef\u6839\u64da\u6b77\u53f2\u6578\u64da\u6ce2\u52d5\u9032\u884c\u8abf\u6574\uff0c\u5efa\u8b70\u9032\u884c\u56de\u6e2c\u4ee5\u78ba\u5b9a\u6700\u5408\u9069\u7684\u7bc4\u570d\u3002<\/p>\n<p>**Q3: \u6b64\u6307\u6a19\u662f\u5426\u9069\u5408\u6240\u6709\u985e\u578b\u7684\u80a1\u7968\uff1f**<br \/>\nA3: \u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\u9069\u5408\u591a\u6578\u80a1\u7968\uff0c\u4f46\u5728\u9ad8\u5ea6\u6ce2\u52d5\u6216\u6d41\u52d5\u6027\u4e0d\u8db3\u7684\u5e02\u5834\u4e2d\uff0c\u9700\u8b39\u614e\u4f7f\u7528\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053(Stock-to-MarketRatioChannel)\u662f\u4e00\u7a2e\u4ea4\u6613\u6307\u6a19\uff0c\u53ef\u4ee5\u5e6b\u52a9\u6295\u8cc7\u8005\u66f4\u597d\u5730\u5206\u6790\u80a1\u7968\u5e02\u5834\uff0c\u4e26\u63d0\u4f9b\u6295\u8cc7\u8005\u66f4\u591a\u7684\u4ea4\u6613\u6a5f\u6703\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Python\u4f86\u5206\u6790\u80a1\u7968\u5e02\u503c\u6bd4\u901a\u9053\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u5b83\u4f86\u66f4\u597d\u5730\u4ea4\u6613\u80a1\u7968\u3002<\/p>\n","protected":false},"author":1,"featured_media":2518,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,189],"tags":[15,188],"class_list":["post-6222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-189","tag-python","tag-188"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2022\/12\/DALL\u00b7E-2022-12-28-14.25.55-\u62f7\u8c9d2.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Cm","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6222"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6222\/revisions"}],"predecessor-version":[{"id":12743,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6222\/revisions\/12743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/2518"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}