{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "8721fe9f-083b-4ba3-8380-31dc4e541e27", "metadata": {}, "outputs": [], "source": [ "import time\n", "from tqdm import tqdm\n", "import itertools\n", "\n", "import numpy as np\n", "import pandas as pd\n", "from pprint import pprint\n", "\n", "import pyTSL\n", "\n", "TINYSOFT_HOSTNAME = 'tsl.tinysoft.com.cn'\n", "TINYSOFT_PORT = 443\n", "TINYSOFT_USERNAME = 'xunuo2005'\n", "TINYSOFT_PASSWORD = '20220613'\n", "\n", "TINYSOFT_DATA_PATH = 'tinysoft-data'\n", "\n", "\n", "class tsl():\n", " \n", " def __enter__(self):\n", " self.c = pyTSL.Client(TINYSOFT_USERNAME, TINYSOFT_PASSWORD, TINYSOFT_HOSTNAME, 443)\n", " self.c.login()\n", " return self\n", " \n", " \n", " def __exit__(self, exc_type, exc_val, exc_tb):\n", " self.c.logout()\n", " \n", " \n", " def get_stock_list(self, date, bk_name='A股'):\n", " code = \"\"\"\n", " bkName := \"%s\";\n", " endT := %d;\n", " return getAbkbydate(bkName,endT);\n", " \"\"\" % (bk_name, date)\n", " r = self.c.exec(code)\n", " \n", " return r.value()\n", " \n", "\n", " def get_cmp_report(self, table_id, stock_id, start_date):\n", " code = \"\"\"\n", " SetSysParam('ReportMode', -1);\n", " return Select * \n", " from infotable {table_id} of '{stock_id}' \n", " where ['截止日'] >= {start_date}\n", " end;\n", " \"\"\".format(\n", " table_id=table_id, \n", " stock_id=stock_id, \n", " start_date=start_date\n", " )\n", " r = self.c.exec(code)\n", "\n", " df = pd.DataFrame(r.value())\n", " return df\n", " \n", " \n", " def get_cmp_indicator(self, stock_id, start_year, indicator_config_fname):\n", " index_list = ['StockID', '报告期']\n", " \n", " year_list = range(start_year, 2022, 1)\n", " quarter_list = ['0331', '0630', '0930', '1231']\n", " report_date_list = [str(t[0]) + t[1] for t in itertools.product(year_list, quarter_list)]\n", " \n", " config_df = pd.read_csv(indicator_config_fname)\n", " config_df['indicator_id'] = config_df['indicator_id'].astype('string')\n", " indicator_dict = config_df.set_index('indicator_id')['indicator_name'].to_dict()\n", " indicator_id_list = list(indicator_dict.keys())\n", " indicator_name_list = [\"'%s'\" % indicator_dict[indicator_id].strip() for indicator_id in indicator_id_list]\n", " \n", " code = \"\"\"\n", " SetSysParam('ReportMode', -1);\n", " SetSysParam(pn_reportmode(), -1);\n", " SetSysParam(pn_stock(), '{stock_id}');\n", "\n", " date_array := Array({date_list_input});\n", " indicator_array := Array({indicator_id_list_input});\n", " indicator_name_array := Array({indicator_name_list_input});\n", " r := Array();\n", " \n", " for i:=0 to length(date_array)-1 do\n", " begin\n", " r[i]['StockID'] := '{stock_id}';\n", " r[i]['报告期'] := date_array[i];\n", " for j:=0 to length(indicator_array)-1 do\n", " begin\n", " r[i][indicator_name_array[j]] := ReportOfAll(indicator_array[j], date_array[i]);\n", " end\n", " end\n", " return r;\n", " \"\"\".format(\n", " stock_id=stock_id, \n", " date_list_input=', '.join(report_date_list),\n", " indicator_id_list_input=', '.join(indicator_id_list),\n", " indicator_name_list_input=', '.join(indicator_name_list)\n", " )\n", " r = self.c.exec(code)\n", " r = r.value()\n", " df = pd.DataFrame(r, index=range(len(r)))\n", " df.set_index(index_list, inplace=True)\n", " return df\n", "\n", " \n", " def get_mkt_trading_days(self, start_date, end_date):\n", " # TradeDays: \n", " # nday3: 返回用第二个参数计算N日的一维数字下标数组。\n", " # SpecDate: 临时修改当前时间的快捷方法\n", " # Spec: 指定StockID股票为当前股票,计算表达式的值返回\n", " code = \"\"\"\n", " begt:=inttodate(%d);\n", " endt:=inttodate(%d);\n", " return spec(specdate(nday3(tradedays(begt,endt),DateToInt(sp_time())),endt),'SH000001');\n", " \"\"\" % (start_date, end_date);\n", " r = self.c.exec(code)\n", " \n", " return r.value()\n", " \n", " \n", " def get_mkt_stock_k_daily(self, start_date, end_date, stock_id): \n", " # vol: 成交量\n", " # amount: 成交金额\n", " # cjbs: 成交笔数\n", " # yclose: 上次价\n", " code = \"\"\"\n", " SetSysParam(pn_cycle(),cy_day());\n", " return \n", " select \n", " ['StockID'],\n", " datetoint(['date']) as 'date',\n", " ['open'],\n", " ['high'],\n", " ['low'],\n", " ['close'], \n", " ['vol'], \n", " ['amount'], \n", " ['cjbs'],\n", " ['yclose']\n", " from markettable \n", " datekey {start_date}T to {end_date}T+0.999 \n", " of \\'{stock_id}\\'\n", " end;\n", " \"\"\".format(\n", " stock_id=stock_id, \n", " start_date=start_date,\n", " end_date=end_date\n", " )\n", " r = self.c.exec(code)\n", " df = pd.DataFrame(r.value())\n", " df.set_index(['StockID', 'date'], inplace=True)\n", " return df\n", " \n", "\n", " def get_mkt_stock_k_daily_ext(self, start_date, end_date, stock_id):\n", " \n", " date_list = self.get_mkt_trading_days(start_date, end_date)\n", " \n", " # IsSt_3: 是否是ST(指定日),判断当前股票在指定日是否是ST股。函数主要是通过名称变更进行判断。 \n", " # Stockzf3:涨幅(%) =(收盘-昨收)/昨收*100%(已复权)\n", " # http://www.tinysoft.com.cn/tsdn/helpdoc/display.tsl?id=12582\n", " # AuthorityFactor: 以上市日为复权基准日,向后复权,得到指定日比例复权方式的复权因子值,即复权方式为1。调用该函数需注意设置当前股票和当前时间。\n", " code = \"\"\"\n", " SetSysParam(pn_cycle(),cy_day());\n", " SetSysParam(pn_stock(), \\'{stock_id}\\');\n", " \n", " date_array := Array({date_list_input});\n", " r := Array();\n", " \n", " for i:=0 to length(date_array)-1 do\n", " begin\n", " SetSysParam(PN_Date(), inttodate(date_array[i]));\n", " \n", " r[i]['StockID'] := \\'{stock_id}\\';\n", " r[i]['date'] := date_array[i];\n", " r[i]['PctChg'] := StockZf3();\n", " r[i]['IsST'] := IsST_3(date_array[i]);\n", " r[i]['FloatShares'] := StockNegotiableShares(date_array[i]);\n", " r[i]['Factor'] := AuthorityFactor();\n", " end;\n", " return r;\n", " \"\"\".format(\n", " stock_id=stock_id,\n", " date_list_input=', '.join([str(date) for date in date_list])\n", " )\n", " r = self.c.exec(code)\n", "\n", " df = pd.DataFrame(r.value(), index=range(len(r.value())))\n", " df.set_index(['StockID', 'date'], inplace=True)\n", " return df\n", " \n", " \n", " def get_fund_info(self, table_id, fund_id):\n", " code = \"\"\"\n", " SetSysParam('ReportMode', -1);\n", " return Select * \n", " from infotable {table_id} of '{fund_id}' \n", " end;\n", " \"\"\".format(\n", " table_id=table_id, \n", " fund_id=fund_id\n", " )\n", " r = self.c.exec(code)\n", "\n", " df = pd.DataFrame(r.value())\n", " return df\n", " \n", " \n", " def get_fund_list(self, date):\n", " pass\n", "\n" ] }, { "cell_type": "code", "execution_count": 22, "id": "f71302c9-af94-4cc4-942a-281e76468470", "metadata": {}, "outputs": [], "source": [ "with tsl() as t:\n", " df1 = t.get_mkt_stock_k_daily(20220501, 20220609, 'SZ000012')\n", " df2 = t.get_mkt_stock_k_daily_ext(20220501, 20220609, 'SZ000012')\n", " df = pd.concat([df1, df2], axis=1)\n" ] }, { "cell_type": "code", "execution_count": 23, "id": "9ff6c11f-6038-43cf-bd80-a2a3fa09e733", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
closevollowyclosecjbsamounthighopenIsSTFactorPctChgFloatShares
StockIDdate
SZ000012202205055.7852548342.05.615.6247277.03.036327e+085.885.6300.0306672.8469751.956586e+09
202205065.6430434955.05.555.7837648.01.721508e+085.775.6500.030667-2.4221451.956586e+09
202205095.6826512956.05.615.6431115.01.513519e+085.815.6200.0306670.7092201.956586e+09
202205105.7644880370.05.555.6839085.02.556482e+085.775.5800.0306671.4084511.956586e+09
202205115.8263441266.05.805.7650303.03.741822e+086.025.8100.0306671.0416671.956586e+09
202205125.8340711757.05.725.8230591.02.373038e+085.935.8200.0306670.1718211.956586e+09
202205135.9544013643.05.815.8332703.02.597157e+085.975.8900.0306672.0583191.956586e+09
202205165.8051952217.05.765.9546334.03.046104e+086.056.0000.030667-2.5210081.956586e+09
202205175.8837310901.05.675.8033021.02.155254e+085.885.8200.0306671.3793101.956586e+09
202205185.9243071593.05.825.8836175.02.553750e+086.025.8700.0306670.6802721.956586e+09
202205196.0971322634.05.775.9255347.04.292484e+086.205.8100.0306672.8716221.956586e+09
202205206.1563335796.06.036.0947644.03.862153e+086.166.1100.0306670.9852221.956586e+09
202205236.1744809479.06.106.1533057.02.758453e+086.236.1900.0306670.3252031.956586e+09
202205245.9367558001.05.916.1748715.04.162481e+086.376.1800.030667-3.8897891.956586e+09
202205256.0237408360.05.895.9328801.02.233981e+086.025.9700.0306671.5177071.956586e+09
202205266.0631951823.05.916.0228125.01.925206e+086.116.0400.0306670.6644521.956586e+09
202205276.0731871879.05.986.0626731.01.931219e+086.126.0900.0306670.1650171.956586e+09
202205306.1227955000.06.036.0723213.01.700274e+086.136.1100.0306670.8237231.956586e+09
202205316.2250331033.06.066.1237964.03.103057e+086.246.1700.0306671.6339871.956586e+09
202206016.1535835989.06.116.2229394.02.208082e+086.226.2200.030667-1.1254021.956586e+09
202206026.3157818462.06.086.1539913.03.613558e+086.356.1300.0306672.6016261.956586e+09
202206066.3549949153.06.236.3140078.03.153994e+086.386.2900.0306670.6339141.956586e+09
202206076.3968554508.06.326.3546616.04.418079e+086.596.4400.0306670.6299211.956586e+09
202206086.3355527059.06.206.3938473.03.512041e+086.426.3500.030667-0.9389671.956586e+09
202206096.1834466429.06.136.3328828.02.143454e+086.326.3200.030667-2.3696681.956586e+09
\n", "
" ], "text/plain": [ " close vol low yclose cjbs amount \\\n", "StockID date \n", "SZ000012 20220505 5.78 52548342.0 5.61 5.62 47277.0 3.036327e+08 \n", " 20220506 5.64 30434955.0 5.55 5.78 37648.0 1.721508e+08 \n", " 20220509 5.68 26512956.0 5.61 5.64 31115.0 1.513519e+08 \n", " 20220510 5.76 44880370.0 5.55 5.68 39085.0 2.556482e+08 \n", " 20220511 5.82 63441266.0 5.80 5.76 50303.0 3.741822e+08 \n", " 20220512 5.83 40711757.0 5.72 5.82 30591.0 2.373038e+08 \n", " 20220513 5.95 44013643.0 5.81 5.83 32703.0 2.597157e+08 \n", " 20220516 5.80 51952217.0 5.76 5.95 46334.0 3.046104e+08 \n", " 20220517 5.88 37310901.0 5.67 5.80 33021.0 2.155254e+08 \n", " 20220518 5.92 43071593.0 5.82 5.88 36175.0 2.553750e+08 \n", " 20220519 6.09 71322634.0 5.77 5.92 55347.0 4.292484e+08 \n", " 20220520 6.15 63335796.0 6.03 6.09 47644.0 3.862153e+08 \n", " 20220523 6.17 44809479.0 6.10 6.15 33057.0 2.758453e+08 \n", " 20220524 5.93 67558001.0 5.91 6.17 48715.0 4.162481e+08 \n", " 20220525 6.02 37408360.0 5.89 5.93 28801.0 2.233981e+08 \n", " 20220526 6.06 31951823.0 5.91 6.02 28125.0 1.925206e+08 \n", " 20220527 6.07 31871879.0 5.98 6.06 26731.0 1.931219e+08 \n", " 20220530 6.12 27955000.0 6.03 6.07 23213.0 1.700274e+08 \n", " 20220531 6.22 50331033.0 6.06 6.12 37964.0 3.103057e+08 \n", " 20220601 6.15 35835989.0 6.11 6.22 29394.0 2.208082e+08 \n", " 20220602 6.31 57818462.0 6.08 6.15 39913.0 3.613558e+08 \n", " 20220606 6.35 49949153.0 6.23 6.31 40078.0 3.153994e+08 \n", " 20220607 6.39 68554508.0 6.32 6.35 46616.0 4.418079e+08 \n", " 20220608 6.33 55527059.0 6.20 6.39 38473.0 3.512041e+08 \n", " 20220609 6.18 34466429.0 6.13 6.33 28828.0 2.143454e+08 \n", "\n", " high open IsST Factor PctChg FloatShares \n", "StockID date \n", "SZ000012 20220505 5.88 5.63 0 0.030667 2.846975 1.956586e+09 \n", " 20220506 5.77 5.65 0 0.030667 -2.422145 1.956586e+09 \n", " 20220509 5.81 5.62 0 0.030667 0.709220 1.956586e+09 \n", " 20220510 5.77 5.58 0 0.030667 1.408451 1.956586e+09 \n", " 20220511 6.02 5.81 0 0.030667 1.041667 1.956586e+09 \n", " 20220512 5.93 5.82 0 0.030667 0.171821 1.956586e+09 \n", " 20220513 5.97 5.89 0 0.030667 2.058319 1.956586e+09 \n", " 20220516 6.05 6.00 0 0.030667 -2.521008 1.956586e+09 \n", " 20220517 5.88 5.82 0 0.030667 1.379310 1.956586e+09 \n", " 20220518 6.02 5.87 0 0.030667 0.680272 1.956586e+09 \n", " 20220519 6.20 5.81 0 0.030667 2.871622 1.956586e+09 \n", " 20220520 6.16 6.11 0 0.030667 0.985222 1.956586e+09 \n", " 20220523 6.23 6.19 0 0.030667 0.325203 1.956586e+09 \n", " 20220524 6.37 6.18 0 0.030667 -3.889789 1.956586e+09 \n", " 20220525 6.02 5.97 0 0.030667 1.517707 1.956586e+09 \n", " 20220526 6.11 6.04 0 0.030667 0.664452 1.956586e+09 \n", " 20220527 6.12 6.09 0 0.030667 0.165017 1.956586e+09 \n", " 20220530 6.13 6.11 0 0.030667 0.823723 1.956586e+09 \n", " 20220531 6.24 6.17 0 0.030667 1.633987 1.956586e+09 \n", " 20220601 6.22 6.22 0 0.030667 -1.125402 1.956586e+09 \n", " 20220602 6.35 6.13 0 0.030667 2.601626 1.956586e+09 \n", " 20220606 6.38 6.29 0 0.030667 0.633914 1.956586e+09 \n", " 20220607 6.59 6.44 0 0.030667 0.629921 1.956586e+09 \n", " 20220608 6.42 6.35 0 0.030667 -0.938967 1.956586e+09 \n", " 20220609 6.32 6.32 0 0.030667 -2.369668 1.956586e+09 " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 14, "id": "cbbd95e0-0734-46c7-a314-a11e0a882bbc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclosevollowycloseStockIDcjbsamounthighopen
0202205055.7852548342.05.615.62SZ00001247277.03.036327e+085.885.63
1202205065.6430434955.05.555.78SZ00001237648.01.721508e+085.775.65
2202205095.6826512956.05.615.64SZ00001231115.01.513519e+085.815.62
3202205105.7644880370.05.555.68SZ00001239085.02.556482e+085.775.58
4202205115.8263441266.05.805.76SZ00001250303.03.741822e+086.025.81
5202205125.8340711757.05.725.82SZ00001230591.02.373038e+085.935.82
6202205135.9544013643.05.815.83SZ00001232703.02.597157e+085.975.89
7202205165.8051952217.05.765.95SZ00001246334.03.046104e+086.056.00
8202205175.8837310901.05.675.80SZ00001233021.02.155254e+085.885.82
9202205185.9243071593.05.825.88SZ00001236175.02.553750e+086.025.87
10202205196.0971322634.05.775.92SZ00001255347.04.292484e+086.205.81
11202205206.1563335796.06.036.09SZ00001247644.03.862153e+086.166.11
12202205236.1744809479.06.106.15SZ00001233057.02.758453e+086.236.19
13202205245.9367558001.05.916.17SZ00001248715.04.162481e+086.376.18
14202205256.0237408360.05.895.93SZ00001228801.02.233981e+086.025.97
15202205266.0631951823.05.916.02SZ00001228125.01.925206e+086.116.04
16202205276.0731871879.05.986.06SZ00001226731.01.931219e+086.126.09
17202205306.1227955000.06.036.07SZ00001223213.01.700274e+086.136.11
18202205316.2250331033.06.066.12SZ00001237964.03.103057e+086.246.17
19202206016.1535835989.06.116.22SZ00001229394.02.208082e+086.226.22
20202206026.3157818462.06.086.15SZ00001239913.03.613558e+086.356.13
21202206066.3549949153.06.236.31SZ00001240078.03.153994e+086.386.29
22202206076.3968554508.06.326.35SZ00001246616.04.418079e+086.596.44
23202206086.3355527059.06.206.39SZ00001238473.03.512041e+086.426.35
24202206096.1834466429.06.136.33SZ00001228828.02.143454e+086.326.32
\n", "
" ], "text/plain": [ " date close vol low yclose StockID cjbs \\\n", "0 20220505 5.78 52548342.0 5.61 5.62 SZ000012 47277.0 \n", "1 20220506 5.64 30434955.0 5.55 5.78 SZ000012 37648.0 \n", "2 20220509 5.68 26512956.0 5.61 5.64 SZ000012 31115.0 \n", "3 20220510 5.76 44880370.0 5.55 5.68 SZ000012 39085.0 \n", "4 20220511 5.82 63441266.0 5.80 5.76 SZ000012 50303.0 \n", "5 20220512 5.83 40711757.0 5.72 5.82 SZ000012 30591.0 \n", "6 20220513 5.95 44013643.0 5.81 5.83 SZ000012 32703.0 \n", "7 20220516 5.80 51952217.0 5.76 5.95 SZ000012 46334.0 \n", "8 20220517 5.88 37310901.0 5.67 5.80 SZ000012 33021.0 \n", "9 20220518 5.92 43071593.0 5.82 5.88 SZ000012 36175.0 \n", "10 20220519 6.09 71322634.0 5.77 5.92 SZ000012 55347.0 \n", "11 20220520 6.15 63335796.0 6.03 6.09 SZ000012 47644.0 \n", "12 20220523 6.17 44809479.0 6.10 6.15 SZ000012 33057.0 \n", "13 20220524 5.93 67558001.0 5.91 6.17 SZ000012 48715.0 \n", "14 20220525 6.02 37408360.0 5.89 5.93 SZ000012 28801.0 \n", "15 20220526 6.06 31951823.0 5.91 6.02 SZ000012 28125.0 \n", "16 20220527 6.07 31871879.0 5.98 6.06 SZ000012 26731.0 \n", "17 20220530 6.12 27955000.0 6.03 6.07 SZ000012 23213.0 \n", "18 20220531 6.22 50331033.0 6.06 6.12 SZ000012 37964.0 \n", "19 20220601 6.15 35835989.0 6.11 6.22 SZ000012 29394.0 \n", "20 20220602 6.31 57818462.0 6.08 6.15 SZ000012 39913.0 \n", "21 20220606 6.35 49949153.0 6.23 6.31 SZ000012 40078.0 \n", "22 20220607 6.39 68554508.0 6.32 6.35 SZ000012 46616.0 \n", "23 20220608 6.33 55527059.0 6.20 6.39 SZ000012 38473.0 \n", "24 20220609 6.18 34466429.0 6.13 6.33 SZ000012 28828.0 \n", "\n", " amount high open \n", "0 3.036327e+08 5.88 5.63 \n", "1 1.721508e+08 5.77 5.65 \n", "2 1.513519e+08 5.81 5.62 \n", "3 2.556482e+08 5.77 5.58 \n", "4 3.741822e+08 6.02 5.81 \n", "5 2.373038e+08 5.93 5.82 \n", "6 2.597157e+08 5.97 5.89 \n", "7 3.046104e+08 6.05 6.00 \n", "8 2.155254e+08 5.88 5.82 \n", "9 2.553750e+08 6.02 5.87 \n", "10 4.292484e+08 6.20 5.81 \n", "11 3.862153e+08 6.16 6.11 \n", "12 2.758453e+08 6.23 6.19 \n", "13 4.162481e+08 6.37 6.18 \n", "14 2.233981e+08 6.02 5.97 \n", "15 1.925206e+08 6.11 6.04 \n", "16 1.931219e+08 6.12 6.09 \n", "17 1.700274e+08 6.13 6.11 \n", "18 3.103057e+08 6.24 6.17 \n", "19 2.208082e+08 6.22 6.22 \n", "20 3.613558e+08 6.35 6.13 \n", "21 3.153994e+08 6.38 6.29 \n", "22 4.418079e+08 6.59 6.44 \n", "23 3.512041e+08 6.42 6.35 \n", "24 2.143454e+08 6.32 6.32 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1" ] }, { "cell_type": "code", "execution_count": 7, "id": "8ebd92ac-9831-4f66-9614-8cf06a73033c", "metadata": {}, "outputs": [], "source": [ "def dump_to_csv(path_template, path_args={}):\n", " def inner(func):\n", " def func_wrapper(*args, **kwargs):\n", " r = func(*args, **kwargs)\n", " print(path_template.format(**path_args))\n", " print('Will dump to a csv file...')\n", " return r\n", " return func_wrapper\n", " return inner" ] }, { "cell_type": "code", "execution_count": 8, "id": "36926197-5016-459b-a91d-5f2486ff600b", "metadata": {}, "outputs": [], "source": [ "@dump_to_csv(path_template='aaa{name}dd', path_args={'name':'ccc'})\n", "def dump_test():\n", " print('do test')" ] }, { "cell_type": "code", "execution_count": 9, "id": "389c2c4a-6e7d-45ad-9da1-780dffab3371", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "do test\n", "aaacccdd\n", "Will dump to a csv file...\n" ] } ], "source": [ "dump_test()" ] }, { "cell_type": "code", "execution_count": 34, "id": "0c5b725b-7ad7-4466-ba3c-ec6624c2575d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Inside decorator\n", "Inside inner function\n", "I like geeksforgeeks\n", "Inside actual function\n" ] } ], "source": [ "def decorator(*args, **kwargs):\n", " print(\"Inside decorator\")\n", " \n", " def inner(func):\n", " \n", " # code functionality here\n", " print(\"Inside inner function\")\n", " print(\"I like\", kwargs['like'])\n", " \n", " func()\n", " \n", " # returning inner function \n", " return inner\n", " \n", "@decorator(like = \"geeksforgeeks\")\n", "def my_func():\n", " print(\"Inside actual function\")" ] }, { "cell_type": "code", "execution_count": 17, "id": "c7ec2d92-5d6b-4b0c-afa0-d0210b64e0df", "metadata": {}, "outputs": [], "source": [ "with tsl() as t:\n", " date_list = t.get_mkt_trading_days(20000101,20220620)\n", " s = pd.Series(date_list, dtype=np.int64, name='date')" ] }, { "cell_type": "code", "execution_count": 19, "id": "dd10b07e-a170-4428-a6d7-19a7ac06dd18", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 20000104\n", "1 20000105\n", "2 20000106\n", "3 20000107\n", "4 20000110\n", " ... \n", "5436 20220614\n", "5437 20220615\n", "5438 20220616\n", "5439 20220617\n", "5440 20220620\n", "Name: date, Length: 5441, dtype: int64\n" ] } ], "source": [ "pprint(s)" ] }, { "cell_type": "code", "execution_count": 24, "id": "0a34a466-141f-42ec-8d84-7ca4f28efd7e", "metadata": {}, "outputs": [], "source": [ "def dump_mkt_calendar(start_date, end_date, stock_pool_date):\n", " \n", " def _dump_df_to_csv(series):\n", " dump_path = '{}/行情数据/calendar.csv'.format(\n", " TINYSOFT_DATA_PATH\n", " )\n", " series.to_csv(dump_path, index=False)\n", " \n", " with tsl() as t:\n", " date_list = t.get_mkt_trading_days(20000101,20220620)\n", " \n", " s = pd.Series(date_list, dtype=np.int64, name='date')\n", " _dump_df_to_csv(s)\n", " " ] }, { "cell_type": "code", "execution_count": 25, "id": "74b4d3d1-fbbc-4fbd-be36-790901b9270c", "metadata": {}, "outputs": [], "source": [ "dump_mkt_calendar(20200520, 20220620, 20220531)" ] }, { "cell_type": "code", "execution_count": 28, "id": "fde93bc5-bef0-4a3a-a30a-ebe04d65a474", "metadata": {}, "outputs": [], "source": [ "def dump_mkt_k_daily(start_date, end_date, stock_pool_date):\n", " \n", " def _dump_df_to_csv(stock_id, df):\n", " dump_path = '{}/行情数据/k-daily/{}.csv'.format(\n", " TINYSOFT_DATA_PATH, stock_id\n", " )\n", " df.to_csv(dump_path)\n", " \n", " with tsl() as t:\n", " stock_list = t.get_stock_list(stock_pool_date)\n", " print('正在获取日频行情数据:')\n", " \n", " with tqdm(stock_list) as pbar:\n", " for stock_id in pbar:\n", " pbar.set_description(stock_id)\n", " df1 = t.get_mkt_stock_k_daily(start_date, end_date, stock_id)\n", " df2 = t.get_mkt_stock_k_daily_ext(start_date, end_date, stock_id)\n", " df = pd.concat([df1, df2], axis=1)\n", " \n", " _dump_df_to_csv(stock_id, df)\n", " time.sleep(0.001)\n", " " ] }, { "cell_type": "code", "execution_count": 29, "id": "bde355b6-bfc9-45b5-9b8f-3d640306647f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "正在获取日频行情数据:\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "SH600021: 2%|█▌ | 113/4822 [00:37<26:17, 2.98it/s]\n" ] }, { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "Input \u001b[1;32mIn [29]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mdump_mkt_k_daily\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m20200610\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m20220620\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m20220531\u001b[39;49m\u001b[43m)\u001b[49m\n", "Input \u001b[1;32mIn [28]\u001b[0m, in \u001b[0;36mdump_mkt_k_daily\u001b[1;34m(start_date, end_date, stock_pool_date)\u001b[0m\n\u001b[0;32m 15\u001b[0m pbar\u001b[38;5;241m.\u001b[39mset_description(stock_id)\n\u001b[0;32m 16\u001b[0m df1 \u001b[38;5;241m=\u001b[39m t\u001b[38;5;241m.\u001b[39mget_mkt_stock_k_daily(start_date, end_date, stock_id)\n\u001b[1;32m---> 17\u001b[0m df2 \u001b[38;5;241m=\u001b[39m \u001b[43mt\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_mkt_stock_k_daily_ext\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_date\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend_date\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstock_id\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 18\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat([df1, df2], axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 20\u001b[0m _dump_df_to_csv(stock_id, df)\n", "Input \u001b[1;32mIn [16]\u001b[0m, in \u001b[0;36mtsl.get_mkt_stock_k_daily_ext\u001b[1;34m(self, start_date, end_date, stock_id)\u001b[0m\n\u001b[0;32m 159\u001b[0m \u001b[38;5;66;03m# IsSt_3: 是否是ST(指定日),判断当前股票在指定日是否是ST股。函数主要是通过名称变更进行判断。 \u001b[39;00m\n\u001b[0;32m 160\u001b[0m \u001b[38;5;66;03m# Stockzf3:涨幅(%) =(收盘-昨收)/昨收*100%(已复权)\u001b[39;00m\n\u001b[0;32m 161\u001b[0m \u001b[38;5;66;03m# http://www.tinysoft.com.cn/tsdn/helpdoc/display.tsl?id=12582\u001b[39;00m\n\u001b[0;32m 162\u001b[0m \u001b[38;5;66;03m# AuthorityFactor: 以上市日为复权基准日,向后复权,得到指定日比例复权方式的复权因子值,即复权方式为1。调用该函数需注意设置当前股票和当前时间。\u001b[39;00m\n\u001b[0;32m 163\u001b[0m code \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[0;32m 164\u001b[0m \u001b[38;5;124m SetSysParam(pn_cycle(),cy_day());\u001b[39m\n\u001b[0;32m 165\u001b[0m \u001b[38;5;124m SetSysParam(pn_stock(), \u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;132;01m{stock_id}\u001b[39;00m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m);\u001b[39m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 184\u001b[0m date_list_input\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin([\u001b[38;5;28mstr\u001b[39m(date) \u001b[38;5;28;01mfor\u001b[39;00m date \u001b[38;5;129;01min\u001b[39;00m date_list])\n\u001b[0;32m 185\u001b[0m )\n\u001b[1;32m--> 186\u001b[0m r \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexec\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 188\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame(r\u001b[38;5;241m.\u001b[39mvalue(), index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mlen\u001b[39m(r\u001b[38;5;241m.\u001b[39mvalue())))\n\u001b[0;32m 189\u001b[0m df\u001b[38;5;241m.\u001b[39mset_index([\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mStockID\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdate\u001b[39m\u001b[38;5;124m'\u001b[39m], inplace\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "dump_mkt_k_daily(20200610, 20220620, 20220531)" ] }, { "cell_type": "code", "execution_count": 38, "id": "93a4db53-fe61-4b80-983d-01c6434dd33a", "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('../TslDataFeed/tinysoft-data/行情数据/k-daily/NE430047.csv')" ] }, { "cell_type": "code", "execution_count": 39, "id": "0dc92194-f2fb-432b-a081-ba70688ec766", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StockIDdateclosevollowyclosecjbsamounthighopenIsSTFactorPctChgFloatShares
0NE4300472015030926.9840000.026.526.480.01079070.027.426.501.0000001.888218149259448.0
1NE4300472015031027.509000.027.526.980.0247500.027.527.501.0000001.927354149259448.0
2NE4300472015031127.6029000.027.427.500.0797310.027.627.401.0000000.363636149259448.0
3NE4300472015031327.8031000.027.527.600.0861900.028.027.601.0000000.724638149259448.0
4NE4300472015031628.00110000.028.027.800.03099050.028.828.001.0000000.719424149259448.0
.............................................
5436NE43004720201117NaNNaNNaNNaNNaNNaNNaNNaN00.2119110.000000149259448.0
5437NE43004720201118NaNNaNNaNNaNNaNNaNNaNNaN00.2119110.000000149259448.0
5438NE43004720201119NaNNaNNaNNaNNaNNaNNaNNaN00.2119110.000000149259448.0
5439NE43004720201120NaNNaNNaNNaNNaNNaNNaNNaN00.2119110.000000149259448.0
5440NE43004720201123NaNNaNNaNNaNNaNNaNNaNNaN00.2119110.000000149259448.0
\n", "

5441 rows × 14 columns

\n", "
" ], "text/plain": [ " StockID date close vol low yclose cjbs amount \\\n", "0 NE430047 20150309 26.98 40000.0 26.5 26.48 0.0 1079070.0 \n", "1 NE430047 20150310 27.50 9000.0 27.5 26.98 0.0 247500.0 \n", "2 NE430047 20150311 27.60 29000.0 27.4 27.50 0.0 797310.0 \n", "3 NE430047 20150313 27.80 31000.0 27.5 27.60 0.0 861900.0 \n", "4 NE430047 20150316 28.00 110000.0 28.0 27.80 0.0 3099050.0 \n", "... ... ... ... ... ... ... ... ... \n", "5436 NE430047 20201117 NaN NaN NaN NaN NaN NaN \n", "5437 NE430047 20201118 NaN NaN NaN NaN NaN NaN \n", "5438 NE430047 20201119 NaN NaN NaN NaN NaN NaN \n", "5439 NE430047 20201120 NaN NaN NaN NaN NaN NaN \n", "5440 NE430047 20201123 NaN NaN NaN NaN NaN NaN \n", "\n", " high open IsST Factor PctChg FloatShares \n", "0 27.4 26.5 0 1.000000 1.888218 149259448.0 \n", "1 27.5 27.5 0 1.000000 1.927354 149259448.0 \n", "2 27.6 27.4 0 1.000000 0.363636 149259448.0 \n", "3 28.0 27.6 0 1.000000 0.724638 149259448.0 \n", "4 28.8 28.0 0 1.000000 0.719424 149259448.0 \n", "... ... ... ... ... ... ... \n", "5436 NaN NaN 0 0.211911 0.000000 149259448.0 \n", "5437 NaN NaN 0 0.211911 0.000000 149259448.0 \n", "5438 NaN NaN 0 0.211911 0.000000 149259448.0 \n", "5439 NaN NaN 0 0.211911 0.000000 149259448.0 \n", "5440 NaN NaN 0 0.211911 0.000000 149259448.0 \n", "\n", "[5441 rows x 14 columns]" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 10, "id": "6c924316-cd8c-445b-808d-74b8e4e84131", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "df = pd.DataFrame(columns=['a'])" ] }, { "cell_type": "code", "execution_count": 11, "id": "f4fe5b31-b287-4338-8b8e-a46454f9b307", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['a'], dtype='object')" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.columns" ] }, { "cell_type": "code", "execution_count": 13, "id": "9aea4161-4b67-4133-b778-97d8a1328096", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'a' in df.columns" ] }, { "cell_type": "code", "execution_count": 14, "id": "fbc79e1d-21a9-40aa-abbc-c123a53a1513", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(df.index)" ] }, { "cell_type": "code", "execution_count": 3, "id": "f510f510-03da-4663-a584-176fa76d1ff0", "metadata": {}, "outputs": [], "source": [ "code = \"\"\"\n", "return getAbkbydate('A股',20220630T); \n", "\"\"\"\n", "\n", "with tsl() as t:\n", " r = t.c.exec(code)" ] }, { "cell_type": "code", "execution_count": 5, "id": "cbd25e2b-69dc-4c9b-9c34-a184d282c479", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4817" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(r.value())" ] }, { "cell_type": "code", "execution_count": 17, "id": "240086e1-673d-4ebd-ad18-d397c43ac1b6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5012" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "code = \"\"\"\n", "return getbk('A股;暂停上市;终止上市');\n", "\"\"\"\n", "\n", "with tsl() as t:\n", " r = t.c.exec(code)\n", " \n", "len(r.value())" ] }, { "cell_type": "code", "execution_count": 22, "id": "2104d772-8224-4310-84df-48f2bd7f1d20", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2023" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datetime import datetime\n", "datetime.now().year + 1" ] }, { "cell_type": "code", "execution_count": null, "id": "1b7eede1-b09f-4de5-b531-b28487005afa", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" } }, "nbformat": 4, "nbformat_minor": 5 }