{"id":1720,"date":"2024-12-17T07:37:00","date_gmt":"2024-12-16T23:37:00","guid":{"rendered":"https:\/\/blog.laoyulaoyu.top\/?p=1720"},"modified":"2024-11-23T19:25:48","modified_gmt":"2024-11-23T11:25:48","slug":"%e4%b8%80%e6%ad%a5%e6%ad%a5%e6%95%99%e4%bd%a0%e8%bd%bb%e6%9d%be%e6%89%93%e9%80%a0%e7%a7%81%e4%ba%ba%e4%b8%93%e5%b1%9e%e7%9a%84%e5%a4%96%e6%b1%87%e4%ba%a4%e6%98%93%e6%9c%ba%e5%99%a8%e4%ba%ba","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2024\/12\/17\/%e4%b8%80%e6%ad%a5%e6%ad%a5%e6%95%99%e4%bd%a0%e8%bd%bb%e6%9d%be%e6%89%93%e9%80%a0%e7%a7%81%e4%ba%ba%e4%b8%93%e5%b1%9e%e7%9a%84%e5%a4%96%e6%b1%87%e4%ba%a4%e6%98%93%e6%9c%ba%e5%99%a8%e4%ba%ba\/","title":{"rendered":"\u4e00\u6b65\u6b65\u6559\u4f60\u8f7b\u677e\u6253\u9020\u79c1\u4eba\u4e13\u5c5e\u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba"},"content":{"rendered":"\n<p>\u4f5c\u8005\uff1a<a href=\"https:\/\/www.laoyulaoyu.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8001\u4f59\u635e\u9c7c<\/a><\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/111901.png\" alt=\"\" class=\"wp-image-3074\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-verse\"><strong>\u5199\u5728\u524d\u9762\u7684\u8bdd\uff1a<\/strong>\u6bcf\u5929\u5728\u65b0\u95fb\u4e2d\u770b\u5230\u4eba\u6c11\u5e01\u5bf9\u7f8e\u5143\u6c47\u7387\u7684\u8dcc\u5b95\u8d77\u4f0f\uff0c\u662f\u5426\u4f1a\u8ba9\u4f60\u5bf9\u5916\u6c47\u4ea4\u6613\u7684\u4e16\u754c\u5145\u6ee1\u597d\u5947\uff0c\u540c\u65f6\u53c8\u5e0c\u671b\u80fd\u627e\u5230\u4e00\u79cd\u66f4\u9ad8\u6548\u3001\u66f4\u7701\u529b\u7684\u4ea4\u6613\u65b9\u5f0f\uff1f\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u6211\u5c06\u5e26\u4f60\u8d70\u8fdb\u81ea\u52a8\u5316\u4ea4\u6613\u7684\u795e\u79d8\u9886\u57df\uff0c\u63ed\u793a\u5982\u4f55\u5229\u7528\u5148\u8fdb\u7684\u6280\u672f\u6253\u9020\u5c5e\u4e8e\u81ea\u5df1\u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u3002<\/mark>\u65e0\u9700\u62c5\u5fc3\u7f16\u7a0b\u96be\u9898\uff0c\u6211\u5c06\u4ee5\u901a\u4fd7\u6613\u61c2\u7684\u65b9\u5f0f\uff0c\u9010\u6b65\u6307\u5bfc\u4f60\u5b8c\u6210\u6574\u4e2a\u8fc7\u7a0b\u3002\u4ece\u7b56\u7565\u9009\u62e9\u5230\u98ce\u9669\u63a7\u5236\uff0c\u6bcf\u4e00\u6b65\u90fd\u662f\u4e3a\u4e86\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u5e76\u5e94\u7528\u81ea\u52a8\u5316\u4ea4\u6613\u3002\u65e0\u8bba\u4f60\u7684\u80cc\u666f\u5982\u4f55\uff0c\u8fd9\u91cc\u90fd\u6709\u9002\u5408\u4f60\u7684\u77e5\u8bc6\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u8fc8\u5411\u667a\u80fd\u4ea4\u6613\u7684\u65b0\u5f81\u7a0b\u3002<\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\uff1f<\/strong><\/h2>\n\n\n\n<p>\u5728\u4eba\u5de5\u667a\u80fd\u65f6\u4ee3\uff0c\u81ea\u52a8\u4ea4\u6613\u5df2\u6210\u4e3a\u6295\u8d44\u8005\u4f18\u5316\u5916\u6c47\u5e02\u573a\u64cd\u4f5c\u7684\u6709\u529b\u5de5\u5177\u3002\u4ea4\u6613\u673a\u5668\u4eba\u53ef\u4ee5\u6839\u636e\u9884\u5b9a\u4e49\u7684\u53c2\u6570\u81ea\u52a8\u6267\u884c\u4ea4\u6613\uff0c\u8ba9\u4ea4\u6613\u8005\u53ef\u4ee5\u6bcf\u5929 24 \u5c0f\u65f6\u5728\u91d1\u878d\u5e02\u573a\u4e0a\u64cd\u4f5c\u3002\u5728\u6df1\u5165\u4e86\u89e3\u6280\u672f\u6d41\u7a0b\u4e4b\u524d\uff0c\u6709\u5fc5\u8981\u5148\u4e86\u89e3\u4e00\u4e0b\u4e3a\u4ec0\u4e48\u4ea4\u6613\u673a\u5668\u4eba\u5728\u5916\u6c47\u4e16\u754c\u4e2d\u5982\u6b64\u53d7\u91cd\u89c6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-119.png\" alt=\"\" class=\"wp-image-3075\"\/><\/figure>\n\n\n\n<p>\u521b\u5efa\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u4e0d\u4ec5\u80fd\u591f\u63d0\u9ad8\u4ea4\u6613\u6548\u7387\uff0c\u51cf\u5c11\u60c5\u7eea\u5e72\u6270\uff0c\u8fd8\u80fd\u5b9e\u73b024\u5c0f\u65f6\u4e0d\u95f4\u65ad\u4ea4\u6613\u3002\u901a\u8fc7\u56de\u6d4b\u4e0e\u4f18\u5316\uff0c\u4ea4\u6613\u8005\u53ef\u4ee5\u4e0d\u65ad\u6539\u8fdb\u81ea\u5df1\u7684\u4ea4\u6613\u7b56\u7565\uff0c\u4ece\u800c\u5728\u7ade\u4e89\u6fc0\u70c8\u7684\u5916\u6c47\u5e02\u573a\u4e2d\u5360\u636e\u4f18\u52bf\u3002\u968f\u7740\u6280\u672f\u7684\u4e0d\u65ad\u8fdb\u6b65\uff0c\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u5c06\u6210\u4e3a\u8d8a\u6765\u8d8a\u591a\u4ea4\u6613\u8005\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u521b\u5efa\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u7684\u4e94\u4e2a\u5fc5\u8981\u6b65\u9aa4<\/strong><\/h2>\n\n\n\n<p id=\"739b\">\u4e0b\u9762\u5c06\u9010\u6b65\u4ecb\u7ecd\u5982\u4f55\u7528 Python \u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6b65\u9aa4\u4e00\uff1a\u5b89\u88c5\u5fc5\u8981\u7684\u5de5\u5177<\/strong><\/h3>\n\n\n\n<p>\u6280\u672f\u4e0a\u6211\u4eec\u4f1a\u4f7f\u7528 Python\u6765\u5b9e\u73b0\uff0c\u5148\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\uff0c\u6bd4\u5982\u7528\u4e8e\u83b7\u53d6\u5e02\u573a\u6570\u636e\u7684 yfinance\uff0c\u63a5\u7740\u8fd8\u4f1a\u5b89\u88c5\u4ea4\u6613\u5546\u5e73\u53f0\u4e0e\u5176\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\u4ea4\u4e92\u6240\u9700\u7684\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1e36\"><strong><strong>\u6b65\u9aa4\u4e8c\uff1a<\/strong>\u786e\u5b9a\u4ea4\u6613\u7b56\u7565<\/strong><\/h3>\n\n\n\n<p>\u8fd9\u91cc\u4f1a\u9009\u62e9\u4e00\u79cd\u5e38\u7528\u7684\u7b56\u7565\u6765\u4e3e\u4f8b\uff0c\u8fd9\u5c31\u662f\u7b80\u5355\u79fb\u52a8\u5e73\u5747\u7ebf (SMA) \u4ea4\u53c9\uff0c\u901a\u8fc7\u6bd4\u8f83\u4e24\u4e2a SMA\uff08\u77ed\u671f\u548c\u957f\u671f\uff09\u6765\u751f\u6210\u4e70\u5165\u6216\u5356\u51fa\u4fe1\u53f7\u3002\u4f8b\u5982\uff1a\u5982\u679c 20 \u5206\u949f\u5747\u7ebf\u7a7f\u8fc7 50 \u5206\u949f\u5747\u7ebf\uff0c\u5c31\u4f1a\u4ea7\u751f\u4e70\u5165\u4fe1\u53f7\u3002\u540e\u671f\u4f60\u4eec\u53ef\u4ee5\u81ea\u5df1\u6dfb\u52a0\u6216\u8c03\u6574\u7b56\u7565\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b23b\"><strong><strong>\u6b65\u9aa4\u4e09\uff1a<\/strong>\u83b7\u53d6\u5e02\u573a\u6570\u636e<\/strong><\/h3>\n\n\n\n<p>\u8bbe\u7f6e\u4f60\u7684\u673a\u5668\u4eba\uff0c\u4ece\u53ef\u9760\u7684\u6765\u6e90\uff08\u5982\u96c5\u864e\u8d22\u7ecf API\uff09\u6216\u4f60\u7684\u4ea4\u6613\u5e73\u53f0\u90a3\u91cc\u83b7\u53d6\u5b9e\u65f6\u5e02\u573a\u6570\u636e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8994\"><strong>\u6b65\u9aa4\u56db\uff1a\u5b9e\u65bd\u4ea4\u6613\u903b\u8f91<\/strong><\/h3>\n\n\n\n<p>\u914d\u7f6e\u673a\u5668\u4eba\uff0c\u6839\u636e\u4ea4\u6613\u7b56\u7565\u751f\u6210\u7684\u4fe1\u53f7\u6267\u884c\u4e70\u5165\u6216\u5356\u51fa\u4ea4\u6613\u3002\u5e76\u5728\u5c06\u8fd9\u4e9b\u4ea4\u6613\u5e94\u7528\u4e8e\u5b9e\u9645\u73af\u5883\u4e4b\u524d\uff0c\u5148\u6a21\u62df\u8fd9\u4e9b\u4ea4\u6613\u4ee5\u9a8c\u8bc1\u5176\u6709\u6548\u6027\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"880d\"><strong>\u6b65\u9aa4\u4e94\uff1a\u6d4b\u8bd5\u548c\u4f18\u5316<\/strong><\/h3>\n\n\n\n<p>\u5229\u7528\u5386\u53f2\u6570\u636e\u8fdb\u884c\u6a21\u62df\uff08\u56de\u6eaf\u6d4b\u8bd5\uff09\uff0c\u8bc4\u4f30\u7b56\u7565\u7684\u6027\u80fd\u3002\u6839\u636e\u7ed3\u679c\u8c03\u6574\u53c2\u6570\uff0c\u4f18\u5316\u7b56\u7565\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u4ee3\u7801\u5b9e\u73b0<\/strong><\/h2>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Python \u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u793a\u4f8b\uff0c\u5b83\u57fa\u4e8e\u7b80\u5355\u79fb\u52a8\u5e73\u5747\u7ebf\uff08SMA\uff09\u4ea4\u53c9\u7b56\u7565\u3002\u5728\u4ee3\u7801\u4e0b\u65b9\uff0c\u6211\u5c06\u8be6\u7ec6\u89e3\u91ca\u6bcf\u4e2a\u90e8\u5206\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\n\nimport datetime as dt\nimport time\n\n# Initial Setup\ninitial_balance = 10000  # Initial balance in USD\nbalance = initial_balance\nposition = 0  # Number of euros held\nforex_pair = 'EURUSD=X'  # Forex pair to trade\nshort_window = 20  # Short window for SMA (in minutes)\nlong_window = 50  # Long window for SMA (in minutes)\n\nwhile True:\n    try:\n        # Fetching market data\n        data = yf.download(forex_pair, period='1d', interval='1m', progress=False)\n        \n        # Calculating the SMAs\n        sma_short = data&#91;'Close'].rolling(window=short_window).mean()\n        sma_long = data&#91;'Close'].rolling(window=long_window).mean()\n        \n        # Latest SMA and close values\n        latest_entry = data.iloc&#91;-1]\n        current_price = latest_entry&#91;'Close']\n        sma_short_last = sma_short.iloc&#91;-1]\n        sma_long_last = sma_long.iloc&#91;-1]\n\n        # Trading strategy\n        if sma_short_last &gt; sma_long_last and position == 0:\n            # Buy signal\n            units_to_buy = balance \/\/ current_price\n            balance -= units_to_buy * current_price\n            position += units_to_buy\n            print(f\"Bought {units_to_buy} EUR at {current_price:.4f} USD per unit.\")\n\n        elif sma_short_last &lt; sma_long_last and position &gt; 0:\n            # Sell signal\n            balance += position * current_price\n            print(f\"Sold {position} EUR at {current_price:.4f} USD per unit.\")\n            position = 0\n        \n        # Display current status\n        print(f\"Holding {position} EUR at {current_price:.4f} USD per unit.\")\n\n        # Wait for 60 seconds before the next iteration\n        time.sleep(60)\n\n    except KeyboardInterrupt:\n        print(\"Trading bot stopped by user.\")\n        break\n\n# Final balance calculation\nfinal_balance = balance + position * current_price\nprint(f\"Final balance: {final_balance:.2f} USD\")\n\nif final_balance &gt; initial_balance:\n    print(f\"The balance increased by {((final_balance \/ initial_balance - 1) * 100):.2f}%\")\nelif final_balance &lt; initial_balance:\n    print(f\"The balance decreased by {((1 - final_balance \/ initial_balance) * 100)::.2f}%\")\nelse:\n    print(\"The balance did not change.\")<\/code><\/pre>\n\n\n\n<p>\u673a\u5668\u4eba\u6b63\u5e38\u8fd0\u884c\u7684\u7ed3\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-120.png\" alt=\"\" class=\"wp-image-3076\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><br><strong>3.1 \u6570\u636e\u5165\u5e93<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>yfinance<\/code>\uff1a\u7528\u4e8e\u83b7\u53d6\u5e02\u573a\u6570\u636e\uff0c\u7279\u522b\u662f\u6b27\u5143\/\u7f8e\u5143\u8d27\u5e01\u5bf9\u7684\u6570\u636e\u3002\uff08\u540e\u671f\u4f60\u4e5f\u53ef\u4ee5\u6539\u6210\u5176\u4ed6\u8d27\u5e01\u5bf9\uff09<\/li>\n\n\n\n<li><code>datetime<\/code>&nbsp;and&nbsp;<code>time<\/code>\u65e5\u671f\u548c\u65f6\u95f4\u7528\u4e8e\u5904\u7406\u65e5\u671f\u548c\u63a7\u5236\u8fed\u4ee3\u4e4b\u95f4\u7684\u7b49\u5f85\u65f6\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"262b\"><strong>3.2 \u521d\u59cb\u8bbe\u7f6e<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>initial_balance<\/code>\uff1a\u5b9a\u4e49\u673a\u5668\u4eba\u7684\u8d77\u59cb\u4f59\u989d\uff08\u672c\u4f8b\u4e2d\u4e3a 10,000 \u7f8e\u5143\uff09\u3002<\/li>\n\n\n\n<li><code>balance<\/code>\uff1a\u4f59\u989d\u4fdd\u5b58\u5f53\u524d\u4f59\u989d\u7684\u53d8\u91cf\uff0c\u6bcf\u6b21\u4ea4\u6613\u540e\u90fd\u4f1a\u66f4\u65b0\u3002<\/li>\n\n\n\n<li><code>position<\/code>: \u5934\u5bf8-\u4ee3\u8868\u673a\u5668\u4eba\u5728\u4efb\u4f55\u7ed9\u5b9a\u65f6\u95f4\u5185\u6301\u6709\u7684\u6b27\u5143\u6570\u91cf\u3002\u4ece 0 \u5f00\u59cb\u3002<\/li>\n\n\n\n<li><code>forex_pair<\/code>\uff1a\u5b9a\u4e49\u8981\u4ea4\u6613\u7684\u8d27\u5e01\u5bf9\uff0c\u672c\u4f8b\u4e2d\u4e3a EUR\/USD\u3002<\/li>\n\n\n\n<li><code>short_window<\/code>&nbsp;and&nbsp;<code>long_window<\/code>\uff1a\u8fd9\u4e9b\u53d8\u91cf\u5b9a\u4e49\u4e86\u7528\u4e8e\u77ed\u671f\u548c\u957f\u671f\u4ea4\u6613\u7684\u7b80\u5355\u79fb\u52a8\u5e73\u5747\u7ebf (SMA) \u7684\u65f6\u95f4\u7a97\u53e3\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"c5e7\"><strong>3.3 \u4e3b\u73af\u8def\u8bf4\u660e<\/strong><\/h3>\n\n\n\n<p><strong>\u4ea4\u6613\u7b56\u7565\u5982\u4e0b<\/strong>\uff1a<\/p>\n\n\n\n<p><strong>1. \u4e70\u5165\u4fe1\u53f7\uff1a<\/strong>\u5982\u679c\u77ed\u671f\u5747\u7ebf\uff0820 \u5206\u949f\uff09\u8d8a\u8fc7\u957f\u671f\u5747\u7ebf\uff0850 \u5206\u949f\uff09\uff0c\u4e14\u673a\u5668\u4eba\u76ee\u524d\u672a\u6301\u6709\u5934\u5bf8\uff0c\u5373\u5934\u5bf8 ==0(i.e.,&nbsp;<code>position == 0<\/code>),\uff0c\u673a\u5668\u4eba\u5c06\u6267\u884c\u4e70\u5165\u6307\u4ee4\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8d2d\u4e70\u5355\u4f4d\uff08euros\uff09\u7684\u6570\u91cf\u662f\u7528\u5f53\u524d\u4f59\u989d\u9664\u4ee5\u6700\u65b0\u6536\u76d8\u4ef7\uff08<code>current_price<\/code>\uff09\u8ba1\u7b97\u5f97\u51fa\u7684\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u673a\u5668\u4eba\u5c3d\u53ef\u80fd\u591a\u5730\u6295\u8d44\u53ef\u7528\u4f59\u989d\u3002<\/li>\n\n\n\n<li>\u7136\u540e\uff0c\u4f59\u989d\uff08<code>balance<\/code>\uff09\u51cf\u53bb\u6b27\u5143\u652f\u51fa\u603b\u989d\uff0c\u5934\u5bf8\uff08<code>position<\/code>\uff09\u4e5f\u968f\u4e4b\u66f4\u65b0\uff0c\u4ee5\u53cd\u6620\u65b0\u7684\u6b27\u5143\u6301\u6709\u91cf\u3002<\/li>\n\n\n\n<li>\u63a7\u5236\u53f0\u5c06\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u8bf4\u660e\u8d2d\u4e70\u4e86\u591a\u5c11\u6b27\u5143\u4ee5\u53ca\u4ef7\u683c\u662f\u591a\u5c11\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>2. \u5356\u51fa\u4fe1\u53f7\uff1a<\/strong>\u76f8\u53cd\uff0c\u5982\u679c\u77ed\u671f\u5747\u7ebf\u7a7f\u8fc7\u957f\u671f\u5747\u7ebf\u4e0b\u65b9\uff0c\u4e14\u673a\u5668\u4eba\u6301\u6709\u6b27\u5143\uff0c\u5373\u4ed3\u4f4d\u5927\u4e8e 0(i.e.,&nbsp;<code>position &gt; 0<\/code>)\uff0c\u673a\u5668\u4eba\u5c06\u6267\u884c\u5356\u51fa\u6307\u4ee4\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f59\u989d\uff08<code>balance<\/code>\uff09\u589e\u52a0\u4e86\u6309\u5f53\u524d\u4ef7\u683c\u51fa\u552e\u6b27\u5143\u6240\u5f97\u7684\u91d1\u989d\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e\u6240\u6709\u6b27\u5143\u90fd\u5df2\u552e\u51fa\uff0c\u5934\u5bf8\uff08<code>position<\/code>\uff09\u91cd\u7f6e\u4e3a\u96f6\u3002<\/li>\n\n\n\n<li>\u63a7\u5236\u53f0\u5c06\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u8bf4\u660e\u552e\u51fa\u4e86\u591a\u5c11\u6b27\u5143\u4ee5\u53ca\u4ef7\u683c\u662f\u591a\u5c11\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>3. \u663e\u793a\u5f53\u524d\u72b6\u6001\uff1a<\/strong>\u6bcf\u6b21\u8fed\u4ee3\u540e\uff0c\u673a\u5668\u4eba\u90fd\u4f1a\u6253\u5370\u5f53\u524d\u72b6\u6001\uff0c\u663e\u793a\u5b83\u6301\u6709\u591a\u5c11\u6b27\u5143\u4ee5\u53ca\u5f53\u524d\u6bcf\u6b27\u5143\u7684\u7f8e\u5143\u4ef7\u683c\u3002\u8fd9\u6709\u52a9\u4e8e\u5b9e\u65f6\u8ddf\u8e2a\u673a\u5668\u4eba\u7684\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n\n\n\n<p><strong>4. \u7b49\u5f85 60 \u79d2\uff1a<\/strong>\u7136\u540e\uff0c\u673a\u5668\u4eba\u6682\u505c 60 \u79d2\uff0c\u518d\u83b7\u53d6\u4e0b\u4e00\u7ec4\u6570\u636e\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u673a\u5668\u4eba\u6309\u5206\u949f\u8fd0\u884c\uff0c\u4e0e\u6570\u636e\u9891\u7387\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2475\"><strong>3.4 \u4e2d\u65ad\u5904\u7406<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c\u7528\u6237\u624b\u52a8\u505c\u6b62\u673a\u5668\u4eba\uff08\u6309\u4e0b Ctrl+C \u7b49\u7ec4\u5408\u952e\uff09\uff0c\u5219\u4f1a\u6355\u83b7 <code>KeyboardInterrupt<\/code>\u5f02\u5e38\uff0c\u5e76\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u8bf4\u660e\u4ea4\u6613\u673a\u5668\u4eba\u5df2\u88ab\u7528\u6237\u505c\u6b62\u3002\u7136\u540e\u5faa\u73af\u4e2d\u65ad\uff0c\u673a\u5668\u4eba\u505c\u6b62\u8fd0\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2534\"><strong>3.5 \u6700\u7ec8\u4f59\u989d\u8ba1\u7b97<\/strong><\/h3>\n\n\n\n<p>\u4e00\u65e6\u673a\u5668\u4eba\u505c\u6b62\u8fd0\u884c\uff0c\u5b83\u5c31\u4f1a\u8ba1\u7b97\u6700\u7ec8\u4f59\u989d\uff0c\u5e76\u5c06\u53ef\u80fd\u4ecd\u6301\u6709\u7684\u6b27\u5143\u8ba1\u7b97\u5728\u5185\u3002\u6700\u7ec8\u4f59\u989d\u7684\u8ba1\u7b97\u65b9\u6cd5\u662f\uff1a\u5269\u4f59\u7684\u7f8e\u5143\u4f59\u989d\u52a0\u4e0a\u6309\u6700\u65b0\u4ef7\u683c\u5151\u6362\u6210\u7f8e\u5143\u7684\u6b27\u5143\u4ef7\u503c\u3002\u7136\u540e\uff0c\u673a\u5668\u4eba\u4f1a\u5c06\u6700\u7ec8\u4f59\u989d\u4e0e\u521d\u59cb\u4f59\u989d\u8fdb\u884c\u6bd4\u8f83\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6700\u7ec8\u4f59\u989d\u5927\u4e8e\u521d\u59cb\u4f59\u989d\uff0c\u5219\u4f1a\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u663e\u793a\u4f59\u989d\u589e\u52a0\u7684\u767e\u5206\u6bd4\uff1b<\/li>\n\n\n\n<li>\u5982\u679c\u6700\u7ec8\u4f59\u989d\u5c11\u4e8e\u521d\u59cb\u4f59\u989d\uff0c\u5219\u4f1a\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u663e\u793a\u4f59\u989d\u51cf\u5c11\u7684\u767e\u5206\u6bd4\uff1b<\/li>\n\n\n\n<li>\u5982\u679c\u4f59\u989d\u4fdd\u6301\u4e0d\u53d8\uff0c\u5219\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u8bf4\u660e\u4f59\u989d\u4fdd\u6301\u4e0d\u53d8\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/strong><\/h2>\n\n\n\n<p>\u672c Python \u811a\u672c\u662f\u4e00\u4e2a\u57fa\u672c\u793a\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u4f7f\u7528\u7b80\u5355\u7684\u79fb\u52a8\u5e73\u5747\u4ea4\u53c9\u7b56\u7565\u5b9e\u73b0\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\u3002\u5b83\u5c55\u793a\u4e86\u81ea\u52a8\u4ea4\u6613\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u6570\u636e\u68c0\u7d22\u3001\u7b56\u7565\u5b9e\u65bd\u548c\u5b9e\u65f6\u51b3\u7b56\u3002\u4e0d\u8fc7\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e2a\u811a\u672c\u53ea\u662f\u4e00\u4e2a\u8d77\u70b9\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-121.png\" alt=\"\" class=\"wp-image-3081\"\/><\/figure>\n<\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u56de\u6eaf\u6d4b\u8bd5\u548c\u4f18\u5316\uff1a<\/strong>\u5728\u771f\u5b9e\u4ea4\u6613\u73af\u5883\u4e2d\u4f7f\u7528\u8be5\u673a\u5668\u4eba\u4e4b\u524d\uff0c\u5fc5\u987b\u4f7f\u7528\u5386\u53f2\u6570\u636e\u5bf9\u7b56\u7565\u8fdb\u884c\u56de\u6eaf\u6d4b\u8bd5\uff0c\u4ee5\u8bc4\u4f30\u5176\u6027\u80fd\u5e76\u505a\u51fa\u5fc5\u8981\u8c03\u6574\u3002<\/li>\n\n\n\n<li><strong>\u4ea4\u6613\u6210\u672c\uff1a<\/strong>\u8be5\u811a\u672c\u6ca1\u6709\u8003\u8651\u4ea4\u6613\u8d39\u7528\u6216\u6ed1\u70b9\uff0c\u800c\u8fd9\u53ef\u80fd\u4f1a\u4e25\u91cd\u5f71\u54cd\u673a\u5668\u4eba\u7684\u76c8\u5229\u80fd\u529b\u3002\u60a8\u5e94\u4fee\u6539\u811a\u672c\uff0c\u5c06\u8fd9\u4e9b\u8d39\u7528\u5305\u62ec\u5728\u5185\u3002<\/li>\n\n\n\n<li><strong>\u98ce\u9669\u7ba1\u7406\uff1a<\/strong>\u5b9e\u65bd\u989d\u5916\u7684\u98ce\u9669\u7ba1\u7406\u6218\u7565\uff0c\u5982\u6b62\u635f\u5355\uff0c\u6709\u52a9\u4e8e\u9632\u6b62\u91cd\u5927\u635f\u5931\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"47fe\">\u8fd9\u4e2a\u673a\u5668\u4eba\u7684\u7b80\u5355\u6027\u53ef\u4ee5\u4f7f\u5176\u6210\u4e3a\u4e00\u4e2a\u5b9d\u8d35\u7684\u5b66\u4e60\u5de5\u5177\uff0c\u4f46\u540c\u65f6\u4e5f\u7a81\u51fa\u4e86\u5728\u5f00\u53d1\u548c\u90e8\u7f72\u81ea\u52a8\u4ea4\u6613\u7cfb\u7edf\u65f6\u6301\u7eed\u6539\u8fdb\u548c\u76d1\u63a7\u7684\u91cd\u8981\u6027\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e94\u3001\u89c2\u70b9\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p><br>\u6784\u5efa\u4e00\u4e2a\u57fa\u4e8ePython\u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba\uff0c\u8981\u6c42\u5177\u5907\u6df1\u5165\u7684\u5e02\u573a\u6d1e\u5bdf\u529b\u548c\u660e\u786e\u7684\u4ea4\u6613\u7b56\u7565\u3002\u81ea\u52a8\u5316\u4ea4\u6613\u7684\u4f18\u52bf\u660e\u663e\uff0c\u5305\u62ec\u4e0d\u95f4\u65ad\u7684\u5e02\u573a\u76d1\u63a7\u3001\u57fa\u4e8e\u6570\u636e\u7684\u51b3\u7b56\u5236\u5b9a\u4ee5\u53ca\u6548\u7387\u7684\u5927\u5e45\u63d0\u5347\u3002\u7136\u800c\uff0c\u6211\u4eec\u5fc5\u987b\u94ed\u8bb0\uff0c\u5c3d\u7ba1\u4ea4\u6613\u673a\u5668\u4eba\u80fd\u591f\u589e\u5f3a\u4ea4\u6613\u6548\u7387\uff0c\u4f46\u4e0e\u4e4b\u76f8\u4f34\u7684\u98ce\u9669\u4e5f\u4e0d\u5bb9\u5ffd\u89c6\u3002\u5173\u952e\u5728\u4e8e\u6301\u7eed\u5730\u5bf9\u7b56\u7565\u8fdb\u884c\u4f18\u5316\u548c\u5b66\u4e60\u3002\u901a\u8fc7\u5f00\u53d1\u4ea4\u6613\u673a\u5668\u4eba\uff0c\u4f60\u5c06\u80fd\u591f\u5728\u6fc0\u70c8\u7684\u5916\u6c47\u5e02\u573a\u4e2d\u8131\u9896\u800c\u51fa\uff0c\u83b7\u5f97\u72ec\u7279\u7684\u7ade\u4e89\u4f18\u52bf\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u81ea\u52a8\u5316\u4ea4\u6613\u7684\u4f18\u52bf<\/strong>\uff1a\u4ea4\u6613\u673a\u5668\u4eba\u80fd\u591f\u6301\u7eed\u4e0d\u65ad\u5730\u6267\u884c\u4ea4\u6613\uff0c\u51cf\u5c11\u4eba\u4e3a\u9519\u8bef\uff0c\u5e76\u4e14\u80fd\u591f\u6839\u636e\u6570\u636e\u548c\u7b97\u6cd5\u8fdb\u884c\u5ba2\u89c2\u7684\u4ea4\u6613\u51b3\u7b56\u3002<\/li>\n\n\n\n<li><strong>\u6280\u672f\u5b9e\u73b0\u7684\u91cd\u8981\u6027<\/strong>\uff1a\u4f7f\u7528 Python \u7f16\u7a0b\u8bed\u8a00\u548c\u76f8\u5173\u7684\u91d1\u878d\u6570\u636e\u83b7\u53d6\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5b9e\u73b0\u590d\u6742\u7684\u4ea4\u6613\u7b56\u7565\uff0c\u5e76\u4e14\u80fd\u591f\u5feb\u901f\u54cd\u5e94\u5e02\u573a\u53d8\u5316\u3002<\/li>\n\n\n\n<li><strong>\u7b56\u7565\u7684\u9009\u62e9\u4e0e\u6267\u884c<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u4ea4\u6613\u7b56\u7565\uff08\u5982 SMA \u4ea4\u53c9\u7b56\u7565\uff09\u5bf9\u4e8e\u4ea4\u6613\u673a\u5668\u4eba\u7684\u6210\u529f\u81f3\u5173\u91cd\u8981\uff0c\u540c\u65f6\u7b56\u7565\u7684\u6267\u884c\u9700\u8981\u7cbe\u786e\u7684\u6570\u636e\u5206\u6790\u548c\u5b9e\u65f6\u51b3\u7b56\u3002<\/li>\n\n\n\n<li><strong>\u98ce\u9669\u7ba1\u7406\u4e0e\u6301\u7eed\u4f18\u5316<\/strong>\uff1a\u5728\u5f00\u53d1\u548c\u90e8\u7f72\u4ea4\u6613\u673a\u5668\u4eba\u65f6\uff0c\u8003\u8651\u5230\u4ea4\u6613\u6210\u672c\u3001\u6ed1\u70b9\u548c\u98ce\u9669\u7ba1\u7406\u662f\u5fc5\u8981\u7684\uff0c\u6301\u7eed\u7684\u56de\u6eaf\u6d4b\u8bd5\u548c\u7b56\u7565\u4f18\u5316\u80fd\u591f\u63d0\u9ad8\u4ea4\u6613\u673a\u5668\u4eba\u7684\u8868\u73b0\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-verse\">but as Warren Buffett wisely said, \u201cRisk comes from not knowing what you\u2019re doing.\u201d Therefore, keep learning, adjusting, and refining your bot to achieve success in the world of automated trading.<br>\u4f46\u6b63\u5982\u6c83\u4f26-\u5df4\u83f2\u7279\uff08Warren Buffett\uff09\u6240\u8a00\uff0c\"\u98ce\u9669\u6765\u81ea\u4e8e\u4e0d\u77e5\u9053\u81ea\u5df1\u5728\u505a\u4ec0\u4e48\"\u3002<strong>\u56e0\u6b64\uff0c\u4e0d\u65ad\u5b66\u4e60\u3001\u8c03\u6574\u548c\u5b8c\u5584\u4f60\u7684\u673a\u5668\u4eba\uff0c\u624d\u80fd\u5728\u81ea\u52a8\u4ea4\u6613\u9886\u57df\u53d6\u5f97\u6210\u529f\u3002<\/strong><\/pre>\n<\/blockquote>\n\n\n\n<p><em>\u611f\u8c22\u60a8\u9605\u8bfb\u5230\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u7ed9\u60a8\u5e26\u6765\u65b0\u7684\u6536\u83b7\u3002\u795d\u60a8\u6295\u8d44\u987a\u5229\uff01\u5982\u679c\u5bf9\u6587\u4e2d\u7684\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\uff0c\u8bf7\u7ed9\u6211\u7559\u8a00\uff0c\u5fc5\u590d\u3002<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\" id=\"a1c6\">\u672c\u6587\u5185\u5bb9\u4ec5\u9650\u6280\u672f\u63a2\u8ba8\u548c\u5b66\u4e60\uff0c\u4e0d\u6784\u6210\u4efb\u4f55\u6295\u8d44\u5efa\u8bae\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u8001\u4f59\u635e\u9c7c \u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/laoyulaoyu.com\/index.php\/2024\/12\/17\/%e4%b8%80%e6%ad%a5%e6%ad%a5%e6%95%99%e4%bd%a0%e8%bd%bb%e6%9d%be%e6%89%93%e9%80%a0%e7%a7%81%e4%ba%ba%e4%b8%93%e5%b1%9e%e7%9a%84%e5%a4%96%e6%b1%87%e4%ba%a4%e6%98%93%e6%9c%ba%e5%99%a8%e4%ba%ba\/\">Continue reading<span class=\"screen-reader-text\">\u4e00\u6b65\u6b65\u6559\u4f60\u8f7b\u677e\u6253\u9020\u79c1\u4eba\u4e13\u5c5e\u7684\u5916\u6c47\u4ea4\u6613\u673a\u5668\u4eba<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[4,5],"class_list":{"0":"post-1720","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-aiinvest","7":"tag-ai","9":"entry"},"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=1720"}],"version-history":[{"count":1,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1720\/revisions"}],"predecessor-version":[{"id":1721,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1720\/revisions\/1721"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=1720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=1720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=1720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}