{"id":566,"date":"2025-07-29T23:48:04","date_gmt":"2025-07-29T15:48:04","guid":{"rendered":"https:\/\/khsci.com\/khQuant\/?page_id=566"},"modified":"2026-03-01T15:13:43","modified_gmt":"2026-03-01T07:13:43","slug":"chapter13","status":"publish","type":"page","link":"https:\/\/khsci.com\/khQuant\/chapter13\/","title":{"rendered":"3.2 \u7b56\u7565\u5de5\u5177\u7bb1\uff1a\u5e38\u7528\u51fd\u6570\u4e0e\u6280\u5de7"},"content":{"rendered":"<p>\u4e3a\u4e86\u8ba9\u7b56\u7565\u7f16\u5199\u66f4\u52a0\u9ad8\u6548\u548c\u4fbf\u6377\uff0c\u770b\u6d77\u91cf\u5316\uff08KHQuant\uff09\u63d0\u4f9b\u4e86\u4e00\u5957\u4e30\u5bcc\u7684\u5185\u7f6e\u51fd\u6570\u5de5\u5177\u7bb1\u3002\u8fd9\u4e9b\u5de5\u5177\u51fd\u6570\u5c01\u88c5\u4e86\u5e38\u89c1\u7684\u91cd\u590d\u6027\u4efb\u52a1\uff0c\u4f8b\u5982\u65f6\u95f4\u5224\u65ad\u3001\u6570\u636e\u67e5\u8be2\u3001\u4ea4\u6613\u8ba1\u7b97\u3001\u6307\u6807\u5206\u6790\u7b49\uff0c\u4f7f\u60a8\u53ef\u4ee5\u5c06\u66f4\u591a\u7cbe\u529b\u805a\u7126\u4e8e\u7b56\u7565\u903b\u8f91\u672c\u8eab\uff0c\u800c\u4e0d\u662f\u5e95\u5c42\u7684\u5b9e\u73b0\u7ec6\u8282\u3002<\/p>\n<p>\u672c\u7ae0\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u5de5\u5177\u51fd\u6570\u3002<strong>\u60a8\u65e0\u9700\u5173\u5fc3\u5b83\u4eec\u6765\u81ea\u54ea\u4e2a\u5177\u4f53\u7684\u5185\u90e8\u6a21\u5757\uff0c\u53ea\u9700\u77e5\u9053\u53ef\u4ee5\u901a\u8fc7 <code>from khQuantImport import *<\/code> \u8fd9\u4e00\u884c\u7b80\u5355\u7684\u4ee3\u7801\uff0c\u5c06\u5b83\u4eec\u5168\u90e8\u5bfc\u5165\u5230\u60a8\u7684\u7b56\u7565\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u4fbf\u53ef\u76f4\u63a5\u8c03\u7528\u3002<\/strong><\/p>\n<hr \/>\n<h2>1 \u4fbf\u6377\u6570\u636e\u67e5\u8be2\u51fd\u6570<\/h2>\n<p>\u8fd9\u7c7b\u51fd\u6570\u7684\u76ee\u6807\u662f\u4ee5\u6700\u7b80\u6d01\u7684\u65b9\u5f0f\uff0c\u4ece <code>data<\/code> \u6570\u636e\u5b57\u5178\u4e2d\u63d0\u53d6\u51fa\u60a8\u6700\u5173\u5fc3\u7684\u6570\u636e\u3002<\/p>\n<h3><code>khGet(data, key)<\/code> &#8211; \u4e07\u80fd\u6570\u636e\u83b7\u53d6\u51fd\u6570 (V2\/V3 \u901a\u7528)<\/h3>\n<p><code>khGet<\/code> \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u201c\u4e07\u80fd\u201d\u6570\u636e\u83b7\u53d6\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u60a8\u8f7b\u677e\u5730\u4ece <code>data<\/code> \u4e2d\u63d0\u53d6\u5404\u79cd\u5d4c\u5957\u7684\u4fe1\u606f\uff0c\u800c\u65e0\u9700\u7f16\u5199\u7e41\u7410\u7684\u5b57\u5178\u8bbf\u95ee\u4ee3\u7801\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khGet(data: Dict, key: str) -&gt; Any<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u6839\u636e\u6307\u5b9a\u7684 <code>key<\/code>\uff0c\u4ece <code>data<\/code> \u6570\u636e\u5b57\u5178\u4e2d\u5b89\u5168\u5730\u83b7\u53d6\u5bf9\u5e94\u7684\u503c\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>data<\/code> (dict): \u5373\u7b56\u7565\u56de\u8c03\u51fd\u6570\u4e2d\u6536\u5230\u7684 <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>key<\/code> (str): \u60a8\u5e0c\u671b\u83b7\u53d6\u7684\u6570\u636e\u7684<strong>\u201c\u522b\u540d\u201d<\/strong>\u3002\u652f\u6301\u7684\u522b\u540d\u5305\u62ec\uff1a\n<ul>\n<li><code>'date_str'<\/code>\uff1a\u8fd4\u56de <code>\"YYYY-MM-DD\"<\/code> \u683c\u5f0f\u7684\u65e5\u671f\u5b57\u7b26\u4e32\u3002<\/li>\n<li><code>'date_num'<\/code>\uff1a\u8fd4\u56de <code>\"YYYYMMDD\"<\/code> \u683c\u5f0f\u7684\u65e5\u671f\u5b57\u7b26\u4e32\u3002<\/li>\n<li><code>'time_str'<\/code>\uff1a\u8fd4\u56de <code>\"HH:MM:SS\"<\/code> \u683c\u5f0f\u7684\u65f6\u95f4\u5b57\u7b26\u4e32\u3002<\/li>\n<li><code>'datetime_str'<\/code>\uff1a\u8fd4\u56de <code>\"YYYY-MM-DD HH:MM:SS\"<\/code> \u683c\u5f0f\u7684\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u3002<\/li>\n<li><code>'datetime_obj'<\/code>\uff1a\u8fd4\u56de Python \u7684 <code>datetime<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>'timestamp'<\/code>\uff1a\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u7684 Unix \u65f6\u95f4\u6233\u3002<\/li>\n<li><code>'cash'<\/code>\uff1a\u8fd4\u56de\u5f53\u524d\u53ef\u7528\u8d44\u91d1 (float)\u3002<\/li>\n<li><code>'market_value'<\/code>\uff1a\u8fd4\u56de\u5f53\u524d\u6301\u4ed3\u603b\u5e02\u503c (float)\u3002<\/li>\n<li><code>'total_asset'<\/code>\uff1a\u8fd4\u56de\u5f53\u524d\u603b\u8d44\u4ea7 (float)\u3002<\/li>\n<li><code>'stocks'<\/code>\uff1a\u8fd4\u56de\u5f53\u524d\u80a1\u7968\u6c60\u7684\u5b8c\u6574\u5217\u8868 (List[str])\u3002<\/li>\n<li><code>'first_stock'<\/code>\uff1a\u8fd4\u56de\u80a1\u7968\u6c60\u4e2d\u7684\u7b2c\u4e00\u652f\u80a1\u7968\u4ee3\u7801 (str)\u3002<\/li>\n<li><code>'positions'<\/code>\uff1a\u8fd4\u56de\u5b8c\u6574\u7684\u6301\u4ed3\u5b57\u5178 (Dict)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a\u6839\u636e <code>key<\/code> \u8fd4\u56de\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u5982\u679c\u952e\u4e0d\u5b58\u5728\u6216\u6570\u636e\u65e0\u6548\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5b89\u5168\u7684\u9ed8\u8ba4\u503c\uff08\u5982 <code>None<\/code>, <code>0.0<\/code>, <code>[]<\/code>\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    # \u83b7\u53d6\u65f6\u95f4\u4fe1\u606f\n    current_date = khGet(data, 'date_str') # \"2024-07-15\"\n    current_time = khGet(data, 'time_str') # \"09:31:00\"\n\n    # \u83b7\u53d6\u8d26\u6237\u4fe1\u606f\n    available_cash = khGet(data, 'cash')\n\n    # \u83b7\u53d6\u80a1\u7968\u6c60\u4fe1\u606f\n    stock_list = khGet(data, 'stocks')\n    first_stock = khGet(data, 'first_stock')\n\n    logging.info(f\"\u65e5\u671f: {current_date}, \u65f6\u95f4: {current_time}, \u8d44\u91d1: {available_cash:.2f}\")\n\n    return []\n<\/code><\/pre>\n<h3><code>khPrice(data, stock_code, field)<\/code> &#8211; \u83b7\u53d6\u884c\u60c5\u4ef7\u683c (V2\/V3 \u901a\u7528)<\/h3>\n<p><code>khPrice<\/code> \u662f\u4e13\u95e8\u7528\u4e8e\u83b7\u53d6\u80a1\u7968\u884c\u60c5\u6570\u636e\u7684\u51fd\u6570\uff0c\u76f8\u6bd4\u76f4\u63a5\u8bbf\u95ee <code>data<\/code>\uff0c\u5b83\u66f4\u52a0\u5b89\u5168\uff0c\u80fd\u81ea\u52a8\u5904\u7406\u6570\u636e\u4e0d\u5b58\u5728\u6216\u65e0\u6548\u7684\u60c5\u51b5\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khPrice(data: Dict, stock_code: str, field: str = 'close') -&gt; float<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u83b7\u53d6\u6307\u5b9a\u80a1\u7968\u5728\u5f53\u524d\u65f6\u95f4\u70b9\u7684\u7279\u5b9a\u884c\u60c5\u5b57\u6bb5\u503c\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>data<\/code> (dict): \u5373 <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>stock_code<\/code> (str): \u80a1\u7968\u4ee3\u7801\uff0c\u5982 <code>'000001.SZ'<\/code>\u3002<\/li>\n<li><code>field<\/code> (str, \u53ef\u9009): \u884c\u60c5\u5b57\u6bb5\u540d\uff0c\u9ed8\u8ba4\u4e3a <code>'close'<\/code>\u3002\u652f\u6301 <code>'open'<\/code>, <code>'high'<\/code>, <code>'low'<\/code>, <code>'volume'<\/code>, <code>'amount'<\/code> \u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(float) \u5bf9\u5e94\u7684\u884c\u60c5\u6570\u636e\u3002\u5982\u679c\u6570\u636e\u4e0d\u5b58\u5728\u6216\u65e0\u6548\uff0c<strong>\u5b89\u5168\u5730\u8fd4\u56de <code>0.0<\/code><\/strong>\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    stock = '000001.SZ'\n\n    # \u83b7\u53d6\u5e73\u5b89\u94f6\u884c\u7684\u5f53\u524d\u5f00\u76d8\u4ef7\u548c\u6536\u76d8\u4ef7\n    open_price = khPrice(data, stock, 'open')\n    close_price = khPrice(data, stock, 'close') # \u7b49\u540c\u4e8e khPrice(data, stock)\n\n    if open_price &gt; 0:\n        logging.info(f\"{stock} \u5f00\u76d8\u4ef7: {open_price}, \u6700\u65b0\u4ef7: {close_price}\")\n\n    return []\n<\/code><\/pre>\n<h3><code>khIndex(data, stock_code, field)<\/code> &#8211; \u83b7\u53d6\u6280\u672f\u6307\u6807 (V3 \u4e13\u7528)<\/h3>\n<p><code>khIndex<\/code> \u662f\u4e13\u95e8\u7528\u4e8e\u83b7\u53d6\u6280\u672f\u6307\u6807\u6570\u636e\u7684\u51fd\u6570\u3002\u867d\u7136\u5e95\u5c42\u5b9e\u73b0\u4e0e <code>khPrice<\/code> \u7c7b\u4f3c\uff0c\u4f46\u5728\u8bed\u4e49\u4e0a\u533a\u5206\u4e86\u201c\u57fa\u7840\u884c\u60c5\u201d\u548c\u201c\u884d\u751f\u6307\u6807\u201d\uff0c\u4f7f\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khIndex(data: Dict, stock_code: str, field: str) -&gt; float<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u83b7\u53d6\u6307\u5b9a\u80a1\u7968\u5728\u5f53\u524d\u65f6\u95f4\u70b9\u7684\u7279\u5b9a\u6280\u672f\u6307\u6807\u503c\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>data<\/code> (dict): \u5373 <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>stock_code<\/code> (str): \u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<li><code>field<\/code> (str): \u6307\u6807\u5b57\u6bb5\u540d\uff0c\u5982 <code>'MA_5'<\/code>, <code>'RSI_14'<\/code>, <code>'MACD'<\/code> \u7b49\u3002<strong>\u6ce8\u610f\uff1a\u8fd9\u4e9b\u6307\u6807\u9700\u8981\u5728 <code>init<\/code> \u51fd\u6570\u4e2d\u901a\u8fc7 <code>khAddExtraFields<\/code> \u9884\u5148\u6ce8\u518c\u624d\u4f1a\u81ea\u52a8\u8ba1\u7b97\u3002<\/strong><\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(float) \u5bf9\u5e94\u7684\u6307\u6807\u6570\u636e\u3002\u5982\u679c\u6570\u636e\u4e0d\u5b58\u5728\u6216\u65e0\u6548\uff0c\u8fd4\u56de <code>0.0<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\"># \u5728 init \u4e2d\u6ce8\u518c\u6307\u6807\ndef init(stock_list, data):\n    khAddExtraFields(data, ['MA_5', 'RSI_14'])\n\n# \u5728 khHandlebar \u4e2d\u83b7\u53d6\u6307\u6807\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    stock = '000001.SZ'\n    ma5 = khIndex(data, stock, 'MA_5')\n    rsi = khIndex(data, stock, 'RSI_14')\n    # ...\n<\/code><\/pre>\n<h3><code>khHas(data, stock_code)<\/code> &#8211; \u5224\u65ad\u6301\u4ed3 (V2\/V3 \u901a\u7528)<\/h3>\n<p><code>khHas<\/code> \u662f\u4e00\u4e2a\u7b80\u6d01\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u5feb\u901f\u5224\u65ad\u5f53\u524d\u662f\u5426\u6301\u6709\u67d0\u53ea\u7279\u5b9a\u7684\u80a1\u7968\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khHas(data: Dict, stock_code: str) -&gt; bool<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u68c0\u67e5\u8d26\u6237\u5f53\u524d\u662f\u5426\u6301\u6709\u6307\u5b9a\u7684\u80a1\u7968\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>data<\/code> (dict): \u5373 <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>stock_code<\/code> (str): \u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(bool) \u5982\u679c\u6301\u6709\u8be5\u80a1\u7968\uff0c\u8fd4\u56de <code>True<\/code>\uff1b\u5426\u5219\u8fd4\u56de <code>False<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    stock = '600519.SH'\n\n    # \u68c0\u67e5\u662f\u5426\u6301\u6709\u8d35\u5dde\u8305\u53f0\n    if khHas(data, stock):\n        logging.info(f\"\u5f53\u524d\u6301\u6709 {stock}\u3002\")\n        # \u5728\u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u5356\u51fa\u903b\u8f91\n    else:\n        logging.info(f\"\u5f53\u524d\u672a\u6301\u6709 {stock}\u3002\")\n        # \u5728\u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u4e70\u5165\u903b\u8f91\n\n    return []\n<\/code><\/pre>\n<hr \/>\n<h2>2 \u7b56\u7565\u914d\u7f6e\u4e0e\u6570\u636e\u9884\u52a0\u8f7d (\u8fdb\u9636)<\/h2>\n<p>\u4e3a\u4e86\u63d0\u9ad8\u56de\u6d4b\u6548\u7387\uff0cKHQuant \u63d0\u4f9b\u4e86\u6570\u636e\u9884\u52a0\u8f7d\u673a\u5236\uff0c\u5141\u8bb8\u60a8\u5728\u7b56\u7565\u521d\u59cb\u5316\u9636\u6bb5\u58f0\u660e\u9700\u8981\u7528\u5230\u7684\u989d\u5916\u6570\u636e\u5b57\u6bb5\u3002<\/p>\n<h3><code>khAddExtraFields(data, fields)<\/code> &#8211; \u6ce8\u518c\u989d\u5916\u6570\u636e\u5b57\u6bb5 (V3 \u4e13\u7528)<\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a<strong>\u975e\u5e38\u91cd\u8981<\/strong>\u7684\u4f18\u5316\u51fd\u6570\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6846\u67b6\u53ea\u52a0\u8f7d\u57fa\u7840\u884c\u60c5\u6570\u636e\uff08OHLCV\uff09\u3002\u5982\u679c\u60a8\u5728\u7b56\u7565\u4e2d\u9700\u8981\u4f7f\u7528\u6280\u672f\u6307\u6807\uff08\u5982 MA, RSI, MACD \u7b49\uff09\uff0c\u5fc5\u987b\u5728 <code>init<\/code> \u51fd\u6570\u4e2d\u8c03\u7528\u6b64\u51fd\u6570\u8fdb\u884c\u6ce8\u518c\u3002\u6846\u67b6\u4f1a\u81ea\u52a8\u8ba1\u7b97\u5e76\u5728 <code>khHandlebar<\/code> \u4e2d\u63d0\u4f9b\u8fd9\u4e9b\u6307\u6807\u6570\u636e\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khAddExtraFields(data: Dict, fields: List[str]) -&gt; None<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u52a8\u6001\u914d\u7f6e\u9700\u8981\u989d\u5916\u52a0\u8f7d\u7684\u6570\u636e\u5b57\u6bb5\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>data<\/code> (dict): \u7b56\u7565\u7684 <code>data<\/code> \u5b57\u5178\uff08\u5728 <code>init<\/code> \u51fd\u6570\u4e2d\u4f20\u5165\uff09\u3002<\/li>\n<li><code>fields<\/code> (list): \u9700\u8981\u989d\u5916\u52a0\u8f7d\u7684\u5b57\u6bb5\u5217\u8868\uff0c\u5982 <code>['MA_5', 'RSI_14', 'MACD', 'KDJ']<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a<strong>\u5fc5\u987b\u5728 <code>init<\/code> \u51fd\u6570\u4e2d\u8c03\u7528<\/strong>\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">def init(stock_list, data):\n    # \u544a\u8bc9\u6846\u67b6\uff1a\u6211\u9700\u8981\u7528\u5230 5\u65e5\u5747\u7ebf\u300114\u65e5RSI \u548c MACD \u6307\u6807\n    # \u6846\u67b6\u4f1a\u5728\u56de\u6d4b\u5f00\u59cb\u524d\u81ea\u52a8\u8ba1\u7b97\u597d\u8fd9\u4e9b\u6570\u636e\n    khAddExtraFields(data, ['MA_5', 'RSI_14', 'MACD'])\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    # \u76f4\u63a5\u83b7\u53d6\u8ba1\u7b97\u597d\u7684\u6307\u6807\uff0c\u901f\u5ea6\u6781\u5feb\n    ma5 = khIndex(data, '000001.SZ', 'MA_5')\n    pass\n<\/code><\/pre>\n<hr \/>\n<h2>3 \u65f6\u95f4\u4e0e\u65e5\u671f\u5de5\u5177<\/h2>\n<p>\u5728\u7f16\u5199\u62e9\u65f6\u7b56\u7565\u6216\u8fdb\u884c\u65f6\u95f4\u76f8\u5173\u7684\u903b\u8f91\u5224\u65ad\u65f6\uff0c\u65f6\u95f4\u5de5\u5177\u51fd\u6570\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002<\/p>\n<h3><code>is_trade_time()<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>is_trade_time() -&gt; bool<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u5224\u65ad\u5f53\u524d\u65f6\u95f4\u662f\u5426\u5904\u4e8eA\u80a1\u7684\u5e38\u89c4\u4ea4\u6613\u65f6\u95f4\u6bb5\u5185\uff08<code>09:30-11:30<\/code>, <code>13:00-15:00<\/code>\uff09\u3002<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(bool) \u662f\u5219\u8fd4\u56de <code>True<\/code>\uff0c\u5426\u5219\u8fd4\u56de <code>False<\/code>\u3002<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a\u786e\u4fdd\u4ea4\u6613\u903b\u8f91\u53ea\u5728\u5f00\u76d8\u65f6\u6bb5\u6267\u884c\uff0c\u907f\u514d\u5728\u5348\u4f11\u6216\u975e\u4ea4\u6613\u65f6\u6bb5\u4ea7\u751f\u65e0\u6548\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">if is_trade_time():\n    # \u53ea\u5728\u4ea4\u6613\u65f6\u6bb5\u5185\u6267\u884c\u6838\u5fc3\u7b56\u7565\n    pass\n<\/code><\/pre>\n<h3><code>is_trade_day(date_str)<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>is_trade_day(date_str: str = None) -&gt; bool<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u5224\u65ad\u6307\u5b9a\u65e5\u671f\u662f\u5426\u4e3aA\u80a1\u7684\u4ea4\u6613\u65e5\uff08\u4f1a\u81ea\u52a8\u5254\u9664\u5468\u672b\u548c\u4e2d\u56fd\u7684\u6cd5\u5b9a\u8282\u5047\u65e5\uff09\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>date_str<\/code> (str, \u53ef\u9009): \u65e5\u671f\u5b57\u7b26\u4e32\uff0c\u652f\u6301 <code>\"YYYY-MM-DD\"<\/code> \u548c <code>\"YYYYMMDD\"<\/code> \u4e24\u79cd\u683c\u5f0f\u3002\u5982\u679c\u7559\u7a7a\uff0c\u5219\u9ed8\u8ba4\u5224\u65ad\u5f53\u5929\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(bool) \u662f\u4ea4\u6613\u65e5\u5219\u8fd4\u56de <code>True<\/code>\uff0c\u5426\u5219\u8fd4\u56de <code>False<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\"># \u5224\u65ad\u7279\u5b9a\u65e5\u671f\u662f\u5426\u4e3a\u4ea4\u6613\u65e5\nis_trading_day = is_trade_day(\"20241001\") # \u8fd4\u56de False (\u56fd\u5e86\u8282)\n\n# \u7ed3\u5408 khGet \u4f7f\u7528\ncurrent_date = khGet(data, 'date_num')\nif is_trade_day(current_date):\n    pass\n<\/code><\/pre>\n<h3><code>get_trade_days_count(start_date, end_date)<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>get_trade_days_count(start_date: str, end_date: str) -&gt; int<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684A\u80a1\u4ea4\u6613\u65e5\u5929\u6570\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>start_date<\/code> (str): <code>\"YYYY-MM-DD\"<\/code> \u683c\u5f0f\u7684\u5f00\u59cb\u65e5\u671f\u3002<\/li>\n<li><code>end_date<\/code> (str): <code>\"YYYY-MM-DD\"<\/code> \u683c\u5f0f\u7684\u7ed3\u675f\u65e5\u671f\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(int) \u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u4ea4\u6613\u65e5\u603b\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\"># \u8ba1\u7b972024\u5e74\u7b2c\u4e00\u5b63\u5ea6\u7684\u4ea4\u6613\u65e5\u5929\u6570\ndays = get_trade_days_count(\"2024-01-01\", \"2024-03-31\")\nlogging.info(f\"2024\u5e74Q1\u5171\u6709 {days} \u4e2a\u4ea4\u6613\u65e5\u3002\")\n<\/code><\/pre>\n<hr \/>\n<h2>4 \u5386\u53f2\u6570\u636e\u4e0e\u6280\u672f\u6307\u6807 (\u6838\u5fc3)<\/h2>\n<p>\u8fd9\u7c7b\u51fd\u6570\u4e13\u6ce8\u4e8e\u5386\u53f2\u6570\u636e\u7684\u83b7\u53d6\u548c\u5e38\u7528\u6280\u672f\u6307\u6807\u7684\u8ba1\u7b97\u3002<\/p>\n<h3><code>khHistory(symbol_list, fields, bar_count, fre_step, ...)<\/code> &#8211; \u5386\u53f2\u6570\u636e\u83b7\u53d6 (V2\/V3 \u901a\u7528)<\/h3>\n<p><code>khHistory<\/code> \u662f\u7b56\u7565\u4e2d<strong>\u6700\u6838\u5fc3\u7684\u529f\u80fd\u4e4b\u4e00<\/strong>\uff0c\u7528\u4e8e\u83b7\u53d6\u6307\u5b9a\u8bc1\u5238\u7684\u5386\u53f2K\u7ebf\u6570\u636e\uff0c\u662f\u8ba1\u7b97\u5404\u79cd\u6280\u672f\u6307\u6807\u7684\u57fa\u7840\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>khHistory(symbol_list, fields, bar_count, fre_step, current_time=None, skip_paused=False, fq='pre', force_download=False)<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u83b7\u53d6\u5386\u53f2K\u7ebf\u6570\u636e\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>symbol_list<\/code> (list\/str): \u4e00\u4e2a\u6216\u591a\u4e2a\u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<li><code>fields<\/code> (list): \u5e0c\u671b\u83b7\u53d6\u7684\u884c\u60c5\u5b57\u6bb5\uff0c\u5982 <code>['open', 'high', 'low', 'close']<\/code>\u3002<\/li>\n<li><code>bar_count<\/code> (int): \u5e0c\u671b\u83b7\u53d6\u7684K\u7ebf\u6570\u91cf\u3002<\/li>\n<li><code>fre_step<\/code> (str): K\u7ebf\u5468\u671f\uff0c\u652f\u6301 <code>'1m'<\/code>, <code>'5m'<\/code>, <code>'1d'<\/code> \u7b49\u3002<\/li>\n<li><code>current_time<\/code> (str, \u53ef\u9009): \u83b7\u53d6\u5386\u53f2\u6570\u636e\u7684<strong>\u622a\u6b62\u65f6\u95f4\u70b9\uff08\u4e0d\u5305\u542b\uff09<\/strong>\u3002\u5982\u679c\u4e3a <code>None<\/code>\uff0c\u5219\u6570\u636e\u622a\u6b62\u5230\u5f53\u524d\u6700\u65b0\u65f6\u95f4\u3002<strong>\u5728\u56de\u6d4b\u4e2d\uff0c\u4e3a\u4e86\u907f\u514d\u7528\u5230\u672a\u6765\u6570\u636e\uff0c\u901a\u5e38\u5e94\u4f20\u5165\u5f53\u524d\u65f6\u95f4\u70b9<\/strong>\u3002<\/li>\n<li><code>skip_paused<\/code> (bool, \u53ef\u9009): \u662f\u5426\u8df3\u8fc7\u505c\u724c\u65e5\uff0c\u9ed8\u8ba4\u4e3a <code>False<\/code>\u3002<\/li>\n<li><code>fq<\/code> (str, \u53ef\u9009): \u590d\u6743\u7c7b\u578b\uff0c\u9ed8\u8ba4\u4e3a <code>'pre'<\/code> (\u524d\u590d\u6743)\u3002<\/li>\n<li><code>force_download<\/code> (bool, \u53ef\u9009): \u662f\u5426\u5f3a\u5236\u4e0b\u8f7d\u65b0\u6570\u636e\uff0c\u9ed8\u8ba4\u4e3a <code>False<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (dict) \u4e00\u4e2a\u5b57\u5178\uff0c\u952e\u4e3a\u80a1\u7968\u4ee3\u7801\uff0c\u503c\u4e3a\u5305\u542b\u5386\u53f2\u6570\u636e\u7684 <code>pandas.DataFrame<\/code>\u3002<\/li>\n<\/ul>\n<h4><code>current_time<\/code> \u53c2\u6570\u8be6\u89e3<\/h4>\n<p><code>current_time<\/code> \u53c2\u6570\u5b9a\u4e49\u4e86\u6570\u636e\u83b7\u53d6\u7684<strong>\u201c\u89c2\u5bdf\u70b9\u201d<\/strong>\uff0c\u51fd\u6570\u5c06\u8fd4\u56de\u8be5\u89c2\u5bdf\u70b9<strong>\u4e4b\u524d<\/strong>\u7684\u5386\u53f2\u6570\u636e\uff0c<strong>\u4e25\u683c\u4e0d\u5305\u542b<\/strong> <code>current_time<\/code> \u8fd9\u4e00\u65f6\u523b\u7684\u6570\u636e\u3002\u8fd9\u662f\u4e3a\u4e86\u5728\u56de\u6d4b\u4e2d\u6a21\u62df\u771f\u5b9e\u7684\u4ea4\u6613\u573a\u666f\uff1a\u5728\u505a\u51b3\u7b56\u65f6\uff0c\u6211\u4eec\u53ea\u80fd\u770b\u5230\u201c\u5f53\u524d\u65f6\u523b\u201d\u4e4b\u524d\u53d1\u751f\u7684\u884c\u60c5\u3002<\/p>\n<p>\u8be5\u53c2\u6570\u652f\u6301\u591a\u79cd\u65f6\u95f4\u683c\u5f0f\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e <code>fre_step<\/code> \u81ea\u52a8\u9002\u914d\u8fc7\u6ee4\u903b\u8f91\uff1a<\/p>\n<ol>\n<li><strong>\u65e5\u671f\u683c\u5f0f<\/strong> (<code>YYYY-MM-DD<\/code> \u6216 <code>YYYYMMDD<\/code>)\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u4e3b\u8981\u7528\u4e8e\u65e5\u7ebf (<code>1d<\/code>) \u56de\u6d4b\u3002<\/li>\n<li><strong>\u8fc7\u6ee4\u903b\u8f91<\/strong>\uff1a\u8fd4\u56de\u65e5\u671f <strong>\u5c0f\u4e8e<\/strong> <code>current_time<\/code> \u7684\u6570\u636e\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a\u82e5 <code>current_time=\"2024-01-15\"<\/code>\uff0c\u5219\u8fd4\u56de <code>2024-01-14<\/code> \u53ca\u4e4b\u524d\u7684 K \u7ebf\uff0c<strong>\u4e0d\u5305\u542b<\/strong> 15 \u53f7\u5f53\u5929\u7684\u6570\u636e\uff08\u56e0\u4e3a 15 \u53f7\u6536\u76d8\u540e\u624d\u80fd\u770b\u5230\u5f53\u65e5 K \u7ebf\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u65f6\u95f4\u683c\u5f0f<\/strong> (<code>YYYY-MM-DD HH:MM:SS<\/code> \u6216 <code>YYYYMMDD HHMMSS<\/code>)\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u4e3b\u8981\u7528\u4e8e\u5206\u949f\u7ebf (<code>1m<\/code>, <code>5m<\/code>) \u6216 Tick \u6570\u636e\u56de\u6d4b\u3002<\/li>\n<li><strong>\u8fc7\u6ee4\u903b\u8f91<\/strong>\uff1a\u8fd4\u56de\u65f6\u95f4\u6233 <strong>\u5c0f\u4e8e<\/strong> <code>current_time<\/code> \u7684\u6570\u636e\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a\u82e5 <code>current_time=\"2024-01-15 10:30:00\"<\/code>\uff0c\u5219\u8fd4\u56de <code>10:30:00<\/code> \u4e4b\u524d\u7684\u6240\u6709\u5206\u949f\u7ebf\uff08\u5982 <code>10:29<\/code> \u53ca\u5176\u4e4b\u524d\u7684 K \u7ebf\uff09\uff0c<strong>\u4e0d\u5305\u542b<\/strong> <code>10:30<\/code> \u8fd9\u4e00\u65f6\u523b\u7ed3\u675f\u7684 K \u7ebf\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>\u4f7f\u7528\u6848\u4f8b<\/h4>\n<p><strong>\u6848\u4f8b 1\uff1a\u5728\u65e5\u7ebf\u7b56\u7565\u4e2d\u83b7\u53d6\u5386\u53f2\u6570\u636e<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">def khHandlebar(data: Dict) -&gt; List[Dict]:\n    # \u5047\u8bbe\u5f53\u524d\u56de\u6d4b\u65e5\u671f\u4e3a 2024-01-15\n    current_date = khGet(data, 'date_num') # \"20240115\"\n\n    # \u83b7\u53d6\u622a\u6b62\u5230\u6628\u65e5\u7684\u6700\u8fd120\u6839\u65e5\u7ebf\n    history_data = khHistory(\n        symbol_list='000001.SZ',\n        fields=['close'],\n        bar_count=20,\n        fre_step='1d',\n        current_time=current_date # \u4f20\u5165\u5f53\u5929\u65e5\u671f\n    )\n\n    # \u7ed3\u679c\uff1ahistory_data \u4e2d\u5305\u542b 2024-01-14 \u53ca\u4e4b\u524d\u768420\u5929\u6570\u636e\n    # \u4e0d\u5305\u542b 2024-01-15 \u7684\u6570\u636e\uff08\u907f\u514d\u672a\u6765\u51fd\u6570\uff09\n    pass\n<\/code><\/pre>\n<p><strong>\u6848\u4f8b 2\uff1a\u5728\u5206\u949f\u7b56\u7565\u4e2d\u83b7\u53d6\u5386\u53f2\u6570\u636e<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">def khHandlebar(data: Dict) -&gt; List[Dict]:\n    # \u5047\u8bbe\u5f53\u524d\u56de\u6d4b\u65f6\u95f4\u4e3a 2024-01-15 14:00:00\n    current_time = khGet(data, 'datetime_str') # \"2024-01-15 14:00:00\"\n\n    # \u83b7\u53d6\u622a\u6b62\u5230\u5f53\u524d\u65f6\u523b\u524d\u7684\u6700\u8fd160\u68391\u5206\u949fK\u7ebf\n    history_data = khHistory(\n        symbol_list='000001.SZ',\n        fields=['close'],\n        bar_count=60,\n        fre_step='1m',\n        current_time=current_time \n    )\n\n    # \u7ed3\u679c\uff1ahistory_data \u4e2d\u6700\u540e\u4e00\u6761\u6570\u636e\u7684\u65f6\u95f4\u5e94\u4e3a 13:59:00\n    # \u4e0d\u5305\u542b 14:00:00 \u7684\u6570\u636e\uff08\u5047\u8bbe\u6b64\u65f6\u521a\u523014\u70b9\uff0cK\u7ebf\u5c1a\u672a\u8d70\u5b8c\u6216\u521a\u8d70\u5b8c\uff09\n    pass\n<\/code><\/pre>\n<p><strong>\u6848\u4f8b 3\uff1a\u83b7\u53d6\u6307\u5b9a\u5386\u53f2\u65f6\u523b\u7684\u6570\u636e\uff08\u7528\u4e8e\u590d\u76d8\uff09<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\"># \u60f3\u8981\u67e5\u770b 2023\u5e74\u6625\u8282\u524d\uff082023-01-20\uff09\u6700\u540e10\u5929\u7684\u884c\u60c5\nhistory_data = khHistory(\n    symbol_list='000001.SZ',\n    fields=['close', 'volume'],\n    bar_count=10,\n    fre_step='1d',\n    current_time='2023-01-21' # \u8bbe\u7f6e\u4e3a\u6625\u8282\u540e\u7b2c\u4e00\u5929\u6216\u6625\u8282\u671f\u95f4\n)\n<\/code><\/pre>\n<h3>MyTT \u6307\u6807\u5e93\u901f\u67e5 (V2\/V3 \u901a\u7528)<\/h3>\n<p>KHQuant \u5185\u7f6e\u4e86\u529f\u80fd\u5f3a\u5927\u7684 <code>MyTT<\/code> \u6307\u6807\u5e93\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u5728\u7b56\u7565\u4e2d\u8c03\u7528\u8fd9\u4e9b\u7ecf\u5178\u7684\u901a\u8fbe\u4fe1\/\u540c\u82b1\u987a\u98ce\u683c\u6307\u6807\u51fd\u6570\u3002<strong>\u65e0\u9700\u81ea\u5df1\u7f16\u5199\u590d\u6742\u7684\u516c\u5f0f\uff0c\u76f4\u63a5\u4f7f\u7528\u5373\u53ef\u3002<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u652f\u6301\u7684\u6838\u5fc3\u6307\u6807\u51fd\u6570\u4e00\u89c8\uff1a<\/p>\n<h4>\u57fa\u7840\u8fd0\u7b97\u7c7b<\/h4>\n<ul>\n<li><code>REF(S, N)<\/code>: \u5f15\u7528N\u5468\u671f\u524d\u7684\u6570\u636e\uff08\u5982 <code>REF(CLOSE, 1)<\/code> \u4e3a\u6628\u6536\uff09\u3002<\/li>\n<li><code>ABS(S)<\/code>: \u7edd\u5bf9\u503c\u3002<\/li>\n<li><code>MAX(S1, S2)<\/code> \/ <code>MIN(S1, S2)<\/code>: \u5e8f\u5217\u6700\u5927\/\u6700\u5c0f\u503c\u3002<\/li>\n<li><code>HHV(S, N)<\/code> \/ <code>LLV(S, N)<\/code>: N\u5468\u671f\u5185\u7684\u6700\u9ad8\u503c\/\u6700\u4f4e\u503c\u3002<\/li>\n<li><code>MA(S, N)<\/code>: \u7b80\u5355\u79fb\u52a8\u5e73\u5747\u3002<\/li>\n<li><code>EMA(S, N)<\/code>: \u6307\u6570\u79fb\u52a8\u5e73\u5747\u3002<\/li>\n<li><code>SMA(S, N, M)<\/code>: \u52a0\u6743\u79fb\u52a8\u5e73\u5747\uff08\u4e2d\u56fd\u5f0f\uff09\u3002<\/li>\n<li><code>STD(S, N)<\/code>: \u6837\u672c\u6807\u51c6\u5dee\u3002<\/li>\n<li><code>SUM(S, N)<\/code>: N\u5468\u671f\u7d2f\u52a0\u548c\u3002<\/li>\n<li><code>CONST(S)<\/code>: \u53d6\u5e8f\u5217\u6700\u540e\u4e00\u4e2a\u503c\u4e3a\u5e38\u6570\u3002<\/li>\n<\/ul>\n<h4>\u6838\u5fc3\u6307\u6807\u7c7b<\/h4>\n<ul>\n<li><code>MACD(CLOSE, SHORT=12, LONG=26, M=9)<\/code>: MACD\u6307\u6807\u3002\u8fd4\u56de <code>(DIF, DEA, MACD)<\/code>\u3002<\/li>\n<li><code>RSI(CLOSE, N=14)<\/code>: \u76f8\u5bf9\u5f3a\u5f31\u6307\u6807\u3002<\/li>\n<li><code>KDJ(CLOSE, HIGH, LOW, N=9, M1=3, M2=3)<\/code>: KDJ\u6307\u6807\u3002\u8fd4\u56de <code>(K, D, J)<\/code>\u3002<\/li>\n<li><code>BOLL(CLOSE, N=20, P=2)<\/code>: \u5e03\u6797\u5e26\u3002\u8fd4\u56de <code>(UPPER, MID, LOWER)<\/code>\u3002<\/li>\n<li><code>BIAS(CLOSE, L1=6, L2=12, L3=24)<\/code>: \u4e56\u79bb\u7387\u3002<\/li>\n<li><code>WR(CLOSE, HIGH, LOW, N=10, N1=6)<\/code>: \u5a01\u5ec9\u6307\u6807\u3002<\/li>\n<li><code>CCI(CLOSE, HIGH, LOW, N=14)<\/code>: \u987a\u52bf\u6307\u6807\u3002<\/li>\n<li><code>ATR(CLOSE, HIGH, LOW, N=20)<\/code>: \u771f\u5b9e\u6ce2\u5e45\u3002<\/li>\n<li><code>TRIX(CLOSE)<\/code>: \u4e09\u91cd\u6307\u6570\u5e73\u6ed1\u5e73\u5747\u7ebf\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u793a\u4f8b\uff1a\u8ba1\u7b97 MACD \u91d1\u53c9<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    stock = '000001.SZ'\n\n    # 1. \u83b7\u53d6\u5386\u53f2\u6570\u636e\n    h_data = khHistory(stock, ['close'], 100, '1d', current_time=khGet(data, 'date_num'))\n    if stock not in h_data: return []\n\n    # 2. \u63d0\u53d6\u6536\u76d8\u4ef7\u5e8f\u5217 (\u8f6c\u6362\u4e3a numpy array)\n    close_prices = h_data[stock]['close'].values\n\n    # 3. \u4f7f\u7528 MyTT \u8ba1\u7b97 MACD\n    DIF, DEA, MACD_VAL = MACD(close_prices)\n\n    # 4. \u5224\u65ad\u91d1\u53c9 (DIF \u4e0a\u7a7f DEA)\n    if DIF[-1] &gt; DEA[-1] and DIF[-2] &lt;= DEA[-2]:\n        logging.info(f\"{stock} \u51fa\u73b0 MACD \u91d1\u53c9\uff01\")\n\n    return []\n<\/code><\/pre>\n<h3>\u7f20\u8bba\u5de5\u5177\u7bb1 (KhChanLunTools) (V2\/V3 \u901a\u7528)<\/h3>\n<p>\u5bf9\u4e8e\u9ad8\u9636\u7528\u6237\uff0cKHQuant \u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u7f20\u8bba\u5f62\u6001\u5206\u6790\u5de5\u5177\uff0c\u652f\u6301\u5206\u578b\u8bc6\u522b\u3001\u8d8b\u52bf\u5224\u65ad\u548c\u5206\u578b\u7a81\u7834\u68c0\u6d4b\u3002\u8fd9\u4e9b\u5de5\u5177\u5bf9\u4e8e\u6784\u5efa\u57fa\u4e8e\u5f62\u6001\u7684\u7b56\u7565\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<h4>1. \u5206\u578b\u8bc6\u522b<\/h4>\n<p>\u5206\u578b\u662f\u7f20\u8bba\u4e2d\u6700\u57fa\u672c\u7684\u5f62\u6001\u5355\u5143\uff0c\u5206\u4e3a\u9876\u5206\u578b\u548c\u5e95\u5206\u578b\u3002<\/p>\n<ul>\n<li><strong><code>is_bottom_fractal(kline_data, index=-1)<\/code><\/strong>: \u5224\u65ad\u662f\u5426\u4e3a\u5e95\u5206\u578b\u3002\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>: \u4e2d\u95f4K\u7ebf\u7684\u9ad8\u70b9\u548c\u4f4e\u70b9\u90fd\u4f4e\u4e8e\u5de6\u53f3\u4e24\u6839K\u7ebf\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>kline_data<\/code> (pd.DataFrame): K\u7ebf\u6570\u636e\uff0c\u5fc5\u987b\u5305\u542b <code>high<\/code> \u548c <code>low<\/code> \u5217\u3002<\/li>\n<li><code>index<\/code> (int): \u8981\u5224\u65ad\u7684K\u7ebf\u4f4d\u7f6e\uff0c\u9ed8\u8ba4\u4e3a <code>-1<\/code>\uff08\u6700\u65b0\u4e00\u6839\uff09\u3002\u6ce8\u610f\uff1aindex \u6307\u5411\u7684\u662f\u5206\u578b\u4e2d\u95f4\u90a3\u6839K\u7ebf\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (bool) \u662f\u5e95\u5206\u578b\u8fd4\u56de <code>True<\/code>\uff0c\u5426\u5219\u8fd4\u56de <code>False<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>is_top_fractal(kline_data, index=-1)<\/code><\/strong>: \u5224\u65ad\u662f\u5426\u4e3a\u9876\u5206\u578b\u3002\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>: \u4e2d\u95f4K\u7ebf\u7684\u9ad8\u70b9\u548c\u4f4e\u70b9\u90fd\u9ad8\u4e8e\u5de6\u53f3\u4e24\u6839K\u7ebf\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>: \u540c\u4e0a\u3002<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (bool) \u662f\u9876\u5206\u578b\u8fd4\u56de <code>True<\/code>\uff0c\u5426\u5219\u8fd4\u56de <code>False<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>find_all_fractals(kline_data)<\/code><\/strong>: \u6279\u91cf\u67e5\u627e\u6240\u6709\u5206\u578b\u3002\n<ul>\n<li><strong>\u529f\u80fd<\/strong>: \u626b\u63cf\u6574\u6bb5K\u7ebf\u6570\u636e\uff0c\u627e\u51fa\u6240\u6709\u7684\u9876\u5206\u578b\u548c\u5e95\u5206\u578b\u4f4d\u7f6e\u3002<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: <code>(List[int], List[int])<\/code>\uff0c\u5206\u522b\u8fd4\u56de\u9876\u5206\u578b\u548c\u5e95\u5206\u578b\u7684\u7d22\u5f15\u5217\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. \u8d8b\u52bf\u4e0e\u4ef7\u683c\u5206\u6790<\/h4>\n<ul>\n<li><strong><code>get_trend_direction(kline_data, period=20)<\/code><\/strong>: \u5224\u65adK\u7ebf\u8d8b\u52bf\u65b9\u5411\u3002\n<ul>\n<li><strong>\u539f\u7406<\/strong>: \u7efc\u5408\u5747\u7ebf\u65b9\u5411\u3001\u9ad8\u4f4e\u70b9\u5e8f\u5217\u548c\u6536\u76d8\u4ef7\u4f4d\u7f6e\u8fdb\u884c\u5224\u65ad\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>kline_data<\/code>: K\u7ebf\u6570\u636e\u3002<\/li>\n<li><code>period<\/code> (int): \u5224\u65ad\u5468\u671f\uff0c\u9ed8\u8ba420\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (str) \u8fd4\u56de <code>'up'<\/code> (\u4e0a\u5347), <code>'down'<\/code> (\u4e0b\u964d), \u6216 <code>'sideways'<\/code> (\u9707\u8361)\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>get_fractal_price(kline_data, index, fractal_type)<\/code><\/strong>: \u83b7\u53d6\u5206\u578b\u5173\u952e\u4ef7\u683c\u3002\n<ul>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>index<\/code>: \u5206\u578b\u4f4d\u7f6e\u7d22\u5f15\u3002<\/li>\n<li><code>fractal_type<\/code>: <code>'top'<\/code> (\u9876\u5206\u578b) \u6216 <code>'bottom'<\/code> (\u5e95\u5206\u578b)\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (float) \u9876\u5206\u578b\u8fd4\u56de\u6700\u9ad8\u4ef7\uff0c\u5e95\u5206\u578b\u8fd4\u56de\u6700\u4f4e\u4ef7\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>check_fractal_break(kline_data, fractal_index, fractal_type, current_index=-1)<\/code><\/strong>: \u68c0\u67e5\u5206\u578b\u662f\u5426\u88ab\u7a81\u7834\u3002\n<ul>\n<li><strong>\u529f\u80fd<\/strong>: \u5224\u65ad\u540e\u7eed\u884c\u60c5\u662f\u5426\u7a81\u7834\u4e86\u6307\u5b9a\u5206\u578b\u7684\u6781\u503c\u70b9\uff08\u9876\u5206\u578b\u88ab\u5411\u4e0a\u7a81\u7834\uff0c\u5e95\u5206\u578b\u88ab\u5411\u4e0b\u7a81\u7834\uff09\u3002<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>: (bool) \u7a81\u7834\u8fd4\u56de <code>True<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>3. \u9ad8\u7ea7K\u7ebf\u6570\u636e\u83b7\u53d6<\/h4>\n<ul>\n<li><strong><code>khKline(symbol_list, period, bar_count, ...)<\/code><\/strong>: <strong>\u9ad8\u7ea7K\u7ebf\u83b7\u53d6\u51fd\u6570<\/strong>\u3002\n<ul>\n<li><strong>\u7279\u70b9<\/strong>:\n<ul>\n<li>\u652f\u6301\u4efb\u610f\u81ea\u5b9a\u4e49\u5468\u671f\uff08\u5982 <code>3d<\/code>, <code>2h<\/code>, <code>15m<\/code>\uff09\u3002<\/li>\n<li><strong>\u5e74\u5bf9\u9f50<\/strong>: \u591a\u65e5\u5468\u671f\uff08\u59823\u65e5\u7ebf\uff09\u4ee5\u6bcf\u5e74\u7b2c\u4e00\u4e2a\u4ea4\u6613\u65e5\u4e3a\u57fa\u51c6\u5bf9\u9f50\uff0c\u907f\u514d\u8de8\u5e74\u6570\u636e\u9519\u4f4d\u3002<\/li>\n<li><strong>\u5b9e\u65f6\u5feb\u7167<\/strong>: \u5728\u4ea4\u6613\u65f6\u6bb5\u5185\uff0c\u672a\u6536\u7ebf\u7684K\u7ebf\u4f1a\u5305\u542b\u5f53\u524d\u65f6\u523b\u7684\u5feb\u7167\u6570\u636e\uff0c\u9002\u5408\u5b9e\u65f6\u76d1\u63a7\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u53c2\u6570<\/strong>:\n<ul>\n<li><code>symbol_list<\/code>: \u80a1\u7968\u4ee3\u7801\u6216\u5217\u8868\u3002<\/li>\n<li><code>period<\/code>: \u5468\u671f\u5b57\u7b26\u4e32\uff0c\u5982 <code>'15m'<\/code>, <code>'2h'<\/code>, <code>'3d'<\/code>\u3002<\/li>\n<li><code>bar_count<\/code>: \u83b7\u53d6\u6570\u91cf\u3002<\/li>\n<li><code>end_time<\/code>: \u7ed3\u675f\u65f6\u95f4\uff08\u53ef\u9009\uff09\uff0c\u7528\u4e8e\u5386\u53f2\u56de\u6d4b\u9a8c\u8bc1\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u7efc\u5408\u793a\u4f8b\uff1a\u7f20\u8bba\u5e95\u5206\u578b\u4e70\u5165\u7b56\u7565<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    stock = '000001.SZ'\n\n    # 1. \u83b7\u53d6 15\u5206\u949f K\u7ebf\u6570\u636e\uff08\u7f20\u8bba\u5e38\u7528\u5c0f\u5468\u671f\uff09\n    # \u83b7\u53d650\u6839K\u7ebf\uff0c\u786e\u4fdd\u6709\u8db3\u591f\u6570\u636e\u5224\u65ad\u8d8b\u52bf\u548c\u5206\u578b\n    kline_dict = khKline(stock, '15m', 50) \n\n    if stock in kline_dict:\n        df = kline_dict[stock]\n\n        # 2. \u5224\u65ad\u6700\u65b0 K \u7ebf\uff08\u5012\u6570\u7b2c\u4e8c\u6839\u4e3a\u4e2d\u95f4K\u7ebf\uff0c\u6240\u4ee5\u68c0\u67e5 index=-2 \u6216 -1\uff09\n        # \u6ce8\u610f\uff1a\u5b9e\u76d8\u4e2d\u901a\u5e38\u7b49\u5f85\u5206\u578b\u786e\u8ba4\uff08\u53f3\u4fa7K\u7ebf\u6536\u76d8\uff09\uff0c\u6216\u8005\u5728\u53f3\u4fa7K\u7ebf\u8fd0\u884c\u4e2d\u9884\u5224\n        # \u8fd9\u91cc\u6f14\u793a\u5224\u65ad\u521a\u521a\u5b8c\u6210\u7684\u4e00\u7ec4\u5206\u578b\uff08\u5047\u8bbe\u5f53\u524d\u65f6\u523b\u662f\u53f3\u4fa7K\u7ebf\u7684\u7ed3\u675f\u6216\u4e0b\u4e00\u6839\u7684\u5f00\u59cb\uff09\n\n        # \u5224\u65ad\u5012\u6570\u7b2c\u4e8c\u6839\u662f\u5426\u6784\u6210\u5e95\u5206\u578b\u7684\u4e2d\u95f4K\u7ebf\uff08\u5373\u5206\u578b\u5df2\u786e\u7acb\uff09\n        if is_bottom_fractal(df, index=-2):\n\n            # 3. \u7ed3\u5408\u8d8b\u52bf\u8fc7\u6ee4\uff1a\u53ea\u6709\u5728\u4e0a\u5347\u8d8b\u52bf\u6216\u9707\u8361\u4e2d\u624d\u4e70\u5165\n            trend = get_trend_direction(df)\n            if trend != 'down':\n                logging.info(f\"{stock} 15\u5206\u949f\u7ea7\u522b\u786e\u7acb\u5e95\u5206\u578b\uff0c\u8d8b\u52bf: {trend}\")\n\n                # 4. \u83b7\u53d6\u5206\u578b\u6700\u4f4e\u70b9\u4f5c\u4e3a\u6b62\u635f\u4f4d\n                stop_loss_price = get_fractal_price(df, -2, 'bottom')\n                logging.info(f\"\u5efa\u8bae\u6b62\u635f\u4f4d: {stop_loss_price}\")\n\n                # \u751f\u6210\u4e70\u5165\u4fe1\u53f7...\n\n    return []\n<\/code><\/pre>\n<hr \/>\n<h2>5 \u4ea4\u6613\u4fe1\u53f7\u4e0e\u8d44\u91d1\u7ba1\u7406<\/h2>\n<p>\u8fd9\u7c7b\u51fd\u6570\u7528\u4e8e\u7b80\u5316\u4ea4\u6613\u4fe1\u53f7\u7684\u751f\u6210\u548c\u4ed3\u4f4d\u8ba1\u7b97\uff0c\u80fd\u6781\u5927\u63d0\u9ad8\u7b56\u7565\u7f16\u5199\u6548\u7387\u3002<\/p>\n<h3><code>calculate_max_buy_volume(data, stock_code, price, cash_ratio)<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>calculate_max_buy_volume(data: Dict, stock_code: str, price: float, cash_ratio: float = 1.0) -&gt; int<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u6839\u636e\u53ef\u7528\u8d44\u91d1\u3001\u80a1\u4ef7\u548c\u4ea4\u6613\u6210\u672c\uff0c\u7cbe\u786e\u8ba1\u7b97\u51fa\u7406\u8bba\u4e0a\u53ef\u4ee5\u4e70\u5165\u7684\u6700\u5927\u80a1\u7968\u6570\u91cf\uff08\u4f1a\u81ea\u52a8\u5411\u4e0b\u53d6\u6574\u5230100\u7684\u500d\u6570\uff09\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>data<\/code> (dict): <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>stock_code<\/code> (str): \u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<li><code>price<\/code> (float): \u8ba1\u5212\u4e70\u5165\u7684\u4ef7\u683c\u3002<\/li>\n<li><code>cash_ratio<\/code> (float, \u53ef\u9009): \u8ba1\u5212\u4f7f\u7528\u7684\u8d44\u91d1\u6bd4\u4f8b\uff0c\u9ed8\u8ba4\u4e3a <code>1.0<\/code> (\u5168\u90e8\u53ef\u7528\u8d44\u91d1)\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a(int) \u53ef\u4ee5\u4e70\u5165\u7684\u6700\u5927\u80a1\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\"># \u8ba1\u5212\u752850%\u7684\u8d44\u91d1\u4e70\u5165\u5e73\u5b89\u94f6\u884c\ncurrent_price = khPrice(data, '000001.SZ', 'close')\nmax_volume = calculate_max_buy_volume(data, '000001.SZ', current_price, cash_ratio=0.5)\nif max_volume &gt; 0:\n    logging.info(f\"\u6700\u591a\u53ef\u4e70\u5165 {max_volume} \u80a1\")\n<\/code><\/pre>\n<h3><code>generate_signal(data, stock_code, price, ratio, action, reason)<\/code> &#8211; \u667a\u80fd\u4fe1\u53f7\u751f\u6210 (V2\/V3 \u901a\u7528)<\/h3>\n<p><code>generate_signal<\/code> \u662f\u4e00\u4e2a<strong>\u5f3a\u70c8\u63a8\u8350\u4f7f\u7528<\/strong>\u7684\u9ad8\u7ea7\u4fe1\u53f7\u751f\u6210\u51fd\u6570\u3002\u5b83\u5c01\u88c5\u4e86\u7e41\u7410\u7684\u4ed3\u4f4d\u8ba1\u7b97\u903b\u8f91\uff0c\u8ba9\u60a8\u53ea\u9700\u5173\u6ce8\u4ea4\u6613\u65b9\u5411\u548c\u6bd4\u4f8b\u5373\u53ef\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>generate_signal(data: Dict, stock_code: str, price: float, ratio: float, action: str, reason: str = \"\") -&gt; List[Dict]<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u667a\u80fd\u751f\u6210\u6807\u51c6\u4ea4\u6613\u4fe1\u53f7\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>data<\/code> (dict): <code>data<\/code> \u5bf9\u8c61\u3002<\/li>\n<li><code>stock_code<\/code> (str): \u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<li><code>price<\/code> (float): \u4ea4\u6613\u4ef7\u683c\u3002<\/li>\n<li><code>ratio<\/code> (float): <strong>\u6838\u5fc3\u53c2\u6570<\/strong>\u3002\n<ul>\n<li>\u5f53 <code>action<\/code> \u4e3a <code>'buy'<\/code> \u65f6, <code>ratio<\/code> \u4ee3\u8868\u8d44\u91d1\u4f7f\u7528\u6bd4\u4f8b\uff08\u5982 <code>0.5<\/code> \u4ee3\u8868\u4f7f\u752850%\u7684\u53ef\u7528\u8d44\u91d1\uff09\u3002<\/li>\n<li>\u5f53 <code>action<\/code> \u4e3a <code>'sell'<\/code> \u65f6, <code>ratio<\/code> \u4ee3\u8868\u6301\u4ed3\u5356\u51fa\u6bd4\u4f8b\uff08\u5982 <code>1.0<\/code> \u4ee3\u8868\u5168\u90e8\u5356\u51fa\uff09\u3002<\/li>\n<li><strong>\u7279\u6b8a\u7528\u6cd5<\/strong>: \u5f53 <code>action<\/code> \u4e3a <code>'buy'<\/code> \u4e14 <code>ratio<\/code> > 1 \u65f6\uff0c<code>ratio<\/code> \u4f1a\u88ab\u89c6\u4e3a<strong>\u56fa\u5b9a\u80a1\u6570<\/strong>\u8fdb\u884c\u4e70\u5165\uff08\u5fc5\u987b\u662f100\u7684\u6574\u6570\u500d\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>action<\/code> (str): <code>'buy'<\/code> \u6216 <code>'sell'<\/code>\u3002<\/li>\n<li><code>reason<\/code> (str, \u53ef\u9009): \u4ea4\u6613\u539f\u56e0\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a<code>List[Dict]<\/code>\uff0c\u4e00\u4e2a\u5305\u542b\u5355\u4e2a\u4ea4\u6613\u4fe1\u53f7\u7684\u5217\u8868\u3002\u5982\u679c\u6761\u4ef6\u4e0d\u6ee1\u8db3\uff08\u5982\u8d44\u91d1\u4e0d\u8db3\u6216\u65e0\u4ed3\u53ef\u5356\uff09\uff0c\u5219\u8fd4\u56de\u7a7a\u5217\u8868\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">from khQuantImport import *\n\ndef khHandlebar(data: Dict) -&gt; List[Dict]:\n    signals = []\n    stock = '000001.SZ'\n    price = khPrice(data, stock, 'close')\n\n    if price == 0: return []\n\n    # \u903b\u8f911\uff1a\u5982\u679c\u672a\u6301\u4ed3\uff0c\u5219\u4f7f\u752850%\u7684\u8d44\u91d1\u4e70\u5165\n    if not khHas(data, stock):\n        # generate_signal\u4f1a\u81ea\u52a8\u8ba1\u7b97\u80a1\u6570\u5e76\u8fd4\u56de\u4fe1\u53f7\u5217\u8868\n        buy_signals = generate_signal(data, stock, price, 0.5, 'buy', \"\u9996\u6b21\u5efa\u4ed3\")\n        signals.extend(buy_signals)\n\n    # \u903b\u8f912\uff1a\u5982\u679c\u5df2\u6301\u4ed3\uff0c\u4e14\u6ee1\u8db3\u67d0\u4e2a\u6761\u4ef6\uff0c\u5219\u5168\u90e8\u5356\u51fa\n    elif should_sell_condition:\n        # ratio=1.0 \u4ee3\u8868\u5168\u4ed3\u5356\u51fa\n        sell_signals = generate_signal(data, stock, price, 1.0, 'sell', \"\u6b62\u76c8\u5356\u51fa\")\n        signals.extend(sell_signals)\n\n    return signals\n<\/code><\/pre>\n<h3><code>round_price(price, decimals)<\/code> &#8211; \u4ef7\u683c\u89c4\u6574 (V2\/V3 \u901a\u7528)<\/h3>\n<p>\u5728\u5b9e\u76d8\u4ea4\u6613\u4e2d\uff0c\u7533\u62a5\u4ef7\u683c\u5fc5\u987b\u7b26\u5408\u4ea4\u6613\u6240\u7684\u6700\u5c0f\u53d8\u52a8\u4ef7\u4f4d\uff08tick size\uff09\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u5c06\u8ba1\u7b97\u51fa\u7684\u7406\u8bba\u4ef7\u683c\u89c4\u6574\u4e3a\u5408\u6cd5\u7684\u7533\u62a5\u4ef7\u683c\u3002<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>round_price(price: float, decimals: int = None, data: Dict = None) -&gt; float<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u5bf9\u4ef7\u683c\u8fdb\u884c\u56db\u820d\u4e94\u5165\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>price<\/code>: \u539f\u59cb\u4ef7\u683c\u3002<\/li>\n<li><code>decimals<\/code>: \u4fdd\u7559\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u5982\u679c\u4e3a <code>None<\/code>\uff0c\u5219\u5c1d\u8bd5\u4ece <code>data<\/code> \u4e2d\u7684\u6846\u67b6\u914d\u7f6e\u81ea\u52a8\u83b7\u53d6\uff0c\u6216\u6839\u636e\u9ed8\u8ba4\u89c4\u5219\uff08\u80a1\u79682\u4f4d\uff0cETF 3\u4f4d\uff09\u5904\u7406\u3002<\/li>\n<li><code>data<\/code>: \u7b56\u7565\u4e0a\u4e0b\u6587\u6570\u636e\uff08\u53ef\u9009\uff0c\u7528\u4e8e\u83b7\u53d6\u914d\u7f6e\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a\u89c4\u6574\u540e\u7684\u4ef7\u683c\u3002<\/li>\n<\/ul>\n<hr \/>\n<h2>6 ETF \u4e13\u5c5e\u5de5\u5177<\/h2>\n<p>\u9488\u5bf9 ETF \u4ea4\u6613\uff0c\u6846\u67b6\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u8f85\u52a9\u51fd\u6570\u3002<\/p>\n<ul>\n<li><strong><code>is_etf(stock_code)<\/code> (V2\/V3 \u901a\u7528)<\/strong>: \u5224\u65ad\u6307\u5b9a\u4ee3\u7801\u662f\u5426\u4e3a ETF \u57fa\u91d1\u3002\n<ul>\n<li>\u793a\u4f8b\uff1a<code>is_etf('510300.SH')<\/code> \u8fd4\u56de <code>True<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>is_t0_etf(stock_code)<\/code> (V3 \u4e13\u7528)<\/strong>: \u5224\u65ad\u6307\u5b9a ETF \u662f\u5426\u652f\u6301 T+0 \u4ea4\u6613\uff08\u5f53\u65e5\u4e70\u5165\u5f53\u65e5\u53ef\u5356\uff09\u3002\n<ul>\n<li>\u793a\u4f8b\uff1a<code>is_t0_etf('159915.SZ')<\/code> \u8fd4\u56de <code>True<\/code>\uff08\u521b\u4e1a\u677fETF\u652f\u6301T+0\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>7 \u5176\u4ed6\u5b9e\u7528\u5de5\u5177<\/h2>\n<h3><code>get_stock_names(stock_codes, stock_list_file)<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>get_stock_names(stock_codes: Union[List[str], str], stock_list_file: str) -&gt; Dict[str, str]<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u6839\u636e\u80a1\u7968\u4ee3\u7801\u5217\u8868\uff0c\u67e5\u8be2\u5e76\u8fd4\u56de\u5bf9\u5e94\u7684\u80a1\u7968\u540d\u79f0\u3002<\/li>\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul>\n<li><code>stock_codes<\/code> (list\/str): \u4e00\u4e2a\u6216\u591a\u4e2a\u80a1\u7968\u4ee3\u7801\u3002<\/li>\n<li><code>stock_list_file<\/code> (str): \u5305\u542b\u80a1\u7968\u4ee3\u7801\u548c\u540d\u79f0\u6620\u5c04\u5173\u7cfb\u7684CSV\u6587\u4ef6\u8def\u5f84\u3002\u901a\u5e38\u662f <code>data\/stock_list\/\u6caa\u6df1A\u80a1_\u80a1\u7968\u5217\u8868.csv<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a\u4e00\u4e2a\u5b57\u5178\uff0c\u952e\u4e3a\u80a1\u7968\u4ee3\u7801\uff0c\u503c\u4e3a\u80a1\u7968\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python line-numbers\">stock_names = get_stock_names(['000001.SZ', '600519.SH'], \"data\/stock_list\/\u6caa\u6df1A\u80a1_\u80a1\u7968\u5217\u8868.csv\")\n# \u8fd4\u56de: {'000001.SZ': '\u5e73\u5b89\u94f6\u884c', '600519.SH': '\u8d35\u5dde\u8305\u53f0'}\nprint(stock_names)\n<\/code><\/pre>\n<h3><code>normalize_stock_code(stock_code)<\/code> (V2\/V3 \u901a\u7528)<\/h3>\n<ul>\n<li><strong>\u51fd\u6570\u7b7e\u540d<\/strong>\uff1a<code>normalize_stock_code(stock_code: str) -&gt; str<\/code><\/li>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u5c06\u5404\u79cd\u683c\u5f0f\u7684\u80a1\u7968\u4ee3\u7801\u7edf\u4e00\u8f6c\u6362\u4e3a\u6807\u51c6\u683c\u5f0f\uff08<code>XXXXXX.SZ<\/code> \u6216 <code>XXXXXX.SH<\/code>\uff09\u3002<\/li>\n<li><strong>\u652f\u6301\u683c\u5f0f<\/strong>\uff1a\n<ul>\n<li><code>\"sh.600000\"<\/code> -> <code>\"600000.SH\"<\/code><\/li>\n<li><code>\"600000\"<\/code> (\u9700\u7ed3\u5408\u4e0a\u4e0b\u6587\uff0c\u6b64\u51fd\u6570\u4e3b\u8981\u5904\u7406\u5e26\u540e\u7f00\u7684\u60c5\u51b5)<\/li>\n<li><code>\"sz000001\"<\/code> -> <code>\"000001.SZ\"<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u8ba9\u7b56\u7565\u7f16\u5199\u66f4\u52a0\u9ad8\u6548\u548c\u4fbf\u6377\uff0c\u770b\u6d77\u91cf\u5316\uff08KHQuant\uff09\u63d0\u4f9b\u4e86\u4e00\u5957\u4e30\u5bcc\u7684\u5185\u7f6e\u51fd\u6570\u5de5\u5177\u7bb1\u3002\u8fd9\u4e9b\u5de5\u5177\u51fd\u6570\u5c01\u88c5\u4e86\u5e38\u89c1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template\/caidan.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-566","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/pages\/566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/comments?post=566"}],"version-history":[{"count":7,"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/pages\/566\/revisions"}],"predecessor-version":[{"id":1012,"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/pages\/566\/revisions\/1012"}],"wp:attachment":[{"href":"https:\/\/khsci.com\/khQuant\/wp-json\/wp\/v2\/media?parent=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}