You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4209 lines
259 KiB

2 years ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 69,
"id": "a98e649f-c649-437c-8b43-8f4b17660524",
"metadata": {},
"outputs": [],
"source": [
"import sqlalchemy as sa\n",
"engine = sa.create_engine(\n",
" 'mssql+pyodbc://sa:passw0rd!@192.168.1.7/master?driver=ODBC+Driver+18+for+SQL+Server',\n",
" connect_args = {\n",
" \"TrustServerCertificate\": \"yes\"\n",
" }, echo=False)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7d0a8dc0-4a98-4766-b0f7-6b2bf61e8514",
"metadata": {},
"outputs": [],
"source": [
"with engine.connect() as conn:\n",
" rs = conn.execute(\"select SecID from [IndexInfo].[dbo].[Constituents] group by SecID\")\n",
" stock_list = [stock_id for (stock_id,) in rs.fetchall()]\n",
" \n",
" rs = conn.execute(\"select IndexID from [IndexInfo].[dbo].[Constituents] group by IndexID\")\n",
" index_list = [index_id for (index_id,) in rs.fetchall()]\n"
]
},
{
"cell_type": "code",
"execution_count": 112,
"id": "cb3235f9-7719-4e94-9a8f-65cd535a2a5e",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"with engine.connect() as conn:\n",
" rs = conn.execute(\"\"\"\n",
" select \n",
" SecID, \n",
" CONCAT(SUBSTRING(EnterDate, 1, 4), '-', SUBSTRING(EnterDate, 5, 2), '-', SUBSTRING(EnterDate, 7, 2)) AS EnterDate, \n",
" CONCAT(SUBSTRING(ExitDate, 1, 4), '-', SUBSTRING(ExitDate, 5, 2), '-', SUBSTRING(ExitDate, 7, 2)) AS ExitDate\n",
" FROM (SELECT\n",
" SecID, \n",
" CAST(EnterDate AS varchar) AS EnterDate,\n",
" CAST(IIF(ExitDate=0, 20220630, ExitDate) AS varchar) AS ExitDate \n",
" from [IndexInfo].[dbo].[Constituents] where IndexID='SH000852'\n",
" )t\n",
" \"\"\")\n",
" index_info = rs.fetchall()\n",
"\n",
"index_info = pd.DataFrame(index_info)\n",
"index_info\n",
"index_info.to_csv('csi1000.txt', sep='\\t', columns=['SecID', 'EnterDate', 'ExitDate'], index=False, header=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc14e8be-a360-4a49-88fb-a9763d8ba655",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"def make_date(series):\n",
" # 特别是对于分红表如果某些关键日期还未公布则会填充0导致日期解析失败\n",
" series.loc[series == 0] = np.nan\n",
" return pd.to_datetime(\n",
" series.astype(str), format='%Y%m%d')\n",
"\n",
"\n",
"with engine.connect() as conn:\n",
" rs = conn.execute(\"select SecID from [IndexInfo].[dbo].[Constituents] group by SecID\")\n",
" stock_list = [stock_id for (stock_id,) in rs.fetchall()]\n",
"\n",
" rs = conn.execute(\"select IndexID from [IndexInfo].[dbo].[Constituents] group by IndexID\")\n",
" concept_list = [index_id for (index_id,) in rs.fetchall()]\n",
" \n",
" stat = \"select distinct S_INFO_WINDCODE, TRADE_DT from Level2BytesKline.dbo.KLine\"\n",
" rs = conn.execute(stat)\n",
" stock_date_list = [(stock_name, date) for stock_name, date in rs.fetchall()]\n",
" df_calendar = pd.DataFrame(stock_date_list, columns=['code', 'm_nDate'])\n",
" df_calendar['m_nDate'] = make_date(df_calendar['m_nDate'])\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "5bc376b2-1e59-4d4d-a630-37c99884b2d5",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"\n",
"def tscode_to_windcode(series):\n",
" return series.apply(lambda x : x[2:] + '.' + x[:2])\n",
"\n",
"\n",
"def _make_stock2concept_onehot():\n",
" # 从calendar中截取出与当前stock有关的日期然后设置成index\n",
" # 此处calendar使用的是海通高频数据构建因此股票代码为WIND-CODE\n",
" for wind_code, df_calendar_stock in df_calendar.groupby('code'):\n",
" ts_code = wind_code[-2:] + wind_code[:-3]\n",
" \n",
" df_calendar_stock.set_index(['code', 'm_nDate'], inplace=True)\n",
"\n",
" # 纵表转横表,`concept_list`作为列名\n",
" df_stock2concept = pd.DataFrame(0, index=df_calendar_stock.index, columns=concept_list)\n",
"\n",
" # 从Sql-Server中读取`stock_id`所对应的概念板块进出日期\n",
" # 此数据是从天软指数数据中提取因此需要使用TSCODE\n",
" with engine.connect() as conn:\n",
" code = \"\"\"\n",
" select \n",
" SecId, IndexID, EnterDate, ExitDate \n",
" from \n",
" [IndexInfo].[dbo].[Constituents] \n",
" where \n",
" SecID='{stock_id}'\n",
" \"\"\".format(\n",
" stock_id = ts_code\n",
" )\n",
" print(code)\n",
" rs = conn.execute(code)\n",
" row_list = rs.fetchall()\n",
"\n",
" for (stock_id, concept_id, start_date, end_date) in row_list:\n",
" _mark_stock2concept_onehot(df_stock2concept[concept_id], concept_id, start_date, end_date)\n",
"\n",
" yield df_stock2concept\n",
"\n",
"\n",
"def _mark_stock2concept_onehot(df_stock2concept, concept_id, start_date, end_date):\n",
" # 个股成为某个概念(指数)的起始日期是必定会提供的\n",
" # 但是截止日期可能缺失,确实一般意味着当前仍然是在此概念板块中\n",
" # 因此会通过将日期填充至最后一日来表示当前仍然在此概念板块内\n",
" if end_date is None or end_date == 0:\n",
" start_date = pd.to_datetime(str(start_date), format='%Y%m%d')\n",
" df_stock2concept.loc[df_stock2concept.index.get_level_values('m_nDate') >= start_date] = 1\n",
" else:\n",
" start_date = pd.to_datetime(str(start_date), format='%Y%m%d')\n",
" end_date = pd.to_datetime(str(end_date), format='%Y%m%d')\n",
" df_stock2concept.loc[\n",
" (df_stock2concept.index.get_level_values('m_nDate') >= start_date) & \n",
" (df_stock2concept.index.get_level_values('m_nDate') <= end_date)\n",
" ] = 1"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "a67786e5-4776-4492-8a87-72defe93eda4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" select \n",
" SecId, IndexID, EnterDate, ExitDate \n",
" from \n",
" [IndexInfo].[dbo].[Constituents] \n",
" where \n",
" SecID='SZ000001'\n",
" \n",
"('SZ000001', 'SH000940', 20090925, 0)\n",
"('SZ000001', 'SZ399619', 20110615, 0)\n",
"('SZ000001', 'SH000980', 20110510, 0)\n",
"('SZ000001', 'SZ399387', 20111202, 0)\n",
"('SZ000001', 'SZ399920', 20100129, 20180611)\n",
"('SZ000001', 'SZ399920', 20200615, 20210615)\n",
"('SZ000001', 'SH000918', 20080121, 20180611)\n",
"('SZ000001', 'SZ399404', 20150520, 20180102)\n",
"('SZ000001', 'SZ399405', 20131205, 20160104)\n",
"('SZ000001', 'SZ399405', 20180102, 20200615)\n",
"('SZ000001', 'SH000919', 20080121, 20200615)\n",
"('SZ000001', 'SZ399405', 20220613, 0)\n",
"('SZ000001', 'SH000919', 20210615, 0)\n",
"('SZ000001', 'SZ399921', 20100129, 0)\n",
"('SZ000001', 'SZ399004', 20030102, 0)\n",
"('SZ000001', 'SZ399925', 20120702, 0)\n",
"('SZ000001', 'SZ399371', 20100104, 20180702)\n",
"('SZ000001', 'SH000803', 20120109, 20130701)\n",
"('SZ000001', 'SH000803', 20141215, 20180611)\n",
"('SZ000001', 'SH000803', 20190617, 20200615)\n",
"('SZ000001', 'SH000803', 20201214, 20211213)\n",
"('SZ000001', 'SH000803', 20220613, 0)\n",
"('SZ000001', 'SZ399007', 20091104, 0)\n",
"('SZ000001', 'SZ399370', 20100701, 20180702)\n",
"('SZ000001', 'SW857831', 20211213, 0)\n",
"('SZ000001', 'SZ399940', 20090925, 0)\n",
"('SZ000001', 'SH000300', 20050408, 0)\n",
"('SZ000001', 'SH000906', 20070115, 0)\n",
"('SZ000001', 'SH000903', 20060529, 20220613)\n",
"('SZ000001', 'SZ399918', 20080121, 20180611)\n",
"('SZ000001', 'SZ399919', 20080121, 20200615)\n",
"('SZ000001', 'SZ399919', 20210615, 0)\n",
"('SZ000001', 'SZ399661', 20121220, 20130701)\n",
"('SZ000001', 'SZ399088', 20200218, 0)\n",
"('SZ000001', 'SH000971', 20101202, 0)\n",
"('SZ000001', 'SZ399701', 20100510, 0)\n",
"('SZ000001', 'SZ399661', 20150105, 20180702)\n",
"('SZ000001', 'SH000842', 20121221, 0)\n",
"('SZ000001', 'SZ399661', 20190102, 0)\n",
"('SZ000001', 'SH000843', 20130701, 20160613)\n",
"('SZ000001', 'SH000844', 20130107, 20130701)\n",
"('SZ000001', 'SZ399314', 20050203, 0)\n",
"('SZ000001', 'SH000844', 20160613, 0)\n",
"('SZ000001', 'SZ399659', 20121123, 0)\n",
"('SZ000001', 'SZ399400', 20130320, 0)\n",
"('SZ000001', 'SH000967', 20100602, 0)\n",
"('SZ000001', 'SZ399630', 20110901, 20180702)\n",
"('SZ000001', 'SW801780', 20140221, 0)\n",
"('SZ000001', 'SW801783', 20211213, 0)\n",
"('SZ000001', 'SH000965', 20100602, 0)\n",
"('SZ000001', 'SZ399980', 20110510, 0)\n",
"('SZ000001', 'SZ399981', 20110613, 0)\n",
"('SZ000001', 'SH000951', 20091028, 0)\n",
"('SZ000001', 'SZ399631', 20110901, 20180702)\n",
"('SZ000001', 'SZ399631', 20191216, 20220613)\n",
"('SZ000001', 'SZ399632', 20111028, 0)\n",
"('SZ000001', 'SZ399633', 20111028, 0)\n",
"('SZ000001', 'SH000829', 20120806, 20130701)\n",
"('SZ000001', 'SH000829', 20160613, 20180611)\n",
"('SZ000001', 'SZ399011', 20110901, 0)\n",
"('SZ000001', 'SH000828', 20130701, 20160613)\n",
"('SZ000001', 'SH000828', 20180611, 20201214)\n",
"('SZ000001', 'SZ399644', 20130201, 0)\n",
"('SZ000001', 'SZ399645', 20120612, 20130701)\n",
"('SZ000001', 'SZ399645', 20140701, 0)\n",
"('SZ000001', 'SZ399656', 20121119, 0)\n",
"('SZ000001', 'SZ399703', 20100510, 0)\n",
"('SZ000001', 'SZ399657', 20121119, 0)\n",
"('SZ000001', 'SH000981', 20110613, 0)\n",
"('SZ000001', 'SZ399300', 20050408, 0)\n",
"('SZ000001', 'SZ399662', 20130701, 20140701)\n",
"('SZ000001', 'SZ399686', 20150831, 0)\n",
"('SZ000001', 'SZ399002', 19950123, 0)\n",
"('SZ000001', 'SW801190', 19910403, 20140221)\n",
"('SZ000001', 'SW801192', 19910403, 20211213)\n",
"('SZ000001', 'SZ399001', 19950123, 0)\n",
"('SZ000001', 'SZ399984', 20110802, 0)\n",
"('SZ000001', 'SZ399431', 20141230, 0)\n",
"('SZ000001', 'SH000920', 20100129, 20180611)\n",
"('SZ000001', 'SZ399985', 20110802, 0)\n",
"('SZ000001', 'SZ399702', 20100510, 0)\n",
"('SZ000001', 'SH000920', 20200615, 20210615)\n",
"('SZ000001', 'SZ399310', 20050905, 0)\n",
"('SZ000001', 'SH000921', 20100129, 0)\n",
"('SZ000001', 'SZ399311', 20050203, 0)\n",
"('SZ000001', 'SZ399372', 20100701, 20180702)\n",
"('SZ000001', 'SZ399373', 20100104, 20180702)\n",
"('SZ000001', 'SH000925', 20120702, 0)\n",
"('SZ000001', 'SW851911', 19910403, 20211213)\n",
"('SZ000001', 'SH000984', 20110802, 0)\n",
"('SZ000001', 'SZ399903', 20060529, 20220613)\n",
"('SZ000001', 'SZ399312', 20050203, 0)\n",
"('SZ000001', 'SH000985', 20110802, 0)\n",
"('SZ000001', 'SZ399313', 20050104, 0)\n",
"('SZ000001', 'SZ399330', 20030102, 0)\n",
"('SZ000001', 'SZ399986', 20130715, 0)\n",
"('SZ000001', 'SZ399348', 20091104, 20220613)\n",
"('SZ000001', 'SZ399344', 20091104, 0)\n",
"('SZ000001', 'SZ399906', 20070115, 0)\n",
"('SZ000001', 'SZ399345', 20100701, 0)\n",
"('SZ000001', 'SZ399346', 20100701, 20170103)\n",
"('SZ000001', 'SZ399347', 20091104, 0)\n",
" SH000009 SH000010 SH000015 SH000016 SH000020 \\\n",
"code m_nDate \n",
"000001.SZ 2013-01-04 0 0 0 0 0 \n",
" 2013-01-07 0 0 0 0 0 \n",
" 2013-01-08 0 0 0 0 0 \n",
" 2013-01-09 0 0 0 0 0 \n",
" 2013-01-10 0 0 0 0 0 \n",
"... ... ... ... ... ... \n",
" 2022-07-04 0 0 0 0 0 \n",
" 2022-07-05 0 0 0 0 0 \n",
" 2022-07-06 0 0 0 0 0 \n",
" 2022-07-07 0 0 0 0 0 \n",
" 2022-07-08 0 0 0 0 0 \n",
"\n",
" SH000028 SH000029 SH000030 SH000031 SH000032 ... \\\n",
"code m_nDate ... \n",
"000001.SZ 2013-01-04 0 0 0 0 0 ... \n",
" 2013-01-07 0 0 0 0 0 ... \n",
" 2013-01-08 0 0 0 0 0 ... \n",
" 2013-01-09 0 0 0 0 0 ... \n",
" 2013-01-10 0 0 0 0 0 ... \n",
"... ... ... ... ... ... ... \n",
" 2022-07-04 0 0 0 0 0 ... \n",
" 2022-07-05 0 0 0 0 0 ... \n",
" 2022-07-06 0 0 0 0 0 ... \n",
" 2022-07-07 0 0 0 0 0 ... \n",
" 2022-07-08 0 0 0 0 0 ... \n",
"\n",
" SZ399980 SZ399981 SZ399982 SZ399983 SZ399984 \\\n",
"code m_nDate \n",
"000001.SZ 2013-01-04 1 1 0 0 1 \n",
" 2013-01-07 1 1 0 0 1 \n",
" 2013-01-08 1 1 0 0 1 \n",
" 2013-01-09 1 1 0 0 1 \n",
" 2013-01-10 1 1 0 0 1 \n",
"... ... ... ... ... ... \n",
" 2022-07-04 1 1 0 0 1 \n",
" 2022-07-05 1 1 0 0 1 \n",
" 2022-07-06 1 1 0 0 1 \n",
" 2022-07-07 1 1 0 0 1 \n",
" 2022-07-08 1 1 0 0 1 \n",
"\n",
" SZ399985 SZ399986 SZ399990 SZ399995 SZ399998 \n",
"code m_nDate \n",
"000001.SZ 2013-01-04 1 0 0 0 0 \n",
" 2013-01-07 1 0 0 0 0 \n",
" 2013-01-08 1 0 0 0 0 \n",
" 2013-01-09 1 0 0 0 0 \n",
" 2013-01-10 1 0 0 0 0 \n",
"... ... ... ... ... ... \n",
" 2022-07-04 1 1 0 0 0 \n",
" 2022-07-05 1 1 0 0 0 \n",
" 2022-07-06 1 1 0 0 0 \n",
" 2022-07-07 1 1 0 0 0 \n",
" 2022-07-08 1 1 0 0 0 \n",
"\n",
"[2309 rows x 949 columns]\n"
]
}
],
"source": [
"for df in _make_stock2concept_onehot():\n",
" print(df)\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "0d307d4f-e202-4246-871b-dc5d8e9252a7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"000001.SZ SZ000001\n",
"\n",
" select \n",
" SecId, IndexID, EnterDate, ExitDate \n",
" from \n",
" [IndexInfo].[dbo].[Constituents] \n",
" where \n",
" SecID='SZ000001'\n",
" \n",
"('SZ000001', 'SH000940', 20090925, 0)\n",
"('SZ000001', 'SZ399619', 20110615, 0)\n",
"('SZ000001', 'SH000980', 20110510, 0)\n",
"('SZ000001', 'SZ399387', 20111202, 0)\n",
"('SZ000001', 'SZ399920', 20100129, 20180611)\n",
"('SZ000001', 'SZ399920', 20200615, 20210615)\n",
"('SZ000001', 'SH000918', 20080121, 20180611)\n",
"('SZ000001', 'SZ399404', 20150520, 20180102)\n",
"('SZ000001', 'SZ399405', 20131205, 20160104)\n",
"('SZ000001', 'SZ399405', 20180102, 20200615)\n",
"('SZ000001', 'SH000919', 20080121, 20200615)\n",
"('SZ000001', 'SZ399405', 20220613, 0)\n",
"('SZ000001', 'SH000919', 20210615, 0)\n",
"('SZ000001', 'SZ399921', 20100129, 0)\n",
"('SZ000001', 'SZ399004', 20030102, 0)\n",
"('SZ000001', 'SZ399925', 20120702, 0)\n",
"('SZ000001', 'SZ399371', 20100104, 20180702)\n",
"('SZ000001', 'SH000803', 20120109, 20130701)\n",
"('SZ000001', 'SH000803', 20141215, 20180611)\n",
"('SZ000001', 'SH000803', 20190617, 20200615)\n",
"('SZ000001', 'SH000803', 20201214, 20211213)\n",
"('SZ000001', 'SH000803', 20220613, 0)\n",
"('SZ000001', 'SZ399007', 20091104, 0)\n",
"('SZ000001', 'SZ399370', 20100701, 20180702)\n",
"('SZ000001', 'SW857831', 20211213, 0)\n",
"('SZ000001', 'SZ399940', 20090925, 0)\n",
"('SZ000001', 'SH000300', 20050408, 0)\n",
"('SZ000001', 'SH000906', 20070115, 0)\n",
"('SZ000001', 'SH000903', 20060529, 20220613)\n",
"('SZ000001', 'SZ399918', 20080121, 20180611)\n",
"('SZ000001', 'SZ399919', 20080121, 20200615)\n",
"('SZ000001', 'SZ399919', 20210615, 0)\n",
"('SZ000001', 'SZ399661', 20121220, 20130701)\n",
"('SZ000001', 'SZ399088', 20200218, 0)\n",
"('SZ000001', 'SH000971', 20101202, 0)\n",
"('SZ000001', 'SZ399701', 20100510, 0)\n",
"('SZ000001', 'SZ399661', 20150105, 20180702)\n",
"('SZ000001', 'SH000842', 20121221, 0)\n",
"('SZ000001', 'SZ399661', 20190102, 0)\n",
"('SZ000001', 'SH000843', 20130701, 20160613)\n",
"('SZ000001', 'SH000844', 20130107, 20130701)\n",
"('SZ000001', 'SZ399314', 20050203, 0)\n",
"('SZ000001', 'SH000844', 20160613, 0)\n",
"('SZ000001', 'SZ399659', 20121123, 0)\n",
"('SZ000001', 'SZ399400', 20130320, 0)\n",
"('SZ000001', 'SH000967', 20100602, 0)\n",
"('SZ000001', 'SZ399630', 20110901, 20180702)\n",
"('SZ000001', 'SW801780', 20140221, 0)\n",
"('SZ000001', 'SW801783', 20211213, 0)\n",
"('SZ000001', 'SH000965', 20100602, 0)\n",
"('SZ000001', 'SZ399980', 20110510, 0)\n",
"('SZ000001', 'SZ399981', 20110613, 0)\n",
"('SZ000001', 'SH000951', 20091028, 0)\n",
"('SZ000001', 'SZ399631', 20110901, 20180702)\n",
"('SZ000001', 'SZ399631', 20191216, 20220613)\n",
"('SZ000001', 'SZ399632', 20111028, 0)\n",
"('SZ000001', 'SZ399633', 20111028, 0)\n",
"('SZ000001', 'SH000829', 20120806, 20130701)\n",
"('SZ000001', 'SH000829', 20160613, 20180611)\n",
"('SZ000001', 'SZ399011', 20110901, 0)\n",
"('SZ000001', 'SH000828', 20130701, 20160613)\n",
"('SZ000001', 'SH000828', 20180611, 20201214)\n",
"('SZ000001', 'SZ399644', 20130201, 0)\n",
"('SZ000001', 'SZ399645', 20120612, 20130701)\n",
"('SZ000001', 'SZ399645', 20140701, 0)\n",
"('SZ000001', 'SZ399656', 20121119, 0)\n",
"('SZ000001', 'SZ399703', 20100510, 0)\n",
"('SZ000001', 'SZ399657', 20121119, 0)\n",
"('SZ000001', 'SH000981', 20110613, 0)\n",
"('SZ000001', 'SZ399300', 20050408, 0)\n",
"('SZ000001', 'SZ399662', 20130701, 20140701)\n",
"('SZ000001', 'SZ399686', 20150831, 0)\n",
"('SZ000001', 'SZ399002', 19950123, 0)\n",
"('SZ000001', 'SW801190', 19910403, 20140221)\n",
"('SZ000001', 'SW801192', 19910403, 20211213)\n",
"('SZ000001', 'SZ399001', 19950123, 0)\n",
"('SZ000001', 'SZ399984', 20110802, 0)\n",
"('SZ000001', 'SZ399431', 20141230, 0)\n",
"('SZ000001', 'SH000920', 20100129, 20180611)\n",
"('SZ000001', 'SZ399985', 20110802, 0)\n",
"('SZ000001', 'SZ399702', 20100510, 0)\n",
"('SZ000001', 'SH000920', 20200615, 20210615)\n",
"('SZ000001', 'SZ399310', 20050905, 0)\n",
"('SZ000001', 'SH000921', 20100129, 0)\n",
"('SZ000001', 'SZ399311', 20050203, 0)\n",
"('SZ000001', 'SZ399372', 20100701, 20180702)\n",
"('SZ000001', 'SZ399373', 20100104, 20180702)\n",
"('SZ000001', 'SH000925', 20120702, 0)\n",
"('SZ000001', 'SW851911', 19910403, 20211213)\n",
"('SZ000001', 'SH000984', 20110802, 0)\n",
"('SZ000001', 'SZ399903', 20060529, 20220613)\n",
"('SZ000001', 'SZ399312', 20050203, 0)\n",
"('SZ000001', 'SH000985', 20110802, 0)\n",
"('SZ000001', 'SZ399313', 20050104, 0)\n",
"('SZ000001', 'SZ399330', 20030102, 0)\n",
"('SZ000001', 'SZ399986', 20130715, 0)\n",
"('SZ000001', 'SZ399348', 20091104, 20220613)\n",
"('SZ000001', 'SZ399344', 20091104, 0)\n",
"('SZ000001', 'SZ399906', 20070115, 0)\n",
"('SZ000001', 'SZ399345', 20100701, 0)\n",
"('SZ000001', 'SZ399346', 20100701, 20170103)\n",
"('SZ000001', 'SZ399347', 20091104, 0)\n"
]
}
],
"source": [
"stock2concept = _make_stock2concept_onehot('000001.SZ')"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "dbc2211d-75ec-4642-a686-ef5cd569afd6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"code m_nDate \n",
"000001.SZ 2013-01-04 1\n",
" 2013-01-07 1\n",
" 2013-01-08 1\n",
" 2013-01-09 1\n",
" 2013-01-10 1\n",
" ..\n",
" 2022-07-04 0\n",
" 2022-07-05 0\n",
" 2022-07-06 0\n",
" 2022-07-07 0\n",
" 2022-07-08 0\n",
"Name: SZ399920, Length: 2309, dtype: int64"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock2concept['SZ399920']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "51dd0b40-ad19-4e82-80ac-1af35042e8b2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" <th>SH000016</th>\n",
" <th>SH000020</th>\n",
" <th>SH000028</th>\n",
" <th>SH000029</th>\n",
" <th>SH000030</th>\n",
" <th>...</th>\n",
" <th>SZ399980</th>\n",
" <th>SZ399981</th>\n",
" <th>SZ399982</th>\n",
" <th>SZ399983</th>\n",
" <th>SZ399984</th>\n",
" <th>SZ399985</th>\n",
" <th>SZ399986</th>\n",
" <th>SZ399990</th>\n",
" <th>SZ399995</th>\n",
" <th>SZ399998</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-04</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-05</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-06</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-09</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-10</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3932</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-04</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3933</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-05</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3934</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-08</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3935</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-09</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3936</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-10</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3937 rows × 951 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate SH000009 SH000010 SH000015 SH000016 SH000020 \\\n",
"0 600000.SH 2006-01-04 False True False True False \n",
"1 600000.SH 2006-01-05 False True False True False \n",
"2 600000.SH 2006-01-06 False True False True False \n",
"3 600000.SH 2006-01-09 False True False True False \n",
"4 600000.SH 2006-01-10 False True False True False \n",
"... ... ... ... ... ... ... ... \n",
"3932 600000.SH 2022-08-04 False True False False False \n",
"3933 600000.SH 2022-08-05 False True False False False \n",
"3934 600000.SH 2022-08-08 False True False False False \n",
"3935 600000.SH 2022-08-09 False True False False False \n",
"3936 600000.SH 2022-08-10 False True False False False \n",
"\n",
" SH000028 SH000029 SH000030 ... SZ399980 SZ399981 SZ399982 \\\n",
"0 False False False ... False False False \n",
"1 False False False ... False False False \n",
"2 False False False ... False False False \n",
"3 False False False ... False False False \n",
"4 False False False ... False False False \n",
"... ... ... ... ... ... ... ... \n",
"3932 False True False ... True True False \n",
"3933 False True False ... True True False \n",
"3934 False True False ... True True False \n",
"3935 False True False ... True True False \n",
"3936 False True False ... True True False \n",
"\n",
" SZ399983 SZ399984 SZ399985 SZ399986 SZ399990 SZ399995 SZ399998 \n",
"0 False False False False False False False \n",
"1 False False False False False False False \n",
"2 False False False False False False False \n",
"3 False False False False False False False \n",
"4 False False False False False False False \n",
"... ... ... ... ... ... ... ... \n",
"3932 False True True True False False False \n",
"3933 False True True True False False False \n",
"3934 False True True True False False False \n",
"3935 False True True True False False False \n",
"3936 False True True True False False False \n",
"\n",
"[3937 rows x 951 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dolphindb as ddb\n",
"\n",
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" select * from loadTable(\"dfs://daily_stock_ts\", \"idx_daily_concept\") where code='600000.SH' order by m_nDate asc\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b1fe53e6-ad7f-42fb-a7ce-5c304d88ec1b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>IsZt</th>\n",
" <th>IsDt</th>\n",
" <th>IsST</th>\n",
" <th>IsGoDelist</th>\n",
" <th>FloatShares</th>\n",
" <th>MarketValues</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-04</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.566080e+08</td>\n",
" <td>1.224020e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-05</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.566080e+08</td>\n",
" <td>1.241983e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-06</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.566080e+08</td>\n",
" <td>1.234284e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-09</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.566080e+08</td>\n",
" <td>1.277908e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-10</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.566080e+08</td>\n",
" <td>1.285606e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7718</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-04</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.935217e+10</td>\n",
" <td>2.081069e+11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7719</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-05</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.935217e+10</td>\n",
" <td>2.098680e+11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7720</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-08</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.935217e+10</td>\n",
" <td>2.089875e+11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7721</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-09</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.935217e+10</td>\n",
" <td>2.089875e+11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7722</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-10</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2.935217e+10</td>\n",
" <td>2.081069e+11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7723 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate IsZt IsDt IsST IsGoDelist FloatShares \\\n",
"0 000400.SZ 2006-01-04 0 0 0 0 2.566080e+08 \n",
"1 000400.SZ 2006-01-05 0 0 0 0 2.566080e+08 \n",
"2 000400.SZ 2006-01-06 0 0 0 0 2.566080e+08 \n",
"3 000400.SZ 2006-01-09 0 0 0 0 2.566080e+08 \n",
"4 000400.SZ 2006-01-10 0 0 0 0 2.566080e+08 \n",
"... ... ... ... ... ... ... ... \n",
"7718 600000.SH 2022-08-04 0 0 0 0 2.935217e+10 \n",
"7719 600000.SH 2022-08-05 0 0 0 0 2.935217e+10 \n",
"7720 600000.SH 2022-08-08 0 0 0 0 2.935217e+10 \n",
"7721 600000.SH 2022-08-09 0 0 0 0 2.935217e+10 \n",
"7722 600000.SH 2022-08-10 0 0 0 0 2.935217e+10 \n",
"\n",
" MarketValues \n",
"0 1.224020e+09 \n",
"1 1.241983e+09 \n",
"2 1.234284e+09 \n",
"3 1.277908e+09 \n",
"4 1.285606e+09 \n",
"... ... \n",
"7718 2.081069e+11 \n",
"7719 2.098680e+11 \n",
"7720 2.089875e+11 \n",
"7721 2.089875e+11 \n",
"7722 2.081069e+11 \n",
"\n",
"[7723 rows x 8 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dolphindb as ddb\n",
"\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" select code, m_nDate, IsZt, IsDt, IsST, IsGoDelist, FloatShares, MarketValues \n",
" from loadTable('dfs://daily_stock_ts', 'daily_kline')\n",
" where code in (\"600000.SH\", \"000400.SZ\")\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "d6831dd2-75b7-41db-9f87-3e9df85a8699",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-01-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-01-05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-01-06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-01-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-01-08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>719</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-12-27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>720</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-12-28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>721</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-12-29</td>\n",
" </tr>\n",
" <tr>\n",
" <th>722</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-12-30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>723</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-12-31</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>724 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate\n",
"0 600000.SH 2013-01-04\n",
"1 600000.SH 2013-01-05\n",
"2 600000.SH 2013-01-06\n",
"3 600000.SH 2013-01-07\n",
"4 600000.SH 2013-01-08\n",
".. ... ...\n",
"719 600004.SH 2013-12-27\n",
"720 600004.SH 2013-12-28\n",
"721 600004.SH 2013-12-29\n",
"722 600004.SH 2013-12-30\n",
"723 600004.SH 2013-12-31\n",
"\n",
"[724 rows x 2 columns]"
]
},
"execution_count": 145,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dolphindb as ddb\n",
"\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" tbl = table(100:0, `code`m_nDate, [SYMBOL, DATE])\n",
" \n",
" m_nDate = 2013.01.04..2013.12.31;\n",
" code = take('600000.SH', size(m_nDate));\n",
" tbl.append!(table(code, m_nDate));\n",
" \n",
" m_nDate = 2013.01.04..2013.12.31;\n",
" code = take('600004.SH', size(m_nDate));\n",
" tbl.append!(table(code, m_nDate));\n",
" \n",
" tbl;\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "616c7cd3-7871-43c6-b619-f7137fc6556e",
"metadata": {},
"outputs": [],
"source": [
"import dolphindb as ddb\n",
"\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a98da4c3-cf3c-4429-b51f-dba8a1f4d2d3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000515.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000558.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000602.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000677.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5010</th>\n",
" <td>688272.SH</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5011</th>\n",
" <td>688320.SH</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5012</th>\n",
" <td>688739.SH</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5013</th>\n",
" <td>688777.SH</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5014</th>\n",
" <td>830964.NE</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5015 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" code\n",
"0 000400.SZ\n",
"1 000515.SZ\n",
"2 000558.SZ\n",
"3 000602.SZ\n",
"4 000677.SZ\n",
"... ...\n",
"5010 688272.SH\n",
"5011 688320.SH\n",
"5012 688739.SH\n",
"5013 688777.SH\n",
"5014 830964.NE\n",
"\n",
"[5015 rows x 1 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = sess.run(\"\"\"\n",
" select code from loadTable('dfs://daily_stock_ts', 'idx_daily_concept') group by code\n",
"\"\"\")\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "1743a25d-c627-42b4-b6da-b250884a2252",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>stock_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000515.SZ</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000558.SZ</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000602.SZ</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000677.SZ</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5010</th>\n",
" <td>688272.SH</td>\n",
" <td>5010</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5011</th>\n",
" <td>688320.SH</td>\n",
" <td>5011</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5012</th>\n",
" <td>688739.SH</td>\n",
" <td>5012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5013</th>\n",
" <td>688777.SH</td>\n",
" <td>5013</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5014</th>\n",
" <td>830964.NE</td>\n",
" <td>5014</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5015 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" code stock_id\n",
"0 000400.SZ 0\n",
"1 000515.SZ 1\n",
"2 000558.SZ 2\n",
"3 000602.SZ 3\n",
"4 000677.SZ 4\n",
"... ... ...\n",
"5010 688272.SH 5010\n",
"5011 688320.SH 5011\n",
"5012 688739.SH 5012\n",
"5013 688777.SH 5013\n",
"5014 830964.NE 5014\n",
"\n",
"[5015 rows x 2 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"stock_id\"] = df.index\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "31f2b644-e4b8-4c96-be54-edc7367370de",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>stock_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000515.SZ</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000558.SZ</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000602.SZ</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000677.SZ</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5010</th>\n",
" <td>688272.SH</td>\n",
" <td>5010</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5011</th>\n",
" <td>688320.SH</td>\n",
" <td>5011</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5012</th>\n",
" <td>688739.SH</td>\n",
" <td>5012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5013</th>\n",
" <td>688777.SH</td>\n",
" <td>5013</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5014</th>\n",
" <td>830964.NE</td>\n",
" <td>5014</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5015 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" code stock_id\n",
"0 000400.SZ 0\n",
"1 000515.SZ 1\n",
"2 000558.SZ 2\n",
"3 000602.SZ 3\n",
"4 000677.SZ 4\n",
"... ... ...\n",
"5010 688272.SH 5010\n",
"5011 688320.SH 5011\n",
"5012 688739.SH 5012\n",
"5013 688777.SH 5013\n",
"5014 830964.NE 5014\n",
"\n",
"[5015 rows x 2 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3a249c9-879d-4387-9045-27fe72a38cf3",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" cumsum(select * from loadTable('dfs://daily_stock_ts', 'idx_daily_concept') where code in (\"600000.SH\", \"000400.SZ\", \"600001.SH\") context by code)\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "1c606584-6765-41cd-9487-984e1f2c4bff",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cumsum_SH000016</th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" <th>SH000016</th>\n",
" <th>SH000020</th>\n",
" <th>SH000028</th>\n",
" <th>SH000029</th>\n",
" <th>...</th>\n",
" <th>SZ399980</th>\n",
" <th>SZ399981</th>\n",
" <th>SZ399982</th>\n",
" <th>SZ399983</th>\n",
" <th>SZ399984</th>\n",
" <th>SZ399985</th>\n",
" <th>SZ399986</th>\n",
" <th>SZ399990</th>\n",
" <th>SZ399995</th>\n",
" <th>SZ399998</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-04</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-05</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-06</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-09</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>000400.SZ</td>\n",
" <td>2006-01-10</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8569</th>\n",
" <td>645</td>\n",
" <td>600001.SH</td>\n",
" <td>2009-12-09</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8570</th>\n",
" <td>645</td>\n",
" <td>600001.SH</td>\n",
" <td>2009-12-10</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8571</th>\n",
" <td>645</td>\n",
" <td>600001.SH</td>\n",
" <td>2009-12-11</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8572</th>\n",
" <td>645</td>\n",
" <td>600001.SH</td>\n",
" <td>2009-12-14</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8573</th>\n",
" <td>645</td>\n",
" <td>600001.SH</td>\n",
" <td>2009-12-15</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>8574 rows × 952 columns</p>\n",
"</div>"
],
"text/plain": [
" cumsum_SH000016 code m_nDate SH000009 SH000010 SH000015 \\\n",
"0 0 000400.SZ 2006-01-04 False False False \n",
"1 0 000400.SZ 2006-01-05 False False False \n",
"2 0 000400.SZ 2006-01-06 False False False \n",
"3 0 000400.SZ 2006-01-09 False False False \n",
"4 0 000400.SZ 2006-01-10 False False False \n",
"... ... ... ... ... ... ... \n",
"8569 645 600001.SH 2009-12-09 False True True \n",
"8570 645 600001.SH 2009-12-10 False True True \n",
"8571 645 600001.SH 2009-12-11 False True True \n",
"8572 645 600001.SH 2009-12-14 False True True \n",
"8573 645 600001.SH 2009-12-15 False True True \n",
"\n",
" SH000016 SH000020 SH000028 SH000029 ... SZ399980 SZ399981 \\\n",
"0 False False False False ... False False \n",
"1 False False False False ... False False \n",
"2 False False False False ... False False \n",
"3 False False False False ... False False \n",
"4 False False False False ... False False \n",
"... ... ... ... ... ... ... ... \n",
"8569 False False False True ... False False \n",
"8570 False False False True ... False False \n",
"8571 False False False True ... False False \n",
"8572 False False False True ... False False \n",
"8573 False False False True ... False False \n",
"\n",
" SZ399982 SZ399983 SZ399984 SZ399985 SZ399986 SZ399990 SZ399995 \\\n",
"0 False False False False False False False \n",
"1 False False False False False False False \n",
"2 False False False False False False False \n",
"3 False False False False False False False \n",
"4 False False False False False False False \n",
"... ... ... ... ... ... ... ... \n",
"8569 False False False False False False False \n",
"8570 False False False False False False False \n",
"8571 False False False False False False False \n",
"8572 False False False False False False False \n",
"8573 False False False False False False False \n",
"\n",
" SZ399998 \n",
"0 False \n",
"1 False \n",
"2 False \n",
"3 False \n",
"4 False \n",
"... ... \n",
"8569 False \n",
"8570 False \n",
"8571 False \n",
"8572 False \n",
"8573 False \n",
"\n",
"[8574 rows x 952 columns]"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"sess.run(\"\"\"\n",
" tbl = select cumsum(SH000016), * from loadTable('dfs://daily_stock_ts', 'idx_daily_concept') where code in (\"600000.SH\", \"000400.SZ\", \"600001.SH\",) context by code;\n",
" tbl;\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "5d51ac5d-b17f-4105-85b8-63e3a0c4e962",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cumsum_SH000016</th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" <th>SH000016</th>\n",
" <th>SH000020</th>\n",
" <th>SH000028</th>\n",
" <th>SH000029</th>\n",
" <th>...</th>\n",
" <th>SZ399980</th>\n",
" <th>SZ399981</th>\n",
" <th>SZ399982</th>\n",
" <th>SZ399983</th>\n",
" <th>SZ399984</th>\n",
" <th>SZ399985</th>\n",
" <th>SZ399986</th>\n",
" <th>SZ399990</th>\n",
" <th>SZ399995</th>\n",
" <th>SZ399998</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-04</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-05</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-06</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-09</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-10</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3932</th>\n",
" <td>3895</td>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-04</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3933</th>\n",
" <td>3895</td>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-05</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3934</th>\n",
" <td>3895</td>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-08</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3935</th>\n",
" <td>3895</td>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-09</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3936</th>\n",
" <td>3895</td>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-10</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3937 rows × 952 columns</p>\n",
"</div>"
],
"text/plain": [
" cumsum_SH000016 code m_nDate SH000009 SH000010 SH000015 \\\n",
"0 1 600000.SH 2006-01-04 False True False \n",
"1 2 600000.SH 2006-01-05 False True False \n",
"2 3 600000.SH 2006-01-06 False True False \n",
"3 4 600000.SH 2006-01-09 False True False \n",
"4 5 600000.SH 2006-01-10 False True False \n",
"... ... ... ... ... ... ... \n",
"3932 3895 600000.SH 2022-08-04 False True False \n",
"3933 3895 600000.SH 2022-08-05 False True False \n",
"3934 3895 600000.SH 2022-08-08 False True False \n",
"3935 3895 600000.SH 2022-08-09 False True False \n",
"3936 3895 600000.SH 2022-08-10 False True False \n",
"\n",
" SH000016 SH000020 SH000028 SH000029 ... SZ399980 SZ399981 \\\n",
"0 True False False False ... False False \n",
"1 True False False False ... False False \n",
"2 True False False False ... False False \n",
"3 True False False False ... False False \n",
"4 True False False False ... False False \n",
"... ... ... ... ... ... ... ... \n",
"3932 False False False True ... True True \n",
"3933 False False False True ... True True \n",
"3934 False False False True ... True True \n",
"3935 False False False True ... True True \n",
"3936 False False False True ... True True \n",
"\n",
" SZ399982 SZ399983 SZ399984 SZ399985 SZ399986 SZ399990 SZ399995 \\\n",
"0 False False False False False False False \n",
"1 False False False False False False False \n",
"2 False False False False False False False \n",
"3 False False False False False False False \n",
"4 False False False False False False False \n",
"... ... ... ... ... ... ... ... \n",
"3932 False False True True True False False \n",
"3933 False False True True True False False \n",
"3934 False False True True True False False \n",
"3935 False False True True True False False \n",
"3936 False False True True True False False \n",
"\n",
" SZ399998 \n",
"0 False \n",
"1 False \n",
"2 False \n",
"3 False \n",
"4 False \n",
"... ... \n",
"3932 False \n",
"3933 False \n",
"3934 False \n",
"3935 False \n",
"3936 False \n",
"\n",
"[3937 rows x 952 columns]"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select * from tbl where code='600000.SH'\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "6ef3d70e-b8a3-4a17-91bd-2dc4a37a993f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" <th>SH000016</th>\n",
" <th>SH000020</th>\n",
" <th>SH000028</th>\n",
" <th>SH000029</th>\n",
" <th>SH000030</th>\n",
" <th>...</th>\n",
" <th>SZ399980</th>\n",
" <th>SZ399981</th>\n",
" <th>SZ399982</th>\n",
" <th>SZ399983</th>\n",
" <th>SZ399984</th>\n",
" <th>SZ399985</th>\n",
" <th>SZ399986</th>\n",
" <th>SZ399990</th>\n",
" <th>SZ399995</th>\n",
" <th>SZ399998</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-04</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-05</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-06</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-09</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-01-10</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3932</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-04</td>\n",
" <td>0</td>\n",
" <td>3933</td>\n",
" <td>942</td>\n",
" <td>3895</td>\n",
" <td>0</td>\n",
" <td>2973</td>\n",
" <td>3128</td>\n",
" <td>2973</td>\n",
" <td>...</td>\n",
" <td>2701</td>\n",
" <td>2678</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2642</td>\n",
" <td>2642</td>\n",
" <td>2174</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3933</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-05</td>\n",
" <td>0</td>\n",
" <td>3934</td>\n",
" <td>942</td>\n",
" <td>3895</td>\n",
" <td>0</td>\n",
" <td>2973</td>\n",
" <td>3129</td>\n",
" <td>2973</td>\n",
" <td>...</td>\n",
" <td>2702</td>\n",
" <td>2679</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2643</td>\n",
" <td>2643</td>\n",
" <td>2175</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3934</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-08</td>\n",
" <td>0</td>\n",
" <td>3935</td>\n",
" <td>942</td>\n",
" <td>3895</td>\n",
" <td>0</td>\n",
" <td>2973</td>\n",
" <td>3130</td>\n",
" <td>2973</td>\n",
" <td>...</td>\n",
" <td>2703</td>\n",
" <td>2680</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2644</td>\n",
" <td>2644</td>\n",
" <td>2176</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3935</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-09</td>\n",
" <td>0</td>\n",
" <td>3936</td>\n",
" <td>942</td>\n",
" <td>3895</td>\n",
" <td>0</td>\n",
" <td>2973</td>\n",
" <td>3131</td>\n",
" <td>2973</td>\n",
" <td>...</td>\n",
" <td>2704</td>\n",
" <td>2681</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2645</td>\n",
" <td>2645</td>\n",
" <td>2177</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3936</th>\n",
" <td>600000.SH</td>\n",
" <td>2022-08-10</td>\n",
" <td>0</td>\n",
" <td>3937</td>\n",
" <td>942</td>\n",
" <td>3895</td>\n",
" <td>0</td>\n",
" <td>2973</td>\n",
" <td>3132</td>\n",
" <td>2973</td>\n",
" <td>...</td>\n",
" <td>2705</td>\n",
" <td>2682</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2646</td>\n",
" <td>2646</td>\n",
" <td>2178</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3937 rows × 951 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate SH000009 SH000010 SH000015 SH000016 SH000020 \\\n",
"0 600000.SH 2006-01-04 0 1 0 1 0 \n",
"1 600000.SH 2006-01-05 0 2 0 2 0 \n",
"2 600000.SH 2006-01-06 0 3 0 3 0 \n",
"3 600000.SH 2006-01-09 0 4 0 4 0 \n",
"4 600000.SH 2006-01-10 0 5 0 5 0 \n",
"... ... ... ... ... ... ... ... \n",
"3932 600000.SH 2022-08-04 0 3933 942 3895 0 \n",
"3933 600000.SH 2022-08-05 0 3934 942 3895 0 \n",
"3934 600000.SH 2022-08-08 0 3935 942 3895 0 \n",
"3935 600000.SH 2022-08-09 0 3936 942 3895 0 \n",
"3936 600000.SH 2022-08-10 0 3937 942 3895 0 \n",
"\n",
" SH000028 SH000029 SH000030 ... SZ399980 SZ399981 SZ399982 \\\n",
"0 0 0 0 ... 0 0 0 \n",
"1 0 0 0 ... 0 0 0 \n",
"2 0 0 0 ... 0 0 0 \n",
"3 0 0 0 ... 0 0 0 \n",
"4 0 0 0 ... 0 0 0 \n",
"... ... ... ... ... ... ... ... \n",
"3932 2973 3128 2973 ... 2701 2678 0 \n",
"3933 2973 3129 2973 ... 2702 2679 0 \n",
"3934 2973 3130 2973 ... 2703 2680 0 \n",
"3935 2973 3131 2973 ... 2704 2681 0 \n",
"3936 2973 3132 2973 ... 2705 2682 0 \n",
"\n",
" SZ399983 SZ399984 SZ399985 SZ399986 SZ399990 SZ399995 SZ399998 \n",
"0 0 0 0 0 0 0 0 \n",
"1 0 0 0 0 0 0 0 \n",
"2 0 0 0 0 0 0 0 \n",
"3 0 0 0 0 0 0 0 \n",
"4 0 0 0 0 0 0 0 \n",
"... ... ... ... ... ... ... ... \n",
"3932 0 2642 2642 2174 0 0 0 \n",
"3933 0 2643 2643 2175 0 0 0 \n",
"3934 0 2644 2644 2176 0 0 0 \n",
"3935 0 2645 2645 2177 0 0 0 \n",
"3936 0 2646 2646 2178 0 0 0 \n",
"\n",
"[3937 rows x 951 columns]"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" cumsum(select * from loadTable('dfs://daily_stock_ts', 'idx_daily_concept') where code in (\"600000.SH\"))\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e5c75dfd-b9e8-4ab1-b0a0-684d96852d32",
"metadata": {},
"outputs": [],
"source": [
"df = df[['code', 'm_nDate', 'SH000009', 'SH000010', 'SH000015']]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1242241b-c0dc-4ff8-a84b-ed3877db1acb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_nDate</th>\n",
" <th>code</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2006-01-04</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-05</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-06</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-09</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-10</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-04</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-05</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-08</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-09</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-10</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7723 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 000400.SZ False False False\n",
"2006-01-05 000400.SZ False False False\n",
"2006-01-06 000400.SZ False False False\n",
"2006-01-09 000400.SZ False False False\n",
"2006-01-10 000400.SZ False False False\n",
"... ... ... ...\n",
"2022-08-04 600000.SH False True False\n",
"2022-08-05 600000.SH False True False\n",
"2022-08-08 600000.SH False True False\n",
"2022-08-09 600000.SH False True False\n",
"2022-08-10 600000.SH False True False\n",
"\n",
"[7723 rows x 3 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.set_index(['m_nDate', 'code'], inplace=True)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "aedb5cde-bfee-4e38-bbf1-9d8a763a0cd9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4034"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_groups = df.groupby(axis=0, level=\"m_nDate\")\n",
"len(df_groups)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "62de77bd-7c19-49a5-bce4-05989346afd8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2006-01-04', '2006-01-05', '2006-01-06', '2006-01-09',\n",
" '2006-01-10', '2006-01-11', '2006-01-12', '2006-01-13',\n",
" '2006-01-16', '2006-01-17',\n",
" ...\n",
" '2022-07-28', '2022-07-29', '2022-08-01', '2022-08-02',\n",
" '2022-08-03', '2022-08-04', '2022-08-05', '2022-08-08',\n",
" '2022-08-09', '2022-08-10'],\n",
" dtype='datetime64[ns]', name='m_nDate', length=4034, freq=None)"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index_datetime = df.index.unique(level=\"m_nDate\").sort_values(ascending=True)\n",
"index_datetime"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "a2e9d3a5-7a78-486c-a726-2070336d5f49",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"m_nDate\n",
"2006-01-04 1.000000\n",
"2006-01-05 1.024547\n",
"2006-01-06 1.049095\n",
"2006-01-09 1.073642\n",
"2006-01-10 1.098190\n",
" ... \n",
"2022-08-04 99.901810\n",
"2022-08-05 99.926358\n",
"2022-08-08 99.950905\n",
"2022-08-09 99.975453\n",
"2022-08-10 100.000000\n",
"Name: weight, Length: 4034, dtype: float64"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"series = pd.Series(np.linspace(1.0, 100.0, len(index_datetime)), index=index_datetime, name=\"weight\")\n",
"series"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "889094a8-06a9-412d-8a45-5412ec507856",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>weight</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_nDate</th>\n",
" <th>code</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2006-01-04</th>\n",
" <th>000400.SZ</th>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600000.SH</th>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2006-01-05</th>\n",
" <th>000400.SZ</th>\n",
" <td>1.024547</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600000.SH</th>\n",
" <td>1.024547</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-06</th>\n",
" <th>000400.SZ</th>\n",
" <td>1.049095</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-08</th>\n",
" <th>600000.SH</th>\n",
" <td>99.950905</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2022-08-09</th>\n",
" <th>000400.SZ</th>\n",
" <td>99.975453</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600000.SH</th>\n",
" <td>99.975453</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2022-08-10</th>\n",
" <th>000400.SZ</th>\n",
" <td>100.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600000.SH</th>\n",
" <td>100.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7723 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" weight\n",
"m_nDate code \n",
"2006-01-04 000400.SZ 1.000000\n",
" 600000.SH 1.000000\n",
"2006-01-05 000400.SZ 1.024547\n",
" 600000.SH 1.024547\n",
"2006-01-06 000400.SZ 1.049095\n",
"... ...\n",
"2022-08-08 600000.SH 99.950905\n",
"2022-08-09 000400.SZ 99.975453\n",
" 600000.SH 99.975453\n",
"2022-08-10 000400.SZ 100.000000\n",
" 600000.SH 100.000000\n",
"\n",
"[7723 rows x 1 columns]"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = pd.DataFrame(index=df.index, )\n",
"df3 = df2.join(series, on=\"m_nDate\")\n",
"df3.sort_index(level=\"m_nDate\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c62690d3-b263-4c4e-97db-f7d609524f2d",
"metadata": {},
"outputs": [],
"source": [
"df3."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "e8386b34-41a3-42fe-a36a-d54509f5ccb1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>(2006-01-04 00:00:00, 000400.SZ)</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>(2006-01-05 00:00:00, 000400.SZ)</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>(2006-01-06 00:00:00, 000400.SZ)</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>(2006-01-09 00:00:00, 000400.SZ)</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>(2006-01-10 00:00:00, 000400.SZ)</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1379894400000000000</th>\n",
" <td>99.901810</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1379980800000000000</th>\n",
" <td>99.926358</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1380067200000000000</th>\n",
" <td>99.950905</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1380153600000000000</th>\n",
" <td>99.975453</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1380240000000000000</th>\n",
" <td>100.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>11757 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" 0\n",
"(2006-01-04 00:00:00, 000400.SZ) NaN\n",
"(2006-01-05 00:00:00, 000400.SZ) NaN\n",
"(2006-01-06 00:00:00, 000400.SZ) NaN\n",
"(2006-01-09 00:00:00, 000400.SZ) NaN\n",
"(2006-01-10 00:00:00, 000400.SZ) NaN\n",
"... ...\n",
"1379894400000000000 99.901810\n",
"1379980800000000000 99.926358\n",
"1380067200000000000 99.950905\n",
"1380153600000000000 99.975453\n",
"1380240000000000000 100.000000\n",
"\n",
"[11757 rows x 1 columns]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.concat([df2, series])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "392da2ae-51e1-41d1-a3f6-044506e1cf63",
"metadata": {},
"outputs": [],
"source": [
"dfs = []\n",
"for code, df_sub in df.groupby(level=\"code\"):\n",
" dfs.append((df_sub.index, df_sub.values))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2fae9b71-0e29-4717-afb6-e3540d06ed67",
"metadata": {},
"outputs": [],
"source": [
"index_list, data_list = zip(*dfs)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "910caab8-38ea-4b7d-acc6-b5d0275f46a0",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"index = np.concatenate(index_list)\n",
"data = np.concatenate(data_list)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "3ea1efee-f719-4b42-a815-83c1e39a6beb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MultiIndex([('2006-01-04', '000400.SZ'),\n",
" ('2006-01-05', '000400.SZ'),\n",
" ('2006-01-06', '000400.SZ'),\n",
" ('2006-01-09', '000400.SZ'),\n",
" ('2006-01-10', '000400.SZ'),\n",
" ('2006-01-11', '000400.SZ'),\n",
" ('2006-01-12', '000400.SZ'),\n",
" ('2006-01-13', '000400.SZ'),\n",
" ('2006-01-16', '000400.SZ'),\n",
" ('2006-01-17', '000400.SZ'),\n",
" ...\n",
" ('2022-07-28', '000400.SZ'),\n",
" ('2022-07-29', '000400.SZ'),\n",
" ('2022-08-01', '000400.SZ'),\n",
" ('2022-08-02', '000400.SZ'),\n",
" ('2022-08-03', '000400.SZ'),\n",
" ('2022-08-04', '000400.SZ'),\n",
" ('2022-08-05', '000400.SZ'),\n",
" ('2022-08-08', '000400.SZ'),\n",
" ('2022-08-09', '000400.SZ'),\n",
" ('2022-08-10', '000400.SZ')],\n",
" names=['m_nDate', 'code'], length=3786)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index_list[0]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "c88aba7b-8069-4d2b-bba4-b6af420c82ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MultiIndex([('2006-01-04', '000400.SZ'),\n",
" ('2006-01-05', '000400.SZ'),\n",
" ('2006-01-06', '000400.SZ'),\n",
" ('2006-01-09', '000400.SZ'),\n",
" ('2006-01-10', '000400.SZ'),\n",
" ('2006-01-11', '000400.SZ'),\n",
" ('2006-01-12', '000400.SZ'),\n",
" ('2006-01-13', '000400.SZ'),\n",
" ('2006-01-16', '000400.SZ'),\n",
" ('2006-01-17', '000400.SZ'),\n",
" ...\n",
" ('2022-07-28', '600000.SH'),\n",
" ('2022-07-29', '600000.SH'),\n",
" ('2022-08-01', '600000.SH'),\n",
" ('2022-08-02', '600000.SH'),\n",
" ('2022-08-03', '600000.SH'),\n",
" ('2022-08-04', '600000.SH'),\n",
" ('2022-08-05', '600000.SH'),\n",
" ('2022-08-08', '600000.SH'),\n",
" ('2022-08-09', '600000.SH'),\n",
" ('2022-08-10', '600000.SH')],\n",
" names=['datetime', 'instrument'], length=7723)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.MultiIndex.from_tuples(index, names=['datetime', 'instrument'])"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "04129932-e234-403a-b193-997c7d9ad014",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"df2 = pd.DataFrame(data, index=pd.MultiIndex.from_tuples(index, names=['datetime', 'instrument']), columns=df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "cf85603e-44af-47e0-8c1d-ac1fa2750528",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" </tr>\n",
" <tr>\n",
" <th>datetime</th>\n",
" <th>instrument</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2006-01-04</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-05</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-06</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-09</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-10</th>\n",
" <th>000400.SZ</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-04</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-05</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-08</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-09</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-10</th>\n",
" <th>600000.SH</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7723 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" SH000009 SH000010 SH000015\n",
"datetime instrument \n",
"2006-01-04 000400.SZ False False False\n",
"2006-01-05 000400.SZ False False False\n",
"2006-01-06 000400.SZ False False False\n",
"2006-01-09 000400.SZ False False False\n",
"2006-01-10 000400.SZ False False False\n",
"... ... ... ...\n",
"2022-08-04 600000.SH False True False\n",
"2022-08-05 600000.SH False True False\n",
"2022-08-08 600000.SH False True False\n",
"2022-08-09 600000.SH False True False\n",
"2022-08-10 600000.SH False True False\n",
"\n",
"[7723 rows x 3 columns]"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "0f5085bb-b70d-4551-a8bd-87aee7696b94",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['SH000009', 'SH000010', 'SH000015'], dtype='object')"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2.columns"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9e3aa8b8-2c55-45dc-8ab4-9bf255affb61",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_nDate</th>\n",
" <th>code</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2006-01-04</th>\n",
" <th>000400.SZ</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-05</th>\n",
" <th>000400.SZ</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-06</th>\n",
" <th>000400.SZ</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-09</th>\n",
" <th>000400.SZ</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006-01-10</th>\n",
" <th>000400.SZ</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-04</th>\n",
" <th>600000.SH</th>\n",
" <td>0</td>\n",
" <td>3933</td>\n",
" <td>942</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-05</th>\n",
" <th>600000.SH</th>\n",
" <td>0</td>\n",
" <td>3934</td>\n",
" <td>942</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-08</th>\n",
" <th>600000.SH</th>\n",
" <td>0</td>\n",
" <td>3935</td>\n",
" <td>942</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-09</th>\n",
" <th>600000.SH</th>\n",
" <td>0</td>\n",
" <td>3936</td>\n",
" <td>942</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-10</th>\n",
" <th>600000.SH</th>\n",
" <td>0</td>\n",
" <td>3937</td>\n",
" <td>942</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7723 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 000400.SZ 0 0 0\n",
"2006-01-05 000400.SZ 0 0 0\n",
"2006-01-06 000400.SZ 0 0 0\n",
"2006-01-09 000400.SZ 0 0 0\n",
"2006-01-10 000400.SZ 0 0 0\n",
"... ... ... ...\n",
"2022-08-04 600000.SH 0 3933 942\n",
"2022-08-05 600000.SH 0 3934 942\n",
"2022-08-08 600000.SH 0 3935 942\n",
"2022-08-09 600000.SH 0 3936 942\n",
"2022-08-10 600000.SH 0 3937 942\n",
"\n",
"[7723 rows x 3 columns]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby(axis=0, level='code').apply('cumsum')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e0255168-01e4-43fe-b480-dbd76aeec26f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 000400.SZ False False False\n",
"2006-01-05 000400.SZ False False False\n",
"2006-01-06 000400.SZ False False False\n",
"2006-01-09 000400.SZ False False False\n",
"2006-01-10 000400.SZ False False False\n",
"<bound method NDFrame.head of SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 000400.SZ 0 0 0\n",
"2006-01-05 000400.SZ 0 0 0\n",
"2006-01-06 000400.SZ 0 0 0\n",
"2006-01-09 000400.SZ 0 0 0\n",
"2006-01-10 000400.SZ 0 0 0\n",
"... ... ... ...\n",
"2022-08-04 000400.SZ 0 0 0\n",
"2022-08-05 000400.SZ 0 0 0\n",
"2022-08-08 000400.SZ 0 0 0\n",
"2022-08-09 000400.SZ 0 0 0\n",
"2022-08-10 000400.SZ 0 0 0\n",
"\n",
"[3786 rows x 3 columns]>\n",
" SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 600000.SH False True False\n",
"2006-01-05 600000.SH False True False\n",
"2006-01-06 600000.SH False True False\n",
"2006-01-09 600000.SH False True False\n",
"2006-01-10 600000.SH False True False\n",
"<bound method NDFrame.head of SH000009 SH000010 SH000015\n",
"m_nDate code \n",
"2006-01-04 600000.SH 0 1 0\n",
"2006-01-05 600000.SH 0 2 0\n",
"2006-01-06 600000.SH 0 3 0\n",
"2006-01-09 600000.SH 0 4 0\n",
"2006-01-10 600000.SH 0 5 0\n",
"... ... ... ...\n",
"2022-08-04 600000.SH 0 3933 942\n",
"2022-08-05 600000.SH 0 3934 942\n",
"2022-08-08 600000.SH 0 3935 942\n",
"2022-08-09 600000.SH 0 3936 942\n",
"2022-08-10 600000.SH 0 3937 942\n",
"\n",
"[3937 rows x 3 columns]>\n"
]
}
],
"source": [
"for code, sub_df in .\n",
".:\n",
" print(sub_df.head())\n",
" sub_df = sub_df.apply('cumsum')\n",
" print(sub_df.head)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5357df6d-12ce-4421-ac81-3356e9c3e708",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 147,
"id": "86761b9b-cd9d-4cba-8b65-ad70c4fe3ab5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>m_nDate</th>\n",
" <th>SH000009</th>\n",
" <th>SH000010</th>\n",
" <th>SH000015</th>\n",
" <th>SH000016</th>\n",
" <th>SH000020</th>\n",
" <th>SH000028</th>\n",
" <th>SH000029</th>\n",
" <th>SH000030</th>\n",
" <th>...</th>\n",
" <th>SZ399980</th>\n",
" <th>SZ399981</th>\n",
" <th>SZ399982</th>\n",
" <th>SZ399983</th>\n",
" <th>SZ399984</th>\n",
" <th>SZ399985</th>\n",
" <th>SZ399986</th>\n",
" <th>SZ399990</th>\n",
" <th>SZ399995</th>\n",
" <th>SZ399998</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-01-04</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-01-07</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-01-08</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-01-09</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600004.SH</td>\n",
" <td>2013-01-10</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>471</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-25</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>472</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-26</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>473</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-27</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>474</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-30</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>475</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-31</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>476 rows × 951 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate SH000009 SH000010 SH000015 SH000016 SH000020 \\\n",
"0 600004.SH 2013-01-04 True False True False False \n",
"1 600004.SH 2013-01-07 True False False False False \n",
"2 600004.SH 2013-01-08 True False False False False \n",
"3 600004.SH 2013-01-09 True False False False False \n",
"4 600004.SH 2013-01-10 True False False False False \n",
".. ... ... ... ... ... ... ... \n",
"471 600000.SH 2013-12-25 False True True True False \n",
"472 600000.SH 2013-12-26 False True True True False \n",
"473 600000.SH 2013-12-27 False True True True False \n",
"474 600000.SH 2013-12-30 False True True True False \n",
"475 600000.SH 2013-12-31 False True True True False \n",
"\n",
" SH000028 SH000029 SH000030 ... SZ399980 SZ399981 SZ399982 \\\n",
"0 False False False ... False False True \n",
"1 False False False ... False False True \n",
"2 False False False ... False False True \n",
"3 False False False ... False False True \n",
"4 False False False ... False False True \n",
".. ... ... ... ... ... ... ... \n",
"471 True True True ... True True False \n",
"472 True True True ... True True False \n",
"473 True True True ... True True False \n",
"474 True True True ... True True False \n",
"475 True True True ... True True False \n",
"\n",
" SZ399983 SZ399984 SZ399985 SZ399986 SZ399990 SZ399995 SZ399998 \n",
"0 False False True False False False False \n",
"1 False False True False False False False \n",
"2 False False True False False False False \n",
"3 False False True False False False False \n",
"4 False False True False False False False \n",
".. ... ... ... ... ... ... ... \n",
"471 False True True True False False False \n",
"472 False True True True False False False \n",
"473 False True True True False False False \n",
"474 False True True True False False False \n",
"475 False True True True False False False \n",
"\n",
"[476 rows x 951 columns]"
]
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"select top 1000 * from ej(tbl, loadTable('dfs://daily_stock_ts', 'idx_daily_concept'), `code`m_nDate) map\")"
]
},
{
"cell_type": "code",
"execution_count": 120,
"id": "a4cd1087-f2e0-491f-92c3-6359c7a5135d",
"metadata": {},
"outputs": [],
"source": [
"df = df.set_index(['code', 'm_nDate']).astype('int')"
]
},
{
"cell_type": "code",
"execution_count": 121,
"id": "7397b95c-a451-4b3a-a8d8-9c99c01180dc",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "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
"text/plain": [
"<Figure size 2304x2304 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(32, 32))\n",
"ax = sns.heatmap(df.to_numpy()[:,:], cmap='hot')"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "d2d5e7d0-c84a-49fc-ab22-5c07d28699b8",
"metadata": {},
"outputs": [],
"source": [
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "112c1ea9-fa76-418a-ad75-e2191aac85fa",
"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
}