{
"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",
" close | \n",
" vol | \n",
" low | \n",
" yclose | \n",
" cjbs | \n",
" amount | \n",
" high | \n",
" open | \n",
" IsST | \n",
" Factor | \n",
" PctChg | \n",
" FloatShares | \n",
"
\n",
" \n",
" StockID | \n",
" date | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" SZ000012 | \n",
" 20220505 | \n",
" 5.78 | \n",
" 52548342.0 | \n",
" 5.61 | \n",
" 5.62 | \n",
" 47277.0 | \n",
" 3.036327e+08 | \n",
" 5.88 | \n",
" 5.63 | \n",
" 0 | \n",
" 0.030667 | \n",
" 2.846975 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220506 | \n",
" 5.64 | \n",
" 30434955.0 | \n",
" 5.55 | \n",
" 5.78 | \n",
" 37648.0 | \n",
" 1.721508e+08 | \n",
" 5.77 | \n",
" 5.65 | \n",
" 0 | \n",
" 0.030667 | \n",
" -2.422145 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220509 | \n",
" 5.68 | \n",
" 26512956.0 | \n",
" 5.61 | \n",
" 5.64 | \n",
" 31115.0 | \n",
" 1.513519e+08 | \n",
" 5.81 | \n",
" 5.62 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.709220 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220510 | \n",
" 5.76 | \n",
" 44880370.0 | \n",
" 5.55 | \n",
" 5.68 | \n",
" 39085.0 | \n",
" 2.556482e+08 | \n",
" 5.77 | \n",
" 5.58 | \n",
" 0 | \n",
" 0.030667 | \n",
" 1.408451 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220511 | \n",
" 5.82 | \n",
" 63441266.0 | \n",
" 5.80 | \n",
" 5.76 | \n",
" 50303.0 | \n",
" 3.741822e+08 | \n",
" 6.02 | \n",
" 5.81 | \n",
" 0 | \n",
" 0.030667 | \n",
" 1.041667 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220512 | \n",
" 5.83 | \n",
" 40711757.0 | \n",
" 5.72 | \n",
" 5.82 | \n",
" 30591.0 | \n",
" 2.373038e+08 | \n",
" 5.93 | \n",
" 5.82 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.171821 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220513 | \n",
" 5.95 | \n",
" 44013643.0 | \n",
" 5.81 | \n",
" 5.83 | \n",
" 32703.0 | \n",
" 2.597157e+08 | \n",
" 5.97 | \n",
" 5.89 | \n",
" 0 | \n",
" 0.030667 | \n",
" 2.058319 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220516 | \n",
" 5.80 | \n",
" 51952217.0 | \n",
" 5.76 | \n",
" 5.95 | \n",
" 46334.0 | \n",
" 3.046104e+08 | \n",
" 6.05 | \n",
" 6.00 | \n",
" 0 | \n",
" 0.030667 | \n",
" -2.521008 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220517 | \n",
" 5.88 | \n",
" 37310901.0 | \n",
" 5.67 | \n",
" 5.80 | \n",
" 33021.0 | \n",
" 2.155254e+08 | \n",
" 5.88 | \n",
" 5.82 | \n",
" 0 | \n",
" 0.030667 | \n",
" 1.379310 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220518 | \n",
" 5.92 | \n",
" 43071593.0 | \n",
" 5.82 | \n",
" 5.88 | \n",
" 36175.0 | \n",
" 2.553750e+08 | \n",
" 6.02 | \n",
" 5.87 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.680272 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220519 | \n",
" 6.09 | \n",
" 71322634.0 | \n",
" 5.77 | \n",
" 5.92 | \n",
" 55347.0 | \n",
" 4.292484e+08 | \n",
" 6.20 | \n",
" 5.81 | \n",
" 0 | \n",
" 0.030667 | \n",
" 2.871622 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220520 | \n",
" 6.15 | \n",
" 63335796.0 | \n",
" 6.03 | \n",
" 6.09 | \n",
" 47644.0 | \n",
" 3.862153e+08 | \n",
" 6.16 | \n",
" 6.11 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.985222 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220523 | \n",
" 6.17 | \n",
" 44809479.0 | \n",
" 6.10 | \n",
" 6.15 | \n",
" 33057.0 | \n",
" 2.758453e+08 | \n",
" 6.23 | \n",
" 6.19 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.325203 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220524 | \n",
" 5.93 | \n",
" 67558001.0 | \n",
" 5.91 | \n",
" 6.17 | \n",
" 48715.0 | \n",
" 4.162481e+08 | \n",
" 6.37 | \n",
" 6.18 | \n",
" 0 | \n",
" 0.030667 | \n",
" -3.889789 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220525 | \n",
" 6.02 | \n",
" 37408360.0 | \n",
" 5.89 | \n",
" 5.93 | \n",
" 28801.0 | \n",
" 2.233981e+08 | \n",
" 6.02 | \n",
" 5.97 | \n",
" 0 | \n",
" 0.030667 | \n",
" 1.517707 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220526 | \n",
" 6.06 | \n",
" 31951823.0 | \n",
" 5.91 | \n",
" 6.02 | \n",
" 28125.0 | \n",
" 1.925206e+08 | \n",
" 6.11 | \n",
" 6.04 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.664452 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220527 | \n",
" 6.07 | \n",
" 31871879.0 | \n",
" 5.98 | \n",
" 6.06 | \n",
" 26731.0 | \n",
" 1.931219e+08 | \n",
" 6.12 | \n",
" 6.09 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.165017 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220530 | \n",
" 6.12 | \n",
" 27955000.0 | \n",
" 6.03 | \n",
" 6.07 | \n",
" 23213.0 | \n",
" 1.700274e+08 | \n",
" 6.13 | \n",
" 6.11 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.823723 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220531 | \n",
" 6.22 | \n",
" 50331033.0 | \n",
" 6.06 | \n",
" 6.12 | \n",
" 37964.0 | \n",
" 3.103057e+08 | \n",
" 6.24 | \n",
" 6.17 | \n",
" 0 | \n",
" 0.030667 | \n",
" 1.633987 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220601 | \n",
" 6.15 | \n",
" 35835989.0 | \n",
" 6.11 | \n",
" 6.22 | \n",
" 29394.0 | \n",
" 2.208082e+08 | \n",
" 6.22 | \n",
" 6.22 | \n",
" 0 | \n",
" 0.030667 | \n",
" -1.125402 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220602 | \n",
" 6.31 | \n",
" 57818462.0 | \n",
" 6.08 | \n",
" 6.15 | \n",
" 39913.0 | \n",
" 3.613558e+08 | \n",
" 6.35 | \n",
" 6.13 | \n",
" 0 | \n",
" 0.030667 | \n",
" 2.601626 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220606 | \n",
" 6.35 | \n",
" 49949153.0 | \n",
" 6.23 | \n",
" 6.31 | \n",
" 40078.0 | \n",
" 3.153994e+08 | \n",
" 6.38 | \n",
" 6.29 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.633914 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220607 | \n",
" 6.39 | \n",
" 68554508.0 | \n",
" 6.32 | \n",
" 6.35 | \n",
" 46616.0 | \n",
" 4.418079e+08 | \n",
" 6.59 | \n",
" 6.44 | \n",
" 0 | \n",
" 0.030667 | \n",
" 0.629921 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220608 | \n",
" 6.33 | \n",
" 55527059.0 | \n",
" 6.20 | \n",
" 6.39 | \n",
" 38473.0 | \n",
" 3.512041e+08 | \n",
" 6.42 | \n",
" 6.35 | \n",
" 0 | \n",
" 0.030667 | \n",
" -0.938967 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
" 20220609 | \n",
" 6.18 | \n",
" 34466429.0 | \n",
" 6.13 | \n",
" 6.33 | \n",
" 28828.0 | \n",
" 2.143454e+08 | \n",
" 6.32 | \n",
" 6.32 | \n",
" 0 | \n",
" 0.030667 | \n",
" -2.369668 | \n",
" 1.956586e+09 | \n",
"
\n",
" \n",
"
\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",
" date | \n",
" close | \n",
" vol | \n",
" low | \n",
" yclose | \n",
" StockID | \n",
" cjbs | \n",
" amount | \n",
" high | \n",
" open | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 20220505 | \n",
" 5.78 | \n",
" 52548342.0 | \n",
" 5.61 | \n",
" 5.62 | \n",
" SZ000012 | \n",
" 47277.0 | \n",
" 3.036327e+08 | \n",
" 5.88 | \n",
" 5.63 | \n",
"
\n",
" \n",
" 1 | \n",
" 20220506 | \n",
" 5.64 | \n",
" 30434955.0 | \n",
" 5.55 | \n",
" 5.78 | \n",
" SZ000012 | \n",
" 37648.0 | \n",
" 1.721508e+08 | \n",
" 5.77 | \n",
" 5.65 | \n",
"
\n",
" \n",
" 2 | \n",
" 20220509 | \n",
" 5.68 | \n",
" 26512956.0 | \n",
" 5.61 | \n",
" 5.64 | \n",
" SZ000012 | \n",
" 31115.0 | \n",
" 1.513519e+08 | \n",
" 5.81 | \n",
" 5.62 | \n",
"
\n",
" \n",
" 3 | \n",
" 20220510 | \n",
" 5.76 | \n",
" 44880370.0 | \n",
" 5.55 | \n",
" 5.68 | \n",
" SZ000012 | \n",
" 39085.0 | \n",
" 2.556482e+08 | \n",
" 5.77 | \n",
" 5.58 | \n",
"
\n",
" \n",
" 4 | \n",
" 20220511 | \n",
" 5.82 | \n",
" 63441266.0 | \n",
" 5.80 | \n",
" 5.76 | \n",
" SZ000012 | \n",
" 50303.0 | \n",
" 3.741822e+08 | \n",
" 6.02 | \n",
" 5.81 | \n",
"
\n",
" \n",
" 5 | \n",
" 20220512 | \n",
" 5.83 | \n",
" 40711757.0 | \n",
" 5.72 | \n",
" 5.82 | \n",
" SZ000012 | \n",
" 30591.0 | \n",
" 2.373038e+08 | \n",
" 5.93 | \n",
" 5.82 | \n",
"
\n",
" \n",
" 6 | \n",
" 20220513 | \n",
" 5.95 | \n",
" 44013643.0 | \n",
" 5.81 | \n",
" 5.83 | \n",
" SZ000012 | \n",
" 32703.0 | \n",
" 2.597157e+08 | \n",
" 5.97 | \n",
" 5.89 | \n",
"
\n",
" \n",
" 7 | \n",
" 20220516 | \n",
" 5.80 | \n",
" 51952217.0 | \n",
" 5.76 | \n",
" 5.95 | \n",
" SZ000012 | \n",
" 46334.0 | \n",
" 3.046104e+08 | \n",
" 6.05 | \n",
" 6.00 | \n",
"
\n",
" \n",
" 8 | \n",
" 20220517 | \n",
" 5.88 | \n",
" 37310901.0 | \n",
" 5.67 | \n",
" 5.80 | \n",
" SZ000012 | \n",
" 33021.0 | \n",
" 2.155254e+08 | \n",
" 5.88 | \n",
" 5.82 | \n",
"
\n",
" \n",
" 9 | \n",
" 20220518 | \n",
" 5.92 | \n",
" 43071593.0 | \n",
" 5.82 | \n",
" 5.88 | \n",
" SZ000012 | \n",
" 36175.0 | \n",
" 2.553750e+08 | \n",
" 6.02 | \n",
" 5.87 | \n",
"
\n",
" \n",
" 10 | \n",
" 20220519 | \n",
" 6.09 | \n",
" 71322634.0 | \n",
" 5.77 | \n",
" 5.92 | \n",
" SZ000012 | \n",
" 55347.0 | \n",
" 4.292484e+08 | \n",
" 6.20 | \n",
" 5.81 | \n",
"
\n",
" \n",
" 11 | \n",
" 20220520 | \n",
" 6.15 | \n",
" 63335796.0 | \n",
" 6.03 | \n",
" 6.09 | \n",
" SZ000012 | \n",
" 47644.0 | \n",
" 3.862153e+08 | \n",
" 6.16 | \n",
" 6.11 | \n",
"
\n",
" \n",
" 12 | \n",
" 20220523 | \n",
" 6.17 | \n",
" 44809479.0 | \n",
" 6.10 | \n",
" 6.15 | \n",
" SZ000012 | \n",
" 33057.0 | \n",
" 2.758453e+08 | \n",
" 6.23 | \n",
" 6.19 | \n",
"
\n",
" \n",
" 13 | \n",
" 20220524 | \n",
" 5.93 | \n",
" 67558001.0 | \n",
" 5.91 | \n",
" 6.17 | \n",
" SZ000012 | \n",
" 48715.0 | \n",
" 4.162481e+08 | \n",
" 6.37 | \n",
" 6.18 | \n",
"
\n",
" \n",
" 14 | \n",
" 20220525 | \n",
" 6.02 | \n",
" 37408360.0 | \n",
" 5.89 | \n",
" 5.93 | \n",
" SZ000012 | \n",
" 28801.0 | \n",
" 2.233981e+08 | \n",
" 6.02 | \n",
" 5.97 | \n",
"
\n",
" \n",
" 15 | \n",
" 20220526 | \n",
" 6.06 | \n",
" 31951823.0 | \n",
" 5.91 | \n",
" 6.02 | \n",
" SZ000012 | \n",
" 28125.0 | \n",
" 1.925206e+08 | \n",
" 6.11 | \n",
" 6.04 | \n",
"
\n",
" \n",
" 16 | \n",
" 20220527 | \n",
" 6.07 | \n",
" 31871879.0 | \n",
" 5.98 | \n",
" 6.06 | \n",
" SZ000012 | \n",
" 26731.0 | \n",
" 1.931219e+08 | \n",
" 6.12 | \n",
" 6.09 | \n",
"
\n",
" \n",
" 17 | \n",
" 20220530 | \n",
" 6.12 | \n",
" 27955000.0 | \n",
" 6.03 | \n",
" 6.07 | \n",
" SZ000012 | \n",
" 23213.0 | \n",
" 1.700274e+08 | \n",
" 6.13 | \n",
" 6.11 | \n",
"
\n",
" \n",
" 18 | \n",
" 20220531 | \n",
" 6.22 | \n",
" 50331033.0 | \n",
" 6.06 | \n",
" 6.12 | \n",
" SZ000012 | \n",
" 37964.0 | \n",
" 3.103057e+08 | \n",
" 6.24 | \n",
" 6.17 | \n",
"
\n",
" \n",
" 19 | \n",
" 20220601 | \n",
" 6.15 | \n",
" 35835989.0 | \n",
" 6.11 | \n",
" 6.22 | \n",
" SZ000012 | \n",
" 29394.0 | \n",
" 2.208082e+08 | \n",
" 6.22 | \n",
" 6.22 | \n",
"
\n",
" \n",
" 20 | \n",
" 20220602 | \n",
" 6.31 | \n",
" 57818462.0 | \n",
" 6.08 | \n",
" 6.15 | \n",
" SZ000012 | \n",
" 39913.0 | \n",
" 3.613558e+08 | \n",
" 6.35 | \n",
" 6.13 | \n",
"
\n",
" \n",
" 21 | \n",
" 20220606 | \n",
" 6.35 | \n",
" 49949153.0 | \n",
" 6.23 | \n",
" 6.31 | \n",
" SZ000012 | \n",
" 40078.0 | \n",
" 3.153994e+08 | \n",
" 6.38 | \n",
" 6.29 | \n",
"
\n",
" \n",
" 22 | \n",
" 20220607 | \n",
" 6.39 | \n",
" 68554508.0 | \n",
" 6.32 | \n",
" 6.35 | \n",
" SZ000012 | \n",
" 46616.0 | \n",
" 4.418079e+08 | \n",
" 6.59 | \n",
" 6.44 | \n",
"
\n",
" \n",
" 23 | \n",
" 20220608 | \n",
" 6.33 | \n",
" 55527059.0 | \n",
" 6.20 | \n",
" 6.39 | \n",
" SZ000012 | \n",
" 38473.0 | \n",
" 3.512041e+08 | \n",
" 6.42 | \n",
" 6.35 | \n",
"
\n",
" \n",
" 24 | \n",
" 20220609 | \n",
" 6.18 | \n",
" 34466429.0 | \n",
" 6.13 | \n",
" 6.33 | \n",
" SZ000012 | \n",
" 28828.0 | \n",
" 2.143454e+08 | \n",
" 6.32 | \n",
" 6.32 | \n",
"
\n",
" \n",
"
\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",
" StockID | \n",
" date | \n",
" close | \n",
" vol | \n",
" low | \n",
" yclose | \n",
" cjbs | \n",
" amount | \n",
" high | \n",
" open | \n",
" IsST | \n",
" Factor | \n",
" PctChg | \n",
" FloatShares | \n",
" \n",
" \n",
" \n",
" \n",
" 0 | \n",
" NE430047 | \n",
" 20150309 | \n",
" 26.98 | \n",
" 40000.0 | \n",
" 26.5 | \n",
" 26.48 | \n",
" 0.0 | \n",
" 1079070.0 | \n",
" 27.4 | \n",
" 26.5 | \n",
" 0 | \n",
" 1.000000 | \n",
" 1.888218 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 1 | \n",
" NE430047 | \n",
" 20150310 | \n",
" 27.50 | \n",
" 9000.0 | \n",
" 27.5 | \n",
" 26.98 | \n",
" 0.0 | \n",
" 247500.0 | \n",
" 27.5 | \n",
" 27.5 | \n",
" 0 | \n",
" 1.000000 | \n",
" 1.927354 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 2 | \n",
" NE430047 | \n",
" 20150311 | \n",
" 27.60 | \n",
" 29000.0 | \n",
" 27.4 | \n",
" 27.50 | \n",
" 0.0 | \n",
" 797310.0 | \n",
" 27.6 | \n",
" 27.4 | \n",
" 0 | \n",
" 1.000000 | \n",
" 0.363636 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 3 | \n",
" NE430047 | \n",
" 20150313 | \n",
" 27.80 | \n",
" 31000.0 | \n",
" 27.5 | \n",
" 27.60 | \n",
" 0.0 | \n",
" 861900.0 | \n",
" 28.0 | \n",
" 27.6 | \n",
" 0 | \n",
" 1.000000 | \n",
" 0.724638 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 4 | \n",
" NE430047 | \n",
" 20150316 | \n",
" 28.00 | \n",
" 110000.0 | \n",
" 28.0 | \n",
" 27.80 | \n",
" 0.0 | \n",
" 3099050.0 | \n",
" 28.8 | \n",
" 28.0 | \n",
" 0 | \n",
" 1.000000 | \n",
" 0.719424 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" \n",
" \n",
" 5436 | \n",
" NE430047 | \n",
" 20201117 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 0 | \n",
" 0.211911 | \n",
" 0.000000 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 5437 | \n",
" NE430047 | \n",
" 20201118 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 0 | \n",
" 0.211911 | \n",
" 0.000000 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 5438 | \n",
" NE430047 | \n",
" 20201119 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 0 | \n",
" 0.211911 | \n",
" 0.000000 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 5439 | \n",
" NE430047 | \n",
" 20201120 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 0 | \n",
" 0.211911 | \n",
" 0.000000 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" 5440 | \n",
" NE430047 | \n",
" 20201123 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 0 | \n",
" 0.211911 | \n",
" 0.000000 | \n",
" 149259448.0 | \n",
" \n",
" \n",
" \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
}
|