{"id":337,"date":"2021-10-31T20:19:45","date_gmt":"2021-10-31T12:19:45","guid":{"rendered":"\/?p=337"},"modified":"2023-09-23T19:43:27","modified_gmt":"2023-09-23T11:43:27","slug":"%e5%a4%9a%e8%bf%9b%e7%a8%8b%e7%bb%9f%e8%ae%a1%e7%ad%96%e7%95%a5%e7%9b%88%e4%ba%8f%e5%88%86%e5%b8%83-%e4%bb%8e%e9%9b%b6%e5%88%b0%e5%ae%9e%e7%9b%9812","status":"publish","type":"post","link":"\/?p=337","title":{"rendered":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812"},"content":{"rendered":"<p><a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/coderx.com.cn\/?p=334\">\u524d\u6587<\/a>\u4ecb\u7ecd\u4e86\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u7684\u8fc7\u7a0b\uff0c\u672c\u6587\u5c06\u4f7f\u7528\u591a\u8fdb\u7a0b\u8fdb\u884c\u5b9e\u73b0\u3002\u5728<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/coderx.com.cn\/?p=264\">\u524d\u9762\u6587\u7ae0<\/a>\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u7528\u591a\u8fdb\u7a0b\u521b\u5efa\u80a1\u7968\u6570\u636e\uff0c\u672c\u6587\u591a\u8fdb\u7a0b\u5b9e\u73b0\u7684\u4e3b\u8981\u533a\u522b\u662f\uff0c\u9700\u8981\u4e3b\u8fdb\u7a0b\u83b7\u53d6\u5b50\u8fdb\u7a0b\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<h1>\u4e3b\u8981\u4ee3\u7801\u5206\u6790<\/h1>\n<p>\u65b0\u5efa\u6e90\u6587\u4ef6\uff0c\u547d\u540d\u4e3adata_center_v10.py\uff0c\u5168\u90e8\u5185\u5bb9\u89c1\u6587\u672b\uff0cv10\u4e3b\u8981\u6d89\u53ca3\u4e2a\u65b9\u9762\u6539\u52a8\uff1a<\/p>\n<h3>\u4fee\u6539\u76c8\u4e8f\u7edf\u8ba1\u51fd\u6570<\/h3>\n<pre><code class=\"language-python line-numbers\">def profit_loss_statistic(stock_codes, hold_days=10):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u76c8\u4e8f\u5206\u5e03\u7edf\u8ba1\uff0c\u8ba1\u7b97\u5f53\u65e5candidate\u4e3aTrue\uff0c\u6301\u4ed3hold_days\u5929\u7684\u6536\u76ca\u5206\u5e03\uff0c\u5176\u4e2d\uff1a<br \/>\n&#8211; \u53c2\u6570stock_codes\u4e3a\u5f85\u5206\u6790\u7684\u80a1\u7968\u4ee3\u7801<br \/>\n&#8211; \u53c2\u6570hold_days\u4e3a\u6301\u4ed3\u5929\u6570<br \/>\n&#8211; \u8fd4\u56de\u503c\u4e3a\u7b26\u5408\u4e70\u5165\u6761\u4ef6\u7684\u80a1\u7968DataFrame<\/p>\n<p>\u4f5c\u4e3a\u5b50\u8fdb\u7a0b\u8c03\u7528\u7684\u51fd\u6570\uff0c\u76f8\u8f83\u4e8ev9\uff0cv10\u7248\u672c\u8be5\u51fd\u6570\u6ca1\u6709\u8f93\u51fa\u6570\u636e\u5206\u5e03\u8868\u683c\u53ca\u56fe\u7247\u6587\u4ef6\uff0c\u800c\u662f\u5c06\u7b5b\u9009\u51fa\u7684\u80a1\u7968\u6570\u636e\u505a\u4e3a\u8fd4\u56de\u503c\u8fd4\u56de\uff0c\u4f9b\u4e3b\u8fdb\u7a0b\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    # \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    engine = create_mysql_engine()\n\n    # \u521b\u5efa\u7a7a\u7684DataFrame\n    candidate_df = pd.DataFrame()\n\n    # \u8ba1\u7b97\u6536\u76ca\u5206\u5e03\u5faa\u73af\n    for index, code in enumerate(stock_codes):\n        print('({}\/{})\u6b63\u5728\u5904\u7406{}...'.format(index + 1, len(stock_codes), code))\n\n        # \u80a1\u7968\u6570\u636e\u5728\u6570\u636e\u5e93\u4e2d\u7684\u8868\u540d\n        table_name = '{}_{}'.format(code[3:], code[:2])\n\n        # \u5982\u679c\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u8be5\u80a1\u7968\u6570\u636e\u5219\u8df3\u8fc7\n        if table_name not in sqlalchemy.inspect(engine).get_table_names():\n            continue\n\n        # \u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u7279\u5b9a\u5b57\u6bb5\u6570\u636e\n        cols = 'date, open, high, low, close, candidate'\n        sql_cmd = 'SELECT {} FROM {} ORDER BY date DESC'.format(cols, table_name)\n        df = pd.read_sql(sql=sql_cmd, con=engine)\n\n        # \u79fb\u52a8\u7b2c2\u65e5\u5f00\u76d8\u4ef7\u3001\u6700\u4f4e\u4ef7\uff0c\u4ee5\u53cahold_days\u7684\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u6570\u636e\n        df = shift_i(df, ['open'], 1, suffix='l')\n        df = shift_till_n(df, ['high', 'low'], hold_days, suffix='l')\n\n        # \u4e22\u5f03\u6700\u8fd1hold_days\u65e5\u7684\u6570\u636e\n        df = df.iloc[hold_days: df.shape[0] - g_available_days_limit, :]\n\n        # \u9009\u53d6\u51fa\u73b0\u4e70\u70b9\u7684\u80a1\u7968\n        df = df[(df['candidate'] &gt; 0) &amp; (df['low_1l'] &lt;= df['close'])]\n\n        # \u5c06\u6570\u636e\u6dfb\u52a0\u5230\u5019\u9009\u6c60\u4e2d\n        if df.shape[0]:\n            df['code'] = code\n            candidate_df = candidate_df.append(df)\n\n    if candidate_df.shape[0]:\n        # \u8ba1\u7b97\u6700\u5927\u76c8\u5229\n        # \u4e70\u5165\u5f53\u5929\u65e0\u6cd5\u5356\u51fa\uff0c\u56e0\u6b64\u8ba1\u7b97\u6700\u5927\u6536\u76ca\u65f6\uff0c\u4ece\u7b2c2\u65e5\u5f00\u59cb\n        cols = ['high_{}l'.format(x) for x in range(2, hold_days + 1)]\n        candidate_df['max_high'] = candidate_df[cols].max(axis=1)\n        candidate_df['max_profit'] = candidate_df['max_high'] \/ candidate_df[['open_1l', 'close']].min(axis=1) - 1\n\n        # \u8ba1\u7b97\u6700\u5927\u4e8f\u635f\n        cols = ['low_{}l'.format(x) for x in range(2, hold_days + 1)]\n        candidate_df['min_low'] = candidate_df[cols].min(axis=1)\n        candidate_df['max_loss'] = candidate_df['min_low'] \/ candidate_df[['open_1l', 'close']].min(axis=1) - 1\n<\/code><\/pre>\n<p>\u7edf\u8ba1\u76c8\u4e8f\uff0c\u4e0a\u9762\u4ee3\u7801\u4e0ev9\u5185\u5bb9\u76f8\u540c\uff0c\u53ef\u53c2\u8003<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/coderx.com.cn\/?p=334\">v9\u5206\u6790\u5185\u5bb9<\/a>\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    return candidate_df\n<\/code><\/pre>\n<p>\u8fd4\u56de\u5305\u542b\u76c8\u4e8f\u7edf\u8ba1\u6570\u636e\u7684DataFrame\u3002<\/p>\n<h3>\u65b0\u589e\u591a\u8fdb\u7a0b\u8c03\u7528\u6536\u96c6\u8fd4\u56deDataFrame\u51fd\u6570<\/h3>\n<pre><code class=\"language-python line-numbers\">def multiprocessing_func_df(func, args):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u591a\u8fdb\u7a0b\u8c03\u7528\u51fd\u6570\uff0c\u6536\u96c6\u8fd4\u56de\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u7684DataFrame\uff0c\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u53c2\u6570func\u4e3a\u5b50\u8fdb\u7a0b\u8981\u8c03\u7528\u7684\u51fd\u6570<\/li>\n<li>\u53c2\u6570args\u4e3afunc\u7684\u53c2\u6570\uff0c\u7c7b\u578b\u4e3a\u5143\u7ec4\uff0c\u7b2c0\u4e2a\u5143\u7d20\u4e3a\u8fdb\u7a0b\u6570\uff0c\u7b2c1\u4e2a\u5143\u7d20\u4e3a\u80a1\u7968\u4ee3\u7801\u5217\u8868\uff0c\u5982\u679cfunc\u8fd8\u6709\u5176\u4ed6\u53c2\u6570\uff0c\u5219\u4f9d\u6b21\u5f80\u540e\u6392\u5217<\/li>\n<li>\u8fd4\u56de\u503c\u4e3a\u5305\u542b\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u503c\u7684DataFrame<\/li>\n<\/ul>\n<p>\u8be5\u51fd\u6570\u4e3b\u8981\u662f\u8c03\u7528\u4e86multiprocessing_func\u8fdb\u884c\u591a\u8fdb\u7a0b\u8ba1\u7b97\uff0c\u7531\u4e8e\u7a0b\u5e8f\u4e2d\u6d89\u53ca\u5230\u8f83\u591a\u591a\u8fdb\u7a0b\u8c03\u7528\u6536\u96c6DataFrame\u7684\u529f\u80fd\uff0c\u56e0\u6b64\u62bd\u8c61\u51fa\u6b64\u51fd\u6570\uff0c\u65b9\u4fbf\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    results = multiprocessing_func(func, args)\n<\/code><\/pre>\n<p>\u591a\u8fdb\u7a0b\u8c03\u7528\u51fd\u6570func\uff0c\u83b7\u53d6\u5b50\u8fdb\u7a0b\u8fd4\u56de\u5bf9\u8c61\u7684\u5217\u8868\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    df = pd.DataFrame()\n<\/code><\/pre>\n<p>\u6784\u5efa\u7a7aDataFrame\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    for i in results:\n        df = df.append(i.get())\n<\/code><\/pre>\n<p>\u6536\u96c6\u5404\u8fdb\u7a0b\u8fd4\u56de\u503c\uff0c\u5c06\u83b7\u53d6\u5b50\u8fdb\u7a0b\u8fd4\u56de\u503c\uff0c\u6c47\u603b\u5230df\u3002results\u662f\u6211\u4eec\u6784\u9020\u7684\u4e00\u4e2a\u5217\u8868\uff0c\u5728\u521b\u5efa\u5b50\u8fdb\u7a0b\u65f6\uff0c\u6211\u4eec\u901a\u8fc7append\u65b9\u6cd5\uff0c\u628a\u8fdb\u7a0b\u6c60\u7684apply_async\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u90fd\u6dfb\u52a0\u5230results\u5217\u8868\u4e2d\uff0c\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5bf9results\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u8c03\u7528get\u65b9\u6cd5\uff0c\u6765\u83b7\u53d6\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u8c03\u7528func\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u6700\u540e\u5c06\u6240\u6709\u7ed3\u679c\u6c47\u603b\u5230df\u4e2d\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    return df\n<\/code><\/pre>\n<p>\u8fd4\u56de\u5305\u542b\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u503c\u7684DataFrame\u3002<\/p>\n<h3>\u65b0\u589e\u591a\u8fdb\u7a0b\u76c8\u4e8f\u7edf\u8ba1\u51fd\u6570<\/h3>\n<pre><code class=\"language-python line-numbers\">def profit_loss_statistic_mp(stock_codes, process_num=61, hold_days=10):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u591a\u8fdb\u7a0b\u76c8\u4e8f\u5206\u5e03\u7edf\u8ba1\uff0c\u8ba1\u7b97\u5f53\u65e5candidate\u4e3aTrue\uff0c\u6301\u4ed3hold_days\u5929\u7684\u6536\u76ca\u5206\u5e03\uff0c\u8f93\u51fa\u6570\u636e\u5206\u5e03\u8868\u683c\u53ca\u56fe\u7247\u6587\u4ef6\uff0c\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u53c2\u6570stock_codes\u4e3a\u5f85\u5206\u6790\u7684\u80a1\u7968\u4ee3\u7801<\/li>\n<li>\u53c2\u6570process_num\u4e3a\u8fdb\u7a0b\u6570<\/li>\n<li>\u53c2\u6570hold_days\u4e3a\u6301\u4ed3\u5929\u6570<\/li>\n<li>\u8fd4\u56de\u503c\u4e3a\u7a7a<\/li>\n<\/ul>\n<p>\u5728\u51fd\u6570profit_loss_statistic\u4e2d\uff0c\u6211\u4eec\u5b8c\u6210\u4e86\u5b50\u8fdb\u7a0b\u7684\u8ba1\u7b97\uff0c\u5019\u9009\u7684\u80a1\u7968\u6570\u636e\u88ab\u4fdd\u5b58\u5728candidate_df\u4e2d\u5e76\u8fd4\u56de\u3002\u5728profit_loss_statistic_mp\u4e2d\uff0c\u6211\u4eec\u8981\u6536\u96c6\u8fd9\u4e9bcandidate_df\uff0c\u7136\u540e\u8fdb\u884c\u62fc\u63a5\uff0c\u6700\u540e\u7edf\u8ba1\u6574\u4f53\u7684\u76c8\u4e8f\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        candidate_df = multiprocessing_func_df(profit_loss_statistic, (process_num, stock_codes, hold_days,))\n<\/code><\/pre>\n<p>\u591a\u8fdb\u7a0b\u8ba1\u7b97\u83b7\u5f97\u5019\u9009\u80a1\u7968\u6570\u636e\uff0c\u8c03\u7528multiprocessing_func_df\u51fd\u6570\uff0c\u6536\u96c6\u5b50\u8fdb\u7a0b\u8c03\u7528profit_loss_statistic\u51fd\u6570\u8fd4\u56de\u7684DataFrame\u6570\u636e\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    # \u5c06\u6536\u76ca\u5206\u5e03\u6570\u636e\u4fdd\u5b58\u5230excel\u6587\u4ef6\n    candidate_df[['date', 'code', 'max_profit', 'max_loss']].to_excel(\n        'profit_loss_{}.xlsx'.format(hold_days), index=False, encoding='utf-8')\n\n    # \u91cd\u7f6e\u7d22\u5f15\uff0c\u65b9\u4fbf\u540e\u9762\u7ed8\u56fe\n    candidate_df.reset_index(inplace=True)\n\n    # \u8bbe\u7f6e\u7ed8\u56fe\u683c\u5f0f\u5e76\u7ed8\u56fe\n    fig, ax = plt.subplots(1, 1)\n    table(ax, np.round(candidate_df[['max_profit', 'max_loss']].describe(), 4), loc='upper right',\n          colWidths=[0.2, 0.2, 0.2])\n    candidate_df[['max_profit', 'max_loss']].plot(ax=ax, legend=None)\n\n    # \u4fdd\u5b58\u56fe\u8868\n    fig.savefig('profit_loss_{}.png'.format(hold_days))\n<\/code><\/pre>\n<p>\u8f93\u51fa\u76c8\u4e8f\u7edf\u8ba1\u56fe\u8868\uff0c\u4e0a\u9762\u4ee3\u7801\u4e0ev9\u5185\u5bb9\u76f8\u540c\uff0c\u53ef\u53c2\u8003<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/coderx.com.cn\/?p=334\">v9\u5206\u6790\u5185\u5bb9<\/a>\u3002<\/p>\n<p>\u7ed8\u5236\u56fe\u7247\u7ed3\u679c\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/profit_loss_10.png\" alt=\"\" \/><\/p>\n<h1>\u5c0f\u7ed3<\/h1>\n<p>\u672c\u6587\u5b9e\u73b0\u4e86\u591a\u8fdb\u7a0b\u8ba1\u7b97\u7b56\u7565\u7684\u76c8\u4e8f\u5206\u5e03\uff0c\u4f7f\u7528multiprocessing.Pool.apply_async\u8fdb\u884c\u5b50\u8fdb\u7a0b\u7684\u8ba1\u7b97\uff0c\u5b50\u8fdb\u7a0b\u6709\u8fd4\u56de\u503c\uff0c\u4e3b\u8fdb\u7a0b\u83b7\u53d6\u5b50\u8fdb\u7a0b\u7684\u8fd4\u56de\u5bf9\u8c61\uff08\u975e\u8fd4\u56de\u503c\uff09\uff0c\u7136\u540e\u4f7f\u7528get\u65b9\u6cd5\u83b7\u53d6\u8fd4\u56de\u5bf9\u8c61\u7684\u503c\u3002<\/p>\n<p>\u672c\u6587\u6700\u7ec8\u5f97\u5230\u7684\u8ba1\u7b97\u7ed3\u679c\u4e0e<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/coderx.com.cn\/?p=334\">\u524d\u6587<\/a>\u76f8\u540c\uff0c\u7b56\u7565\u670950%\u6982\u7387\u62ff\u52308.7%\u4ee5\u4e0a\u7684\u76c8\u5229\u3002\u7b26\u5408\u4e70\u5165\u6761\u4ef6\u7684\u80a1\u7968\u6570\u636e\u4fdd\u5b58\u5728<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/profit_loss_10.xlsx\">Excel\u6587\u4ef6<\/a>\u4e2d\uff0c\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u4e0b\u8f7d\u5206\u6790\u53ca\u4f18\u5316\u3002<\/p>\n<p>\u4e0b\u4e00\u7bc7\u6587\u7ae0\u5c06\u8bb0\u5f55\u6309\u65e5\u66f4\u65b0\u6570\u636e\u7684\u8fc7\u7a0b\u3002<\/p>\n<hr \/>\n<p>data_center_v10.py\u7684\u5168\u90e8\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">import baostock as bs\nimport datetime\nimport sys\nimport numpy as np\nimport pandas as pd\nimport multiprocessing\nimport sqlalchemy\nimport matplotlib.pyplot as plt\nfrom pandas.plotting import table\n\n# \u53ef\u7528\u65e5\u7ebf\u6570\u91cf\u7ea6\u675f\ng_available_days_limit = 250\n\n# BaoStock\u65e5\u7ebf\u6570\u636e\u5b57\u6bb5\ng_baostock_data_fields = 'date,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,peTTM,pbMRQ, psTTM,pcfNcfTTM,isST'\n\n\ndef create_mysql_engine():\n    \"\"\"\n    \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n\n    :return: \u65b0\u521b\u5efa\u7684\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    \"\"\"\n\n    # \u5f15\u64ce\u53c2\u6570\u4fe1\u606f\n    host = 'localhost'\n    user = 'root'\n    passwd = '111111'\n    port = '3306'\n    db = 'db_quant'\n\n    # \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    mysql_engine = sqlalchemy.create_engine(\n        'mysql+pymysql:\/\/{0}:{1}@{2}:{3}'.format(user, passwd, host, port),\n        poolclass=sqlalchemy.pool.NullPool\n    )\n\n    # \u5982\u679c\u4e0d\u5b58\u5728\u6570\u636e\u5e93db_quant\u5219\u521b\u5efa\n    mysql_engine.execute(\"CREATE DATABASE IF NOT EXISTS {0} \".format(db))\n\n    # \u521b\u5efa\u8fde\u63a5\u6570\u636e\u5e93db_quant\u7684\u5f15\u64ce\u5bf9\u8c61\n    db_engine = sqlalchemy.create_engine(\n        'mysql+pymysql:\/\/{0}:{1}@{2}:{3}\/{4}?charset=utf8'.format(user, passwd, host, port, db),\n        poolclass=sqlalchemy.pool.NullPool\n    )\n\n    # \u8fd4\u56de\u5f15\u64ce\u5bf9\u8c61\n    return db_engine\n\n\ndef get_stock_codes(date=None, update=False):\n    \"\"\"\n    \u83b7\u53d6\u6307\u5b9a\u65e5\u671f\u7684A\u80a1\u4ee3\u7801\u5217\u8868\n\n    \u82e5\u53c2\u6570update\u4e3aFalse\uff0c\u8868\u793a\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u80a1\u7968\u5217\u8868\n    \u82e5\u6570\u636e\u5e93\u4e2d\u4e0d\u5b58\u5728\u80a1\u7968\u5217\u8868\u7684\u8868\uff0c\u6216\u8005update\u4e3aTrue\uff0c\u5219\u4e0b\u8f7d\u6307\u5b9a\u65e5\u671fdate\u7684\u4ea4\u6613\u80a1\u7968\u5217\u8868\n    \u82e5\u53c2\u6570date\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56de\u6700\u8fd11\u4e2a\u4ea4\u6613\u65e5\u7684A\u80a1\u4ee3\u7801\u5217\u8868\n    \u82e5\u53c2\u6570date\u4e0d\u4e3a\u7a7a\uff0c\u4e14\u4e3a\u4ea4\u6613\u65e5\uff0c\u5219\u8fd4\u56dedate\u5f53\u65e5\u7684A\u80a1\u4ee3\u7801\u5217\u8868\n    \u82e5\u53c2\u6570date\u4e0d\u4e3a\u7a7a\uff0c\u4f46\u4e0d\u4e3a\u4ea4\u6613\u65e5\uff0c\u5219\u6253\u5370\u63d0\u793a\u975e\u4ea4\u6613\u65e5\u4fe1\u606f\uff0c\u7a0b\u5e8f\u9000\u51fa\n\n    :param date: \u65e5\u671f\uff0c\u9ed8\u8ba4\u4e3aNone\n    :param update: \u662f\u5426\u66f4\u65b0\u80a1\u7968\u5217\u8868\uff0c\u9ed8\u8ba4\u4e3aFalse\n    :return: A\u80a1\u4ee3\u7801\u7684\u5217\u8868\n    \"\"\"\n\n    # \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    engine = create_mysql_engine()\n\n    # \u6570\u636e\u5e93\u4e2d\u80a1\u7968\u4ee3\u7801\u7684\u8868\u540d\n    table_name = 'stock_codes'\n\n    # \u6570\u636e\u5e93\u4e2d\u4e0d\u5b58\u5728\u80a1\u7968\u4ee3\u7801\u8868\uff0c\u6216\u8005\u9700\u8981\u66f4\u65b0\u80a1\u7968\u4ee3\u7801\u8868\n    if table_name not in sqlalchemy.inspect(engine).get_table_names() or update:\n\n        # \u767b\u5f55baostock\n        bs.login()\n\n        # \u4eceBaoStock\u67e5\u8be2\u80a1\u7968\u6570\u636e\n        stock_df = bs.query_all_stock(date).get_data()\n\n        # \u5982\u679c\u83b7\u53d6\u6570\u636e\u957f\u5ea6\u4e3a0\uff0c\u8868\u793a\u65e5\u671fdate\u975e\u4ea4\u6613\u65e5\n        if 0 == len(stock_df):\n\n            # \u5982\u679c\u8bbe\u7f6e\u4e86\u53c2\u6570date\uff0c\u5219\u6253\u5370\u4fe1\u606f\u63d0\u793adate\u4e3a\u975e\u4ea4\u6613\u65e5\n            if date is not None:\n                print('\u5f53\u524d\u9009\u62e9\u65e5\u671f\u4e3a\u975e\u4ea4\u6613\u65e5\u6216\u5c1a\u65e0\u4ea4\u6613\u6570\u636e\uff0c\u8bf7\u8bbe\u7f6edate\u4e3a\u5386\u53f2\u67d0\u4ea4\u6613\u65e5\u65e5\u671f')\n                sys.exit(0)\n\n            # \u672a\u8bbe\u7f6e\u53c2\u6570date\uff0c\u5219\u5411\u5386\u53f2\u67e5\u627e\u6700\u8fd1\u7684\u4ea4\u6613\u65e5\uff0c\u5f53\u83b7\u53d6\u80a1\u7968\u6570\u636e\u957f\u5ea6\u975e0\u65f6\uff0c\u5373\u627e\u5230\u6700\u8fd1\u4ea4\u6613\u65e5\n            delta = 1\n            while 0 == len(stock_df):\n                stock_df = bs.query_all_stock(datetime.date.today() - datetime.timedelta(days=delta)).get_data()\n                delta += 1\n\n        # \u6ce8\u9500\u767b\u5f55\n        bs.logout()\n\n        # \u7b5b\u9009\u80a1\u7968\u6570\u636e\uff0c\u4e0a\u8bc1\u548c\u6df1\u8bc1\u80a1\u7968\u4ee3\u7801\u5728sh.600000\u4e0esz.39900\u4e4b\u95f4\n        stock_df = stock_df[(stock_df['code'] &gt;= 'sh.600000') &amp; (stock_df['code'] &lt; 'sz.399000')]\n\n        # \u5c06\u80a1\u7968\u4ee3\u7801\u5199\u5165\u6570\u636e\u5e93\n        stock_df.to_sql(name=table_name, con=engine, if_exists='replace', index=False, index_label=False)\n\n        # \u8fd4\u56de\u80a1\u7968\u5217\u8868\n        return stock_df['code'].tolist()\n\n    # \u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u80a1\u7968\u4ee3\u7801\u5217\u8868\n    else:\n\n        # \u5f85\u6267\u884c\u7684sql\u8bed\u53e5\n        sql_cmd = 'SELECT {} FROM {}'.format('code', table_name)\n\n        # \u8bfb\u53d6sql\uff0c\u8fd4\u56de\u80a1\u7968\u5217\u8868\n        return pd.read_sql(sql=sql_cmd, con=engine)['code'].tolist()\n\n\ndef create_data(stock_codes, from_date='1990-12-19', to_date=datetime.date.today().strftime('%Y-%m-%d'),\n                adjustflag='2'):\n    \"\"\"\n    \u4e0b\u8f7d\u6307\u5b9a\u65e5\u671f\u5185\uff0c\u6307\u5b9a\u80a1\u7968\u7684\u65e5\u7ebf\u6570\u636e\uff0c\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\n\n    :param stock_codes: \u5f85\u4e0b\u8f7d\u6570\u636e\u7684\u80a1\u7968\u4ee3\u7801\n    :param from_date: \u65e5\u7ebf\u5f00\u59cb\u65e5\u671f\n    :param to_date: \u65e5\u7ebf\u7ed3\u675f\u65e5\u671f\n    :param adjustflag: \u590d\u6743\u9009\u9879 1\uff1a\u540e\u590d\u6743  2\uff1a\u524d\u590d\u6743  3\uff1a\u4e0d\u590d\u6743  \u9ed8\u8ba4\u4e3a\u524d\u590d\u6743\n    :return: None\n    \"\"\"\n\n    # \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    engine = create_mysql_engine()\n\n    # \u4e0b\u8f7d\u80a1\u7968\u5faa\u73af\n    for code in stock_codes:\n        print('\u6b63\u5728\u4e0b\u8f7d{}...'.format(code))\n\n        # \u767b\u5f55BaoStock\n        bs.login()\n\n        # \u4e0b\u8f7d\u65e5\u7ebf\u6570\u636e\n        out_df = bs.query_history_k_data_plus(code, g_baostock_data_fields, start_date=from_date, end_date=to_date,\n                                              frequency='d', adjustflag=adjustflag).get_data()\n\n        # \u5254\u9664\u505c\u76d8\u6570\u636e\n        if out_df.shape[0]:\n            out_df = out_df[(out_df['volume'] != '0') &amp; (out_df['volume'] != '')]\n\n        # \u5982\u679c\u6570\u636e\u4e3a\u7a7a\uff0c\u5219\u4e0d\u521b\u5efa\n        if not out_df.shape[0]:\n            continue\n\n        # \u5220\u9664\u91cd\u590d\u6570\u636e\n        out_df.drop_duplicates(['date'], inplace=True)\n\n        # \u65e5\u7ebf\u6570\u636e\u5c11\u4e8eg_available_days_limit\uff0c\u5219\u4e0d\u521b\u5efa\n        if out_df.shape[0] &lt; g_available_days_limit:\n            continue\n\n        # \u5c06\u6570\u503c\u6570\u636e\u8f6c\u4e3afloat\u578b\uff0c\u4fbf\u4e8e\u540e\u7eed\u5904\u7406\n        convert_list = ['open', 'high', 'low', 'close', 'preclose', 'volume', 'amount', 'turn', 'pctChg']\n        out_df[convert_list] = out_df[convert_list].astype(float)\n\n        # \u91cd\u7f6e\u7d22\u5f15\n        out_df.reset_index(drop=True, inplace=True)\n\n        # \u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\n        out_df = extend_factor(out_df)\n\n        # \u5199\u5165\u6570\u636e\u5e93\n        table_name = '{}_{}'.format(code[3:], code[:2])\n        out_df.to_sql(name=table_name, con=engine, if_exists='replace', index=True, index_label='id')\n\n\ndef get_code_group(process_num, stock_codes):\n    \"\"\"\n    \u83b7\u53d6\u4ee3\u7801\u5206\u7ec4\uff0c\u7528\u4e8e\u591a\u8fdb\u7a0b\u8ba1\u7b97\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u5904\u7406\u4e00\u7ec4\u80a1\u7968\n\n    :param process_num: \u8fdb\u7a0b\u6570\n    :param stock_codes: \u5f85\u5904\u7406\u7684\u80a1\u7968\u4ee3\u7801\n    :return: \u5206\u7ec4\u540e\u7684\u80a1\u7968\u4ee3\u7801\u5217\u8868\uff0c\u5217\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u4e3a\u4e00\u7ec4\u80a1\u7968\u4ee3\u7801\u7684\u5217\u8868\n    \"\"\"\n\n    # \u521b\u5efa\u7a7a\u7684\u5206\u7ec4\n    code_group = [[] for i in range(process_num)]\n\n    # \u6309\u4f59\u6570\u4e3a\u6bcf\u4e2a\u5206\u7ec4\u5206\u914d\u80a1\u7968\n    for index, code in enumerate(stock_codes):\n        code_group[index % process_num].append(code)\n\n    return code_group\n\n\ndef multiprocessing_func(func, args):\n    \"\"\"\n    \u591a\u8fdb\u7a0b\u8c03\u7528\u51fd\u6570\n\n    :param func: \u51fd\u6570\u540d\n    :param args: func\u7684\u53c2\u6570\uff0c\u7c7b\u578b\u4e3a\u5143\u7ec4\uff0c\u7b2c0\u4e2a\u5143\u7d20\u4e3a\u8fdb\u7a0b\u6570\uff0c\u7b2c1\u4e2a\u5143\u7d20\u4e3a\u80a1\u7968\u4ee3\u7801\u5217\u8868\n    :return: \u5305\u542b\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u5bf9\u8c61\u7684\u5217\u8868\n    \"\"\"\n\n    # \u7528\u4e8e\u4fdd\u5b58\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u5bf9\u8c61\u7684\u5217\u8868\n    results = []\n\n    # \u521b\u5efa\u8fdb\u7a0b\u6c60\n    with multiprocessing.Pool(processes=args[0]) as pool:\n        # \u591a\u8fdb\u7a0b\u5f02\u6b65\u8ba1\u7b97\n        for codes in get_code_group(args[0], args[1]):\n            results.append(pool.apply_async(func, args=(codes, *args[2:],)))\n\n        # \u963b\u6b62\u540e\u7eed\u4efb\u52a1\u63d0\u4ea4\u5230\u8fdb\u7a0b\u6c60\n        pool.close()\n\n        # \u7b49\u5f85\u6240\u6709\u8fdb\u7a0b\u7ed3\u675f\n        pool.join()\n\n    return results\n\n\ndef create_data_mp(stock_codes, process_num=61,\n                   from_date='1990-12-19', to_date=datetime.date.today().strftime('%Y-%m-%d'), adjustflag='2'):\n    \"\"\"\n    \u4f7f\u7528\u591a\u8fdb\u7a0b\u521b\u5efa\u6307\u5b9a\u65e5\u671f\u5185\uff0c\u6307\u5b9a\u80a1\u7968\u7684\u65e5\u7ebf\u6570\u636e\uff0c\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\n\n    :param stock_codes: \u5f85\u521b\u5efa\u6570\u636e\u7684\u80a1\u7968\u4ee3\u7801\n    :param process_num: \u8fdb\u7a0b\u6570\n    :param from_date: \u65e5\u7ebf\u5f00\u59cb\u65e5\u671f\n    :param to_date: \u65e5\u7ebf\u7ed3\u675f\u65e5\u671f\n    :param adjustflag: \u590d\u6743\u9009\u9879 1\uff1a\u540e\u590d\u6743  2\uff1a\u524d\u590d\u6743  3\uff1a\u4e0d\u590d\u6743  \u9ed8\u8ba4\u4e3a\u524d\u590d\u6743\n    :return: None\n    \"\"\"\n\n    multiprocessing_func(create_data, (process_num, stock_codes, from_date, to_date, adjustflag,))\n\n\ndef extend_factor(df):\n    \"\"\"\n    \u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    # \u4f7f\u7528pipe\u4f9d\u6b21\u8ba1\u7b97\u6da8\u505c\u3001\u53cc\u795e\u53ca\u662f\u5426\u4e3a\u5019\u9009\u80a1\u7968\n    df = df.pipe(zt).pipe(ss, delta_days=30).pipe(candidate)\n\n    return df\n\n\ndef zt(df):\n    \"\"\"\n    \u8ba1\u7b97\u6da8\u505c\u56e0\u5b50\n\n    \u82e5\u6da8\u505c\uff0c\u5219\u56e0\u5b50\u4e3aTrue\uff0c\u5426\u5219\u4e3aFalse\n    \u4ee5\u5f53\u65e5\u6536\u76d8\u4ef7\u8f83\u524d\u4e00\u65e5\u6536\u76d8\u4ef7\u4e0a\u6da89.8%\u53ca\u4ee5\u4e0a\u4f5c\u4e3a\u6da8\u505c\u5224\u65ad\u6807\u51c6\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    df['zt'] = np.where((df['close'].values &gt;= 1.098 * df['preclose'].values), True, False)\n\n    return df\n\n\ndef shift_i(df, factor_list, i, fill_value=0, suffix='a'):\n    \"\"\"\n    \u8ba1\u7b97\u79fb\u52a8\u56e0\u5b50\uff0c\u7528\u4e8e\u83b7\u53d6\u524di\u65e5\u6216\u8005\u540ei\u65e5\u7684\u56e0\u5b50\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param factor_list: \u5f85\u79fb\u52a8\u7684\u56e0\u5b50\u5217\u8868\n    :param i: \u79fb\u52a8\u7684\u6b65\u6570\n    :param fill_value: \u7528\u4e8e\u586b\u5145NA\u7684\u503c\uff0c\u9ed8\u8ba4\u4e3a0\n    :param suffix: \u503c\u4e3aa(ago)\u65f6\u8868\u793a\u79fb\u52a8\u83b7\u5f97\u5386\u53f2\u6570\u636e\uff0c\u7528\u4e8e\u8ba1\u7b97\u6307\u6807\uff1b\u503c\u4e3al(later)\u65f6\u8868\u793a\u83b7\u5f97\u672a\u6765\u6570\u636e\uff0c\u7528\u4e8e\u8ba1\u7b97\u6536\u76ca\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    # \u9009\u53d6\u9700\u8981shift\u7684\u5217\u6784\u6210\u65b0\u7684DataFrame\uff0c\u8fdb\u884cshift\u64cd\u4f5c\n    shift_df = df[factor_list].shift(i, fill_value=fill_value)\n\n    # \u5bf9\u65b0\u7684DataFrame\u5217\u8fdb\u884c\u91cd\u547d\u540d\n    shift_df.rename(columns={x: '{}_{}{}'.format(x, i, suffix) for x in factor_list}, inplace=True)\n\n    # \u5c06\u91cd\u547d\u540d\u540e\u7684DataFrame\u5408\u5e76\u5230\u539f\u59cbDataFrame\u4e2d\n    df = pd.concat([df, shift_df], axis=1)\n\n    return df\n\n\ndef shift_till_n(df, factor_list, n, fill_value=0, suffix='a'):\n    \"\"\"\n    \u8ba1\u7b97\u8303\u56f4\u79fb\u52a8\u56e0\u5b50\n\n    \u7528\u4e8e\u83b7\u53d6\u524d\/\u540en\u65e5\u5185\u7684\u76f8\u5173\u56e0\u5b50\uff0c\u5185\u90e8\u8c03\u7528\u4e86shift_i\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param factor_list: \u5f85\u79fb\u52a8\u7684\u56e0\u5b50\u5217\u8868\n    :param n: \u79fb\u52a8\u7684\u6b65\u6570\u8303\u56f4\n    :param fill_value: \u7528\u4e8e\u586b\u5145NA\u7684\u503c\uff0c\u9ed8\u8ba4\u4e3a0\n    :param suffix: \u503c\u4e3aa(ago)\u65f6\u8868\u793a\u79fb\u52a8\u83b7\u5f97\u5386\u53f2\u6570\u636e\uff0c\u7528\u4e8e\u8ba1\u7b97\u6307\u6807\uff1b\u503c\u4e3al(later)\u65f6\u8868\u793a\u83b7\u5f97\u672a\u6765\u6570\u636e\uff0c\u7528\u4e8e\u8ba1\u7b97\u6536\u76ca\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    for i in range(n):\n        df = shift_i(df, factor_list, i + 1, fill_value, suffix)\n    return df\n\n\ndef ss(df, delta_days=30):\n    \"\"\"\n    \u8ba1\u7b97\u53cc\u795e\u56e0\u5b50\uff0c\u5373\u95f4\u9694\u7684\u4e24\u4e2a\u6da8\u505c\n\n    \u82e5\u5f53\u65e5\u5f62\u6210\u53cc\u795e\uff0c\u5219\u56e0\u5b50\u4e3aTrue\uff0c\u5426\u5219\u4e3aFalse\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param delta_days: \u4e24\u6839\u6da8\u505c\u95f4\u9694\u7684\u65f6\u95f4\u4e0d\u80fd\u8d85\u8fc7\u8be5\u503c\uff0c\u5426\u5219\u4e0d\u5224\u5b9a\u4e3a\u53cc\u795e\uff0c\u9ed8\u8ba4\u503c\u4e3a30\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    # \u79fb\u52a8\u6da8\u505c\u56e0\u5b50\uff0c\u6c42\u53d6\u8fd1delta_days\u5929\u5185\u7684\u6da8\u505c\u60c5\u51b5\uff0c\u4fdd\u5b58\u5728\u4e00\u4e2a\u4e34\u65f6DataFrame\u4e2d\n    temp_df = shift_till_n(df, ['zt'], delta_days, fill_value=False)\n\n    # \u751f\u6210\u5217\u8868\uff0c\u7528\u4e8e\u540e\u7eed\u68c0\u7d22\u7b2c2\u5929\u524d\u81f3\u7b2cdelta_days\u5929\u524d\u662f\u5426\u6709\u6da8\u505c\u51fa\u73b0\n    col_list = ['zt_{}a'.format(x) for x in range(2, delta_days + 1)]\n\n    # \u8ba1\u7b97\u53cc\u795e\uff0c\u9700\u540c\u65f6\u6ee1\u8db33\u4e2a\u6761\u4ef6\uff1a\n    # 1\u3001\u7b2c2\u5929\u524d\u81f3\u7b2cdelta_days\u5929\u524d\uff0c\u81f3\u5c11\u67091\u4e2a\u6da8\u505c\n    # 2\u30011\u5929\u524d\u4e0d\u662f\u6da8\u505c\uff08\u5426\u5219\u5c31\u662f\u8fde\u7eed\u6da8\u505c\uff0c\u4e0d\u662f\u95f4\u9694\u7684\u6da8\u505c\uff09\n    # 3\u3001\u5f53\u5929\u662f\u6da8\u505c\n    df['ss'] = temp_df[col_list].any(axis=1) &amp; ~temp_df['zt_1a'] &amp; temp_df['zt']\n\n    return df\n\n\ndef ma(df, n=5, factor='close'):\n    \"\"\"\n    \u8ba1\u7b97\u5747\u7ebf\u56e0\u5b50\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param n: \u5f85\u8ba1\u7b97\u5747\u7ebf\u7684\u5468\u671f\uff0c\u9ed8\u8ba4\u8ba1\u7b975\u65e5\u5747\u7ebf\n    :param factor: \u5f85\u8ba1\u7b97\u5747\u7ebf\u7684\u56e0\u5b50\uff0c\u9ed8\u8ba4\u4e3a\u6536\u76d8\u4ef7\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    # \u5747\u7ebf\u540d\u79f0\uff0c\u4f8b\u5982\uff0c\u6536\u76d8\u4ef7\u76845\u65e5\u5747\u7ebf\u540d\u79f0\u4e3ama_5\uff0c\u6210\u4ea4\u91cf\u76845\u65e5\u5747\u7ebf\u540d\u79f0\u4e3avolume_ma_5\n    name = '{}ma_{}'.format('' if 'close' == factor else factor + '_', n)\n\n    # \u53d6\u5f85\u8ba1\u7b97\u5747\u7ebf\u7684\u56e0\u5b50\u5217\n    s = pd.Series(df[factor], name=name, index=df.index)\n\n    # \u5229\u7528rolling\u548cmean\u8ba1\u7b97\u5747\u7ebf\u6570\u636e\n    s = s.rolling(center=False, window=n).mean()\n\n    # \u5c06\u5747\u7ebf\u6570\u636e\u6dfb\u52a0\u5230\u539f\u59cb\u7684DataFrame\u4e2d\n    df = df.join(s)\n\n    # \u5747\u7ebf\u6570\u503c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\n    df[name] = df[name].apply(lambda x: round(x + 0.001, 2))\n\n    return df\n\n\ndef mas(df, ma_list, factor='close'):\n    \"\"\"\n    \u8ba1\u7b97\u591a\u6761\u5747\u7ebf\u56e0\u5b50\uff0c\u5185\u90e8\u8c03\u7528ma\u8ba1\u7b97\u5355\u6761\u5747\u7ebf\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param ma_list: \u5f85\u8ba1\u7b97\u5747\u7ebf\u7684\u5468\u671f\u5217\u8868\n    :param factor: \u5f85\u8ba1\u7b97\u5747\u7ebf\u7684\u56e0\u5b50\uff0c\u9ed8\u8ba4\u4e3a\u6536\u76d8\u4ef7\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    for i in ma_list:\n        df = ma(df, i, factor)\n    return df\n\n\ndef cross_mas(df, ma_list):\n    \"\"\"\n    \u8ba1\u7b97\u7a7f\u5747\u7ebf\u56e0\u5b50\n\n    \u82e5\u5f53\u65e5\u6700\u4f4e\u4ef7\u4e0d\u9ad8\u4e8e\u5747\u7ebf\u4ef7\u683c\n    \u4e14\u5f53\u65e5\u6536\u76d8\u4ef7\u4e0d\u4f4e\u4e8e\u5747\u7ebf\u4ef7\u683c\n    \u5219\u5f53\u65e5\u7a7f\u5747\u7ebf\u56e0\u5b50\u503c\u4e3aTrue\uff0c\u5426\u5219\u4e3aFalse\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :param ma_list: \u5747\u7ebf\u7684\u5468\u671f\u5217\u8868\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    for i in ma_list:\n        df['cross_{}'.format(i)] = (df['low'] &lt;= df['ma_{}'.format(i)]) &amp; (\n                df['ma_{}'.format(i)] &lt;= df['close'])\n    return df\n\n\ndef candidate(df):\n    \"\"\"\n    \u8ba1\u7b97\u662f\u5426\u4e3a\u5019\u9009\n\n    \u82e5\u5f53\u65e5\u65e5\u7ebf\u540c\u65f6\u7a7f\u8fc75\u300110\u300120\u300130\u65e5\u5747\u7ebf\n    \u4e1430\u65e5\u5747\u7ebf\u572860\u65e5\u5747\u7ebf\u4e0a\u65b9\n    \u4e14\u5f53\u65e5\u5f62\u6210\u53cc\u795e\n    \u5219\u5f53\u65e5\u4f5c\u4e3a\u5019\u9009\uff0c\u8be5\u56e0\u5b50\u503c\u4e3aTrue\uff0c\u5426\u5219\u4e3aFalse\n\n    :param df: \u5f85\u8ba1\u7b97\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    :return: \u5305\u542b\u6269\u5c55\u56e0\u5b50\u7684DataFrame\n    \"\"\"\n\n    # \u5747\u7ebf\u5468\u671f\u5217\u8868\n    ma_list = [5, 10, 20, 30, 60]\n\n    # \u8ba1\u7b97\u5747\u7ebf\u7684\u56e0\u5b50\uff0c\u4fdd\u5b58\u5230\u4e34\u65f6\u7684DataFrame\u4e2d\n    temp_df = mas(df, ma_list)\n\n    # \u8ba1\u7b97\u7a7f\u591a\u7ebf\u7684\u56e0\u5b50\uff0c\u4fdd\u5b58\u5230\u4e34\u65f6\u7684DataFrame\u4e2d\n    temp_df = cross_mas(temp_df, ma_list)\n\n    # \u7a7f\u591a\u7ebf\u56e0\u5b50\u7684\u5217\u540d\u5217\u8868\n    column_list = ['cross_{}'.format(x) for x in ma_list[:-1]]\n\n    # \u8ba1\u7b97\u662f\u5426\u4e3a\u5019\u9009\n    df['candidate'] = temp_df[column_list].all(axis=1) &amp; (temp_df['ma_30'] &gt;= temp_df['ma_60']) &amp; df['ss']\n\n    return df\n\n\ndef profit_loss_statistic(stock_codes, hold_days=10):\n    \"\"\"\n    \u76c8\u4e8f\u5206\u5e03\u7edf\u8ba1\uff0c\u8ba1\u7b97\u5f53\u65e5candidate\u4e3aTrue\uff0c\u6301\u4ed3hold_days\u5929\u7684\u6536\u76ca\u5206\u5e03\n\n    :param stock_codes: \u5f85\u5206\u6790\u7684\u80a1\u7968\u4ee3\u7801\n    :param hold_days: \u6301\u4ed3\u5929\u6570\n    :return: \u7b5b\u9009\u51fa\u7b26\u5408\u4e70\u5165\u6761\u4ef6\u7684\u80a1\u7968DataFrame\n    \"\"\"\n\n    # \u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce\u5bf9\u8c61\n    engine = create_mysql_engine()\n\n    # \u521b\u5efa\u7a7a\u7684DataFrame\n    candidate_df = pd.DataFrame()\n\n    # \u8ba1\u7b97\u6536\u76ca\u5206\u5e03\u5faa\u73af\n    for index, code in enumerate(stock_codes):\n        print('({}\/{})\u6b63\u5728\u5904\u7406{}...'.format(index + 1, len(stock_codes), code))\n\n        # \u80a1\u7968\u6570\u636e\u5728\u6570\u636e\u5e93\u4e2d\u7684\u8868\u540d\n        table_name = '{}_{}'.format(code[3:], code[:2])\n\n        # \u5982\u679c\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u8be5\u80a1\u7968\u6570\u636e\u5219\u8df3\u8fc7\n        if table_name not in sqlalchemy.inspect(engine).get_table_names():\n            continue\n\n        # \u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u7279\u5b9a\u5b57\u6bb5\u6570\u636e\n        cols = 'date, open, high, low, close, candidate'\n        sql_cmd = 'SELECT {} FROM {} ORDER BY date DESC'.format(cols, table_name)\n        df = pd.read_sql(sql=sql_cmd, con=engine)\n\n        # \u79fb\u52a8\u7b2c2\u65e5\u5f00\u76d8\u4ef7\u3001\u6700\u4f4e\u4ef7\uff0c\u4ee5\u53cahold_days\u7684\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u6570\u636e\n        df = shift_i(df, ['open'], 1, suffix='l')\n        df = shift_till_n(df, ['high', 'low'], hold_days, suffix='l')\n\n        # \u4e22\u5f03\u6700\u8fd1hold_days\u65e5\u7684\u6570\u636e\n        df = df.iloc[hold_days: df.shape[0] - g_available_days_limit, :]\n\n        # \u9009\u53d6\u51fa\u73b0\u4e70\u70b9\u7684\u80a1\u7968\n        df = df[(df['candidate'] &gt; 0) &amp; (df['low_1l'] &lt;= df['close'])]\n\n        # \u5c06\u6570\u636e\u6dfb\u52a0\u5230\u5019\u9009\u6c60\u4e2d\n        if df.shape[0]:\n            df['code'] = code\n            candidate_df = candidate_df.append(df)\n\n    if candidate_df.shape[0]:\n        # \u8ba1\u7b97\u6700\u5927\u76c8\u5229\n        # \u4e70\u5165\u5f53\u5929\u65e0\u6cd5\u5356\u51fa\uff0c\u56e0\u6b64\u8ba1\u7b97\u6700\u5927\u6536\u76ca\u65f6\uff0c\u4ece\u7b2c2\u65e5\u5f00\u59cb\n        cols = ['high_{}l'.format(x) for x in range(2, hold_days + 1)]\n        candidate_df['max_high'] = candidate_df[cols].max(axis=1)\n        candidate_df['max_profit'] = candidate_df['max_high'] \/ candidate_df[['open_1l', 'close']].min(axis=1) - 1\n\n        # \u8ba1\u7b97\u6700\u5927\u4e8f\u635f\n        cols = ['low_{}l'.format(x) for x in range(2, hold_days + 1)]\n        candidate_df['min_low'] = candidate_df[cols].min(axis=1)\n        candidate_df['max_loss'] = candidate_df['min_low'] \/ candidate_df[['open_1l', 'close']].min(axis=1) - 1\n\n    return candidate_df\n\n\ndef multiprocessing_func_df(func, args):\n    \"\"\"\n    \u591a\u8fdb\u7a0b\u8c03\u7528\u51fd\u6570\uff0c\u6536\u96c6\u8fd4\u56de\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u7684DataFrame\n\n    :param func: \u51fd\u6570\u540d\n    :param args: func\u7684\u53c2\u6570\uff0c\u7c7b\u578b\u4e3a\u5143\u7ec4\uff0c\u7b2c0\u4e2a\u5143\u7d20\u4e3a\u8fdb\u7a0b\u6570\uff0c\u7b2c1\u4e2a\u5143\u7d20\u4e3a\u80a1\u7968\u4ee3\u7801\u5217\u8868\n    :return: \u5305\u542b\u5404\u5b50\u8fdb\u7a0b\u8fd4\u56de\u503c\u7684DataFrame\n    \"\"\"\n\n    # \u591a\u8fdb\u7a0b\u8c03\u7528\u51fd\u6570func\uff0c\u83b7\u53d6\u5b50\u8fdb\u7a0b\u8fd4\u56de\u5bf9\u8c61\u7684\u5217\u8868\n    results = multiprocessing_func(func, args)\n\n    # \u6784\u5efa\u7a7aDataFrame\n    df = pd.DataFrame()\n\n    # \u6536\u96c6\u5404\u8fdb\u7a0b\u8fd4\u56de\u503c\n    for i in results:\n        df = df.append(i.get())\n\n    return df\n\n\ndef profit_loss_statistic_mp(stock_codes, process_num=61, hold_days=10):\n    \"\"\"\n    \u591a\u8fdb\u7a0b\u76c8\u4e8f\u5206\u5e03\u7edf\u8ba1\uff0c\u8ba1\u7b97\u5f53\u65e5candidate\u4e3aTrue\uff0c\u6301\u4ed3hold_days\u5929\u7684\u6536\u76ca\u5206\u5e03\n    \u8f93\u51fa\u6570\u636e\u5206\u5e03\u8868\u683c\u53ca\u56fe\u7247\u6587\u4ef6\n\n    :param stock_codes: \u5f85\u5206\u6790\u7684\u80a1\u7968\u4ee3\u7801\n    :param process_num: \u8fdb\u7a0b\u6570\n    :param hold_days: \u6301\u4ed3\u5929\u6570\n    :return: None\n    \"\"\"\n\n    # \u591a\u8fdb\u7a0b\u8ba1\u7b97\u83b7\u5f97\u5019\u9009\u80a1\u7968\u6570\u636e\n    candidate_df = multiprocessing_func_df(profit_loss_statistic, (process_num, stock_codes, hold_days,))\n\n    # \u5c06\u6536\u76ca\u5206\u5e03\u6570\u636e\u4fdd\u5b58\u5230excel\u6587\u4ef6\n    candidate_df[['date', 'code', 'max_profit', 'max_loss']].to_excel(\n        'profit_loss_{}.xlsx'.format(hold_days), index=False, encoding='utf-8')\n\n    # \u91cd\u7f6e\u7d22\u5f15\uff0c\u65b9\u4fbf\u540e\u9762\u7ed8\u56fe\n    candidate_df.reset_index(inplace=True)\n\n    # \u8bbe\u7f6e\u7ed8\u56fe\u683c\u5f0f\u5e76\u7ed8\u56fe\n    fig, ax = plt.subplots(1, 1)\n    table(ax, np.round(candidate_df[['max_profit', 'max_loss']].describe(), 4), loc='upper right',\n          colWidths=[0.2, 0.2, 0.2])\n    candidate_df[['max_profit', 'max_loss']].plot(ax=ax, legend=None)\n\n    # \u4fdd\u5b58\u56fe\u8868\n    fig.savefig('profit_loss_{}.png'.format(hold_days))\n\n    # \u663e\u793a\u56fe\u8868\n    plt.show()\n\n\nif __name__ == '__main__':\n    stock_codes = get_stock_codes()\n    profit_loss_statistic_mp(stock_codes)\n<\/code><\/pre>\n<hr \/>\n<p><strong>\u535a\u5ba2\u5185\u5bb9\u53ea\u7528\u4e8e\u4ea4\u6d41\u5b66\u4e60\uff0c\u4e0d\u6784\u6210\u6295\u8d44\u5efa\u8bae\uff0c\u76c8\u4e8f\u81ea\u8d1f\uff01<\/strong><\/p>\n<p>\u6b22\u8fce\u5927\u5bb6\u8f6c\u53d1\u3001\u7559\u8a00\u3002\u5df2\u5efa\u5fae\u4fe1\u7fa4\u7528\u4e8e\u5b66\u4e60\u4ea4\u6d41\uff0c\u7fa41\u5df2\u6ee1\uff0c\u7fa42\u5df2\u521b\u5efa\uff0c\u611f\u5174\u8da3\u7684\u8bfb\u8005\u8bf7\u626b\u7801\u52a0\u5fae\u4fe1\uff01<\/p>\n<p>\u5982\u679c\u8ba4\u4e3a\u535a\u5ba2\u5bf9\u60a8\u6709\u5e2e\u52a9\uff0c\u53ef\u4ee5\u626b\u7801\u8fdb\u884c\u6350\u8d60\uff0c\u611f\u8c22\uff01<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">\u5fae\u4fe1\u4e8c\u7ef4\u7801<\/th>\n<th align=\"center\">\u5fae\u4fe1\u6350\u8d60\u4e8c\u7ef4\u7801<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\"><img decoding=\"async\" src=\"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/wechat_margin.png\" alt=\"\u5fae\u4fe1\u4e8c\u7ef4\u7801\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"http:\/\/coderx.com.cn\/\/wordpress\/wp-content\/uploads\/2021\/09\/wechatpay.png\" alt=\"\u6350\u8d60\u4e8c\u7ef4\u7801\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<style>\npre{\n    white-space: pre;\n    overflow-x: auto;\n    overflow-y: auto;\n    max-height: 300px;\n}\n.table-wrapper {\n    overflow-x: auto;\n    overflow-y: auto;\n    white-space: nowrap;\n    max-height: 300px;\n}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u6587\u4ecb\u7ecd\u4e86\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u7684\u8fc7\u7a0b\uff0c\u672c\u6587\u5c06\u4f7f\u7528\u591a\u8fdb\u7a0b\u8fdb\u884c\u5b9e\u73b0\u3002\u5728\u524d\u9762\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u7528\u591a\u8fdb\u7a0b\u521b\u5efa\u80a1\u7968\u6570\u636e\uff0c\u672c\u6587 &#8230; <a title=\"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812\" class=\"read-more\" href=\"\/?p=337\" aria-label=\"\u7ee7\u7eed\u9605\u8bfb\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab<\/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:\/\/coderx.com.cn\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab\" \/>\n<meta property=\"og:description\" content=\"\u524d\u6587\u4ecb\u7ecd\u4e86\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u7684\u8fc7\u7a0b\uff0c\u672c\u6587\u5c06\u4f7f\u7528\u591a\u8fdb\u7a0b\u8fdb\u884c\u5b9e\u73b0\u3002\u5728\u524d\u9762\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u7528\u591a\u8fdb\u7a0b\u521b\u5efa\u80a1\u7968\u6570\u636e\uff0c\u672c\u6587 ... \u9605\u8bfb\u66f4\u591a\" \/>\n<meta property=\"og:url\" content=\"\/?p=337\" \/>\n<meta property=\"og:site_name\" content=\"Python\u91cf\u5316\u6280\u672f\u5206\u4eab\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-31T12:19:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-23T11:43:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/profit_loss_10.png\" \/>\n<meta name=\"author\" content=\"mnj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"mnj\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/coderx.com.cn\/#article\",\"isPartOf\":{\"@id\":\"\/?p=337\"},\"author\":{\"name\":\"mnj\",\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3\"},\"headline\":\"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812\",\"datePublished\":\"2021-10-31T12:19:45+00:00\",\"dateModified\":\"2023-09-23T11:43:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"\/?p=337\"},\"wordCount\":85,\"commentCount\":8,\"publisher\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3\"},\"articleSection\":[\"\u4ece\u96f6\u5230\u5b9e\u76d8\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/coderx.com.cn\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"\/?p=337\",\"url\":\"http:\/\/coderx.com.cn\/\",\"name\":\"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab\",\"isPartOf\":{\"@id\":\"http:\/\/coderx.com.cn\/#website\"},\"datePublished\":\"2021-10-31T12:19:45+00:00\",\"dateModified\":\"2023-09-23T11:43:27+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/coderx.com.cn\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/coderx.com.cn\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/coderx.com.cn\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/coderx.com.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/coderx.com.cn\/#website\",\"url\":\"http:\/\/coderx.com.cn\/\",\"name\":\"Python\u91cf\u5316\u6280\u672f\u5206\u4eab-\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0\",\"description\":\"\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0\",\"publisher\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/coderx.com.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3\",\"name\":\"mnj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/\",\"url\":\"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg\",\"contentUrl\":\"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg\",\"width\":951,\"height\":189,\"caption\":\"mnj\"},\"logo\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","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:\/\/coderx.com.cn\/","og_locale":"zh_CN","og_type":"article","og_title":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","og_description":"\u524d\u6587\u4ecb\u7ecd\u4e86\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u7684\u8fc7\u7a0b\uff0c\u672c\u6587\u5c06\u4f7f\u7528\u591a\u8fdb\u7a0b\u8fdb\u884c\u5b9e\u73b0\u3002\u5728\u524d\u9762\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u7528\u591a\u8fdb\u7a0b\u521b\u5efa\u80a1\u7968\u6570\u636e\uff0c\u672c\u6587 ... \u9605\u8bfb\u66f4\u591a","og_url":"\/?p=337","og_site_name":"Python\u91cf\u5316\u6280\u672f\u5206\u4eab","article_published_time":"2021-10-31T12:19:45+00:00","article_modified_time":"2023-09-23T11:43:27+00:00","og_image":[{"url":"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/profit_loss_10.png"}],"author":"mnj","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"mnj","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/coderx.com.cn\/#article","isPartOf":{"@id":"\/?p=337"},"author":{"name":"mnj","@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3"},"headline":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812","datePublished":"2021-10-31T12:19:45+00:00","dateModified":"2023-09-23T11:43:27+00:00","mainEntityOfPage":{"@id":"\/?p=337"},"wordCount":85,"commentCount":8,"publisher":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3"},"articleSection":["\u4ece\u96f6\u5230\u5b9e\u76d8"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/coderx.com.cn\/#respond"]}]},{"@type":"WebPage","@id":"\/?p=337","url":"http:\/\/coderx.com.cn\/","name":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","isPartOf":{"@id":"http:\/\/coderx.com.cn\/#website"},"datePublished":"2021-10-31T12:19:45+00:00","dateModified":"2023-09-23T11:43:27+00:00","breadcrumb":{"@id":"http:\/\/coderx.com.cn\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/coderx.com.cn\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/coderx.com.cn\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/coderx.com.cn\/"},{"@type":"ListItem","position":2,"name":"\u591a\u8fdb\u7a0b\u7edf\u8ba1\u7b56\u7565\u76c8\u4e8f\u5206\u5e03\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d812"}]},{"@type":"WebSite","@id":"http:\/\/coderx.com.cn\/#website","url":"http:\/\/coderx.com.cn\/","name":"Python\u91cf\u5316\u6280\u672f\u5206\u4eab-\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0","description":"\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0","publisher":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/coderx.com.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/4f9a19aed18c75500a890ab51b762ad3","name":"mnj","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/","url":"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg","contentUrl":"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg","width":951,"height":189,"caption":"mnj"},"logo":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":7,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":500,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/500"}],"wp:attachment":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}