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.

3655 lines
122 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7246e0c8-61cd-4cbf-a978-aa0dc0172d6d",
"metadata": {},
"outputs": [],
"source": [
"import dolphindb as ddb"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5d0f471e-682e-43cc-abdb-7e52f3bbd707",
"metadata": {},
"outputs": [],
"source": [
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fca58bdc-2aa1-4610-9a94-67d55f97a6e1",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" migrate('/data/dolphindb/backup/', \"dfs://hft_stock_ts\", \"OrderPartitioned\")\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed17fd0b-9b36-47e4-9ab6-11459a3621fb",
"metadata": {},
"outputs": [],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"# backup(backup_path, sql_obj, force, parallel)\n",
"code = \"\"\"\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://hft_stock_ts\", \"TransePartitioned\")>, false, false)\n",
"\"\"\"\n",
"\n",
"sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "c8d07fc8-d80c-490f-9220-0d3e8e4c72a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"# backup(backup_path, sql_obj, force, parallel)\n",
"code = \"\"\"\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"bs_common_ori\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"bs_common_adj\")>, true, false);\n",
" \n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"cfs_common_ori\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"cfs_common_adj\")>, true, false);\n",
" \n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"is_common_adj\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"is_common_adj\")>, true, false);\n",
" \n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"divident\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"earnings_preannouncement\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://pit_stock_ts\", \"preliminary_earnings_estimate\")>, true, false);\n",
"\"\"\"\n",
"\n",
"sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "45c4cbc3-08a1-4083-8117-44e8e3364375",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dolphindb as ddb\n",
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"# backup(backup_path, sql_obj, force, parallel)\n",
"sess.run(\"\"\"\n",
" // backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"hft_daily_factor\")>, false, false);\n",
" // backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"idx_daily_concept\")>, false, false);\n",
" // backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"daily_kline\")>, false, false);\n",
" //backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"idx_daily_kline\")>, true, true);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"hft_daily_factor\")>, false, false);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "463a59a8-39cf-4406-9390-da5dfdc44fa7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"idx_daily_concept\")>, false, false);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 128,
"id": "84f99b12-e868-425e-bcd3-1733feea7524",
"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>dbName</th>\n",
" <th>tableName</th>\n",
" <th>success</th>\n",
" <th>errorMsg</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>dfs://daily_stock_ts</td>\n",
" <td>hft_daily_factor</td>\n",
" <td>True</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" dbName tableName success errorMsg\n",
"0 dfs://daily_stock_ts hft_daily_factor True "
]
},
"execution_count": 128,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#sess = ddb.session('192.168.1.7', 8848)\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" //dropTable(database(\"dfs://daily_stock_ts\"), \"hft_daily_factor\");\n",
" migrate('/data/dolphindb/backup/', \"dfs://daily_stock_ts\", \"hft_daily_factor\");\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8b7dae3d-aef1-4c50-92b2-460d4fea0a96",
"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>tableName</th>\n",
" <th>physicalIndex</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>daily_factor</td>\n",
" <td>1ffH</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>idx_daily_kline</td>\n",
" <td>1eZs</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>idx_daily_concept</td>\n",
" <td>1esb</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>hft_daily_factor</td>\n",
" <td>1eYB</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>daily_kline</td>\n",
" <td>uoH</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" tableName physicalIndex\n",
"0 daily_factor 1ffH\n",
"1 idx_daily_kline 1eZs\n",
"2 idx_daily_concept 1esb\n",
"3 hft_daily_factor 1eYB\n",
"4 daily_kline uoH"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#sess = ddb.session('192.168.1.7', 8848)\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" //getAllDBs()\n",
" //listTables(\"dfs://info_stock_ts\");\n",
" listTables(\"dfs://daily_stock_ts\");\n",
" //listTables(\"dfs://pit_stock_ts\");\n",
" //schema(loadTable(\"dfs://daily_stock_ts\", \"hft_daily_factor\"))\n",
" //dropTable(database(\"dfs://daily_stock_ts\"), \"idx_daily_kline\")\n",
" //schema(loadTable(\"dfs://pit_stock_ts\", \"earnings_preannouncement\"))\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03c3d7d2-1953-48a4-bf6e-fac3807c0d9c",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" schema(loadTable(\"dfs://pit_stock_ts\", ))\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 153,
"id": "fb23b78d-c402-4c11-9504-c61793e5a2a3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'partitionType': 5,\n",
" 'partitionColumnType': 17,\n",
" 'partitionColumnIndex': 0,\n",
" 'chunkPath': None,\n",
" 'colDefs': name typeString typeInt comment\n",
" 0 code SYMBOL 17 \n",
" 1 m_nDate DATE 6 \n",
" 2 open DOUBLE 16 \n",
" 3 high DOUBLE 16 \n",
" 4 low DOUBLE 16 \n",
" 5 close DOUBLE 16 \n",
" 6 vol DOUBLE 16 \n",
" 7 amount DOUBLE 16 \n",
" 8 cjbs INT 4 \n",
" 9 yclose DOUBLE 16 \n",
" 10 PctChg DOUBLE 16 \n",
" 11 IsZt INT 4 \n",
" 12 IsDt INT 4 \n",
" 13 IsST INT 4 \n",
" 14 IsGoDelist INT 4 \n",
" 15 FloatShares DOUBLE 16 \n",
" 16 MarketValues DOUBLE 16 \n",
" 17 factor DOUBLE 16 ,\n",
" 'chunkGranularity': 'TABLE',\n",
" 'partitionTypeName': 'HASH',\n",
" 'keepDuplicates': 'ALL',\n",
" 'engineType': 'TSDB',\n",
" 'partitionColumnName': 'code',\n",
" 'partitionSchema': 50,\n",
" 'sortColumns': array(['code', 'm_nDate'], dtype=object),\n",
" 'partitionSites': None}"
]
},
"execution_count": 153,
"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",
" schema(loadTable(\"dfs://daily_stock_ts\", \"daily_kline\"))\n",
"\"\"\")\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0a52b3b0-8095-46d7-97e9-f47b56168faf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['code', 'm_nDate']"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['name'].to_list()[:2]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f117c6c9-9b7a-4196-b721-8afaa5f3b3d7",
"metadata": {},
"outputs": [],
"source": [
"df[2:].to_csv(\"../assets/idx_concept_list.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "84e9e3df-aec7-4edf-96fc-2481ed6790b5",
"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>dbName</th>\n",
" <th>tableName</th>\n",
" <th>success</th>\n",
" <th>errorMsg</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>dfs://daily_stock_ts</td>\n",
" <td>idx_daily_concept</td>\n",
" <td>False</td>\n",
" <td>table named idx_daily_concept already existed ...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" dbName tableName success \\\n",
"0 dfs://daily_stock_ts idx_daily_concept False \n",
"\n",
" errorMsg \n",
"0 table named idx_daily_concept already existed ... "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"sess.run(\"\"\"\n",
" migrate('/data/dolphindb/backup/', \"dfs://daily_stock_ts\", \"idx_daily_concept\")\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 157,
"id": "58ac1e6f-51cd-4d35-a34f-8220fca52acb",
"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>report_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>S_PROFITNOTICE_STYLE</th>\n",
" <th>S_PROFITNOTICE_CHANGEMIN</th>\n",
" <th>S_PROFITNOTICE_CHANGEMAX</th>\n",
" <th>S_PROFITNOTICE_NETPROFITMIN</th>\n",
" <th>S_PROFITNOTICE_NETPROFITMAX</th>\n",
" <th>S_PROFITNOTICE_REASON</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600000.SH</td>\n",
" <td>2002-12-31</td>\n",
" <td>2002-08-17</td>\n",
" <td>预增</td>\n",
" <td>10.000</td>\n",
" <td>1.000000e+01</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600000.SH</td>\n",
" <td>2004-12-31</td>\n",
" <td>2005-01-08</td>\n",
" <td>预增</td>\n",
" <td>23.237</td>\n",
" <td>2.323700e+01</td>\n",
" <td>1.930000e+09</td>\n",
" <td>1.930000e+09</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600000.SH</td>\n",
" <td>2007-06-30</td>\n",
" <td>2007-07-20</td>\n",
" <td>预增</td>\n",
" <td>50.000</td>\n",
" <td>1.000000e+08</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-03-31</td>\n",
" <td>2008-04-14</td>\n",
" <td>预增</td>\n",
" <td>180.000</td>\n",
" <td>1.000000e+08</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-06-30</td>\n",
" <td>2008-04-26</td>\n",
" <td>预警</td>\n",
" <td>0.000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>公司资产规模增长.利差提高.非利息收入增长.有效所得税率降低.资产质量持续优化.拨备计提减少等。</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-06-30</td>\n",
" <td>2008-07-04</td>\n",
" <td>预增</td>\n",
" <td>140.000</td>\n",
" <td>1.000000e+08</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-09-30</td>\n",
" <td>2008-08-23</td>\n",
" <td>预增</td>\n",
" <td>0.000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>nan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-09-30</td>\n",
" <td>2008-10-14</td>\n",
" <td>预增</td>\n",
" <td>150.000</td>\n",
" <td>1.500000e+02</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>公司2008年一至三季度同比资产规模增长资产质量稳定使风险成本下降利差扩大非利息收入增...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-12-31</td>\n",
" <td>2008-10-30</td>\n",
" <td>预警</td>\n",
" <td>0.000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>实施新税法,有效所得税率降低;公司资产规模进一步扩大,利息收入增加;非利息收入持续增长;资产...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" code report_period appear_at_date S_PROFITNOTICE_STYLE \\\n",
"0 600000.SH 2002-12-31 2002-08-17 预增 \n",
"1 600000.SH 2004-12-31 2005-01-08 预增 \n",
"2 600000.SH 2007-06-30 2007-07-20 预增 \n",
"3 600000.SH 2008-03-31 2008-04-14 预增 \n",
"4 600000.SH 2008-06-30 2008-04-26 预警 \n",
"5 600000.SH 2008-06-30 2008-07-04 预增 \n",
"6 600000.SH 2008-09-30 2008-08-23 预增 \n",
"7 600000.SH 2008-09-30 2008-10-14 预增 \n",
"8 600000.SH 2008-12-31 2008-10-30 预警 \n",
"\n",
" S_PROFITNOTICE_CHANGEMIN S_PROFITNOTICE_CHANGEMAX \\\n",
"0 10.000 1.000000e+01 \n",
"1 23.237 2.323700e+01 \n",
"2 50.000 1.000000e+08 \n",
"3 180.000 1.000000e+08 \n",
"4 0.000 0.000000e+00 \n",
"5 140.000 1.000000e+08 \n",
"6 0.000 0.000000e+00 \n",
"7 150.000 1.500000e+02 \n",
"8 0.000 0.000000e+00 \n",
"\n",
" S_PROFITNOTICE_NETPROFITMIN S_PROFITNOTICE_NETPROFITMAX \\\n",
"0 0.000000e+00 0.000000e+00 \n",
"1 1.930000e+09 1.930000e+09 \n",
"2 0.000000e+00 0.000000e+00 \n",
"3 0.000000e+00 0.000000e+00 \n",
"4 0.000000e+00 0.000000e+00 \n",
"5 0.000000e+00 0.000000e+00 \n",
"6 0.000000e+00 0.000000e+00 \n",
"7 0.000000e+00 0.000000e+00 \n",
"8 0.000000e+00 0.000000e+00 \n",
"\n",
" S_PROFITNOTICE_REASON \n",
"0 nan \n",
"1 nan \n",
"2 nan \n",
"3 nan \n",
"4 公司资产规模增长.利差提高.非利息收入增长.有效所得税率降低.资产质量持续优化.拨备计提减少等。 \n",
"5 nan \n",
"6 nan \n",
"7 公司2008年一至三季度同比资产规模增长资产质量稳定使风险成本下降利差扩大非利息收入增... \n",
"8 实施新税法,有效所得税率降低;公司资产规模进一步扩大,利息收入增加;非利息收入持续增长;资产... "
]
},
"execution_count": 157,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"sess.run(\"\"\"\n",
" // select * from loadTable(\"dfs://daily_stock_ts\", \"daily_kline\") where code='600000.SH' and m_nDate=2020.01.02\n",
" //select min(appear_at_date), max(appear_at_date) from loadTable(\"dfs://pit_stock_ts\", \"earnings_preannouncement\") \n",
" select * from loadTable(\"dfs://pit_stock_ts\", \"earnings_preannouncement\") where code=\"600000.SH\"\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 158,
"id": "a9d1396f-a7e8-4c83-a983-2d48ef894362",
"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>S_PROFITNOTICE_STYLE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>减亏</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>增亏</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>预亏</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>预减</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>预增</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>预平</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>预盈</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>预警</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" S_PROFITNOTICE_STYLE\n",
"0 减亏\n",
"1 增亏\n",
"2 预亏\n",
"3 预减\n",
"4 预增\n",
"5 预平\n",
"6 预盈\n",
"7 预警"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select S_PROFITNOTICE_STYLE from loadTable(\"dfs://pit_stock_ts\", \"earnings_preannouncement\") group by S_PROFITNOTICE_STYLE\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 156,
"id": "5e665dca-835e-4fda-9509-fc79498efe76",
"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>report_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>EQY_RECORD_DT</th>\n",
" <th>EX_DT</th>\n",
" <th>DVD_PAYOUT_DT</th>\n",
" <th>S_DIV_PRELANDATE</th>\n",
" <th>S_DIV_SMTGDATE</th>\n",
" <th>DVD_ANN_DT</th>\n",
" <th>S_DIV_BASESHARE</th>\n",
" <th>S_DIV_BONUSRATE</th>\n",
" <th>S_DIV_CONVERSEDRATE</th>\n",
" <th>MEMO</th>\n",
" <th>S_DIV_PREANNDT</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>600000.SH</td>\n",
" <td>2001-12-31</td>\n",
" <td>2002-03-21</td>\n",
" <td>2002-08-21</td>\n",
" <td>2002-08-22</td>\n",
" <td>2002-08-27</td>\n",
" <td>2002-03-21</td>\n",
" <td>2002-06-29</td>\n",
" <td>2002-08-17</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.5</td>\n",
" <td>0.5</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>600000.SH</td>\n",
" <td>2002-12-31</td>\n",
" <td>2003-03-29</td>\n",
" <td>2003-06-20</td>\n",
" <td>2003-06-23</td>\n",
" <td>2003-06-27</td>\n",
" <td>2003-03-29</td>\n",
" <td>2003-04-30</td>\n",
" <td>2003-06-17</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>600000.SH</td>\n",
" <td>2003-12-31</td>\n",
" <td>2004-02-27</td>\n",
" <td>2004-05-19</td>\n",
" <td>2004-05-20</td>\n",
" <td>2004-05-25</td>\n",
" <td>2004-02-27</td>\n",
" <td>2004-03-31</td>\n",
" <td>2004-05-15</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>600000.SH</td>\n",
" <td>2004-12-31</td>\n",
" <td>2005-02-26</td>\n",
" <td>2005-05-11</td>\n",
" <td>2005-05-12</td>\n",
" <td>2005-05-16</td>\n",
" <td>2005-02-26</td>\n",
" <td>2005-04-27</td>\n",
" <td>2005-04-30</td>\n",
" <td>3.915000e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>600000.SH</td>\n",
" <td>2005-12-31</td>\n",
" <td>2006-03-02</td>\n",
" <td>2006-05-24</td>\n",
" <td>2006-05-25</td>\n",
" <td>2006-05-29</td>\n",
" <td>2006-03-02</td>\n",
" <td>2006-04-06</td>\n",
" <td>2006-05-19</td>\n",
" <td>3.915000e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>600000.SH</td>\n",
" <td>2006-12-31</td>\n",
" <td>2007-03-24</td>\n",
" <td>2007-07-17</td>\n",
" <td>2007-07-18</td>\n",
" <td>2007-07-20</td>\n",
" <td>2007-03-24</td>\n",
" <td>2007-05-22</td>\n",
" <td>2007-07-13</td>\n",
" <td>4.354883e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>600000.SH</td>\n",
" <td>2007-12-31</td>\n",
" <td>2008-02-28</td>\n",
" <td>2008-04-23</td>\n",
" <td>2008-04-24</td>\n",
" <td>2008-04-29</td>\n",
" <td>2008-02-28</td>\n",
" <td>2008-03-20</td>\n",
" <td>2008-04-18</td>\n",
" <td>4.354883e+09</td>\n",
" <td>0.3</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>600000.SH</td>\n",
" <td>2008-12-31</td>\n",
" <td>2009-04-10</td>\n",
" <td>2009-06-08</td>\n",
" <td>2009-06-09</td>\n",
" <td>2009-06-16</td>\n",
" <td>2009-04-10</td>\n",
" <td>2009-05-05</td>\n",
" <td>2009-06-03</td>\n",
" <td>5.661348e+09</td>\n",
" <td>0.4</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>600000.SH</td>\n",
" <td>2009-12-31</td>\n",
" <td>2010-04-07</td>\n",
" <td>2010-06-09</td>\n",
" <td>2010-06-10</td>\n",
" <td>2010-06-18</td>\n",
" <td>2010-04-07</td>\n",
" <td>2010-04-28</td>\n",
" <td>2010-06-04</td>\n",
" <td>8.830046e+09</td>\n",
" <td>0.3</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>600000.SH</td>\n",
" <td>2010-12-31</td>\n",
" <td>2011-03-30</td>\n",
" <td>2011-06-02</td>\n",
" <td>2011-06-03</td>\n",
" <td>2011-06-13</td>\n",
" <td>2011-03-30</td>\n",
" <td>2011-04-28</td>\n",
" <td>2011-05-30</td>\n",
" <td>1.434882e+10</td>\n",
" <td>0.3</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>600000.SH</td>\n",
" <td>2011-12-31</td>\n",
" <td>2012-03-16</td>\n",
" <td>2012-06-25</td>\n",
" <td>2012-06-26</td>\n",
" <td>2012-06-29</td>\n",
" <td>2012-03-16</td>\n",
" <td>2012-06-13</td>\n",
" <td>2012-06-19</td>\n",
" <td>1.865347e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>600000.SH</td>\n",
" <td>2012-12-31</td>\n",
" <td>2013-03-14</td>\n",
" <td>2013-05-31</td>\n",
" <td>2013-06-03</td>\n",
" <td>2013-06-07</td>\n",
" <td>2013-03-14</td>\n",
" <td>2013-05-16</td>\n",
" <td>2013-05-27</td>\n",
" <td>1.865347e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>600000.SH</td>\n",
" <td>2013-12-31</td>\n",
" <td>2014-03-20</td>\n",
" <td>2014-06-23</td>\n",
" <td>2014-06-24</td>\n",
" <td>2014-06-24</td>\n",
" <td>2014-03-20</td>\n",
" <td>2014-05-26</td>\n",
" <td>2014-06-17</td>\n",
" <td>1.865347e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>600000.SH</td>\n",
" <td>2014-12-31</td>\n",
" <td>2015-03-19</td>\n",
" <td>2015-06-19</td>\n",
" <td>2015-06-23</td>\n",
" <td>2015-06-23</td>\n",
" <td>2015-03-19</td>\n",
" <td>2015-05-15</td>\n",
" <td>2015-06-16</td>\n",
" <td>1.865347e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>600000.SH</td>\n",
" <td>2015-12-31</td>\n",
" <td>2016-04-07</td>\n",
" <td>2016-06-22</td>\n",
" <td>2016-06-23</td>\n",
" <td>2016-06-23</td>\n",
" <td>2016-04-07</td>\n",
" <td>2016-04-28</td>\n",
" <td>2016-06-16</td>\n",
" <td>1.965298e+10</td>\n",
" <td>0.1</td>\n",
" <td>0.1</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>600000.SH</td>\n",
" <td>2016-12-31</td>\n",
" <td>2017-04-01</td>\n",
" <td>2017-05-24</td>\n",
" <td>2017-05-25</td>\n",
" <td>2017-05-25</td>\n",
" <td>2017-04-01</td>\n",
" <td>2017-04-25</td>\n",
" <td>2017-05-19</td>\n",
" <td>2.161828e+10</td>\n",
" <td>0.3</td>\n",
" <td>0.3</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>600000.SH</td>\n",
" <td>2017-12-31</td>\n",
" <td>2018-04-28</td>\n",
" <td>2018-07-12</td>\n",
" <td>2018-07-13</td>\n",
" <td>2018-07-13</td>\n",
" <td>2018-04-28</td>\n",
" <td>2018-05-28</td>\n",
" <td>2018-07-06</td>\n",
" <td>2.935208e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>600000.SH</td>\n",
" <td>2018-12-31</td>\n",
" <td>2019-03-26</td>\n",
" <td>2019-06-10</td>\n",
" <td>2019-06-11</td>\n",
" <td>2019-06-11</td>\n",
" <td>2019-03-26</td>\n",
" <td>2019-04-24</td>\n",
" <td>2019-06-04</td>\n",
" <td>2.935208e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>600000.SH</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-04-25</td>\n",
" <td>2020-07-22</td>\n",
" <td>2020-07-23</td>\n",
" <td>2020-07-23</td>\n",
" <td>2020-04-25</td>\n",
" <td>2020-06-19</td>\n",
" <td>2020-07-16</td>\n",
" <td>2.935212e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>600000.SH</td>\n",
" <td>2020-12-31</td>\n",
" <td>2021-03-27</td>\n",
" <td>2021-07-20</td>\n",
" <td>2021-07-21</td>\n",
" <td>2021-07-21</td>\n",
" <td>2021-03-27</td>\n",
" <td>2021-06-11</td>\n",
" <td>2021-07-13</td>\n",
" <td>2.935216e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>600000.SH</td>\n",
" <td>2021-12-31</td>\n",
" <td>2022-04-28</td>\n",
" <td>NaT</td>\n",
" <td>NaT</td>\n",
" <td>NaT</td>\n",
" <td>2022-04-28</td>\n",
" <td>NaT</td>\n",
" <td>NaT</td>\n",
" <td>2.935217e+10</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>NaT</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" code report_period appear_at_date EQY_RECORD_DT EX_DT \\\n",
"0 600000.SH 2001-12-31 2002-03-21 2002-08-21 2002-08-22 \n",
"1 600000.SH 2002-12-31 2003-03-29 2003-06-20 2003-06-23 \n",
"2 600000.SH 2003-12-31 2004-02-27 2004-05-19 2004-05-20 \n",
"3 600000.SH 2004-12-31 2005-02-26 2005-05-11 2005-05-12 \n",
"4 600000.SH 2005-12-31 2006-03-02 2006-05-24 2006-05-25 \n",
"5 600000.SH 2006-12-31 2007-03-24 2007-07-17 2007-07-18 \n",
"6 600000.SH 2007-12-31 2008-02-28 2008-04-23 2008-04-24 \n",
"7 600000.SH 2008-12-31 2009-04-10 2009-06-08 2009-06-09 \n",
"8 600000.SH 2009-12-31 2010-04-07 2010-06-09 2010-06-10 \n",
"9 600000.SH 2010-12-31 2011-03-30 2011-06-02 2011-06-03 \n",
"10 600000.SH 2011-12-31 2012-03-16 2012-06-25 2012-06-26 \n",
"11 600000.SH 2012-12-31 2013-03-14 2013-05-31 2013-06-03 \n",
"12 600000.SH 2013-12-31 2014-03-20 2014-06-23 2014-06-24 \n",
"13 600000.SH 2014-12-31 2015-03-19 2015-06-19 2015-06-23 \n",
"14 600000.SH 2015-12-31 2016-04-07 2016-06-22 2016-06-23 \n",
"15 600000.SH 2016-12-31 2017-04-01 2017-05-24 2017-05-25 \n",
"16 600000.SH 2017-12-31 2018-04-28 2018-07-12 2018-07-13 \n",
"17 600000.SH 2018-12-31 2019-03-26 2019-06-10 2019-06-11 \n",
"18 600000.SH 2019-12-31 2020-04-25 2020-07-22 2020-07-23 \n",
"19 600000.SH 2020-12-31 2021-03-27 2021-07-20 2021-07-21 \n",
"20 600000.SH 2021-12-31 2022-04-28 NaT NaT \n",
"\n",
" DVD_PAYOUT_DT S_DIV_PRELANDATE S_DIV_SMTGDATE DVD_ANN_DT S_DIV_BASESHARE \\\n",
"0 2002-08-27 2002-03-21 2002-06-29 2002-08-17 0.000000e+00 \n",
"1 2003-06-27 2003-03-29 2003-04-30 2003-06-17 0.000000e+00 \n",
"2 2004-05-25 2004-02-27 2004-03-31 2004-05-15 0.000000e+00 \n",
"3 2005-05-16 2005-02-26 2005-04-27 2005-04-30 3.915000e+09 \n",
"4 2006-05-29 2006-03-02 2006-04-06 2006-05-19 3.915000e+09 \n",
"5 2007-07-20 2007-03-24 2007-05-22 2007-07-13 4.354883e+09 \n",
"6 2008-04-29 2008-02-28 2008-03-20 2008-04-18 4.354883e+09 \n",
"7 2009-06-16 2009-04-10 2009-05-05 2009-06-03 5.661348e+09 \n",
"8 2010-06-18 2010-04-07 2010-04-28 2010-06-04 8.830046e+09 \n",
"9 2011-06-13 2011-03-30 2011-04-28 2011-05-30 1.434882e+10 \n",
"10 2012-06-29 2012-03-16 2012-06-13 2012-06-19 1.865347e+10 \n",
"11 2013-06-07 2013-03-14 2013-05-16 2013-05-27 1.865347e+10 \n",
"12 2014-06-24 2014-03-20 2014-05-26 2014-06-17 1.865347e+10 \n",
"13 2015-06-23 2015-03-19 2015-05-15 2015-06-16 1.865347e+10 \n",
"14 2016-06-23 2016-04-07 2016-04-28 2016-06-16 1.965298e+10 \n",
"15 2017-05-25 2017-04-01 2017-04-25 2017-05-19 2.161828e+10 \n",
"16 2018-07-13 2018-04-28 2018-05-28 2018-07-06 2.935208e+10 \n",
"17 2019-06-11 2019-03-26 2019-04-24 2019-06-04 2.935208e+10 \n",
"18 2020-07-23 2020-04-25 2020-06-19 2020-07-16 2.935212e+10 \n",
"19 2021-07-21 2021-03-27 2021-06-11 2021-07-13 2.935216e+10 \n",
"20 NaT 2022-04-28 NaT NaT 2.935217e+10 \n",
"\n",
" S_DIV_BONUSRATE S_DIV_CONVERSEDRATE MEMO S_DIV_PREANNDT \n",
"0 0.5 0.5 nan NaT \n",
"1 0.0 0.0 nan NaT \n",
"2 0.0 0.0 nan NaT \n",
"3 0.0 0.0 nan NaT \n",
"4 0.0 0.0 nan NaT \n",
"5 0.0 0.0 nan NaT \n",
"6 0.3 0.0 nan NaT \n",
"7 0.4 0.0 nan NaT \n",
"8 0.3 0.0 nan NaT \n",
"9 0.3 0.0 nan NaT \n",
"10 0.0 0.0 nan NaT \n",
"11 0.0 0.0 nan NaT \n",
"12 0.0 0.0 nan NaT \n",
"13 0.0 0.0 nan NaT \n",
"14 0.1 0.1 nan NaT \n",
"15 0.3 0.3 nan NaT \n",
"16 0.0 0.0 nan NaT \n",
"17 0.0 0.0 nan NaT \n",
"18 0.0 0.0 nan NaT \n",
"19 0.0 0.0 nan NaT \n",
"20 0.0 0.0 nan NaT "
]
},
"execution_count": 156,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"sess.run(\"\"\"\n",
" select top 100 * from loadTable(\"dfs://pit_stock_ts\", \"divident\") where code=\"600000.SH\"\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "f67794f5-ffc2-42fb-8dd8-faed6ecfad02",
"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>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000106.SH</td>\n",
" <td>3080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000844.SH</td>\n",
" <td>2350</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000919.SH</td>\n",
" <td>3080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>399210.SZ</td>\n",
" <td>765</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>399300.SZ</td>\n",
" <td>3080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>980</th>\n",
" <td>857244.SW</td>\n",
" <td>3079</td>\n",
" </tr>\n",
" <tr>\n",
" <th>981</th>\n",
" <td>857421.SW</td>\n",
" <td>3080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>982</th>\n",
" <td>859512.SW</td>\n",
" <td>3079</td>\n",
" </tr>\n",
" <tr>\n",
" <th>983</th>\n",
" <td>859852.SW</td>\n",
" <td>3080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>984</th>\n",
" <td>I899001.CS</td>\n",
" <td>1862</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>985 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" code count\n",
"0 000106.SH 3080\n",
"1 000844.SH 2350\n",
"2 000919.SH 3080\n",
"3 399210.SZ 765\n",
"4 399300.SZ 3080\n",
".. ... ...\n",
"980 857244.SW 3079\n",
"981 857421.SW 3080\n",
"982 859512.SW 3079\n",
"983 859852.SW 3080\n",
"984 I899001.CS 1862\n",
"\n",
"[985 rows x 2 columns]"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select code, count(*) from loadTable(\"dfs://daily_stock_ts\", \"idx_daily_kline\") group by code\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "3411a78a-4efc-4693-af3f-44abe6ba166e",
"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>m_nDate</th>\n",
" <th>code</th>\n",
" <th>close</th>\n",
" <th>yclose</th>\n",
" <th>PctChg</th>\n",
" <th>factor</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2020-09-11</td>\n",
" <td>600519.SH</td>\n",
" <td>1733.00</td>\n",
" <td>1705.80</td>\n",
" <td>1.594560</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2020-09-14</td>\n",
" <td>600519.SH</td>\n",
" <td>1766.00</td>\n",
" <td>1733.00</td>\n",
" <td>1.904212</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2020-09-15</td>\n",
" <td>600519.SH</td>\n",
" <td>1760.00</td>\n",
" <td>1766.00</td>\n",
" <td>-0.339751</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2020-09-16</td>\n",
" <td>600519.SH</td>\n",
" <td>1725.10</td>\n",
" <td>1760.00</td>\n",
" <td>-1.982955</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2020-09-17</td>\n",
" <td>600519.SH</td>\n",
" <td>1670.52</td>\n",
" <td>1725.10</td>\n",
" <td>-3.163875</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>2020-09-18</td>\n",
" <td>600519.SH</td>\n",
" <td>1695.00</td>\n",
" <td>1670.52</td>\n",
" <td>1.465412</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" m_nDate code close yclose PctChg factor\n",
"0 2020-09-11 600519.SH 1733.00 1705.80 1.594560 3.334994\n",
"1 2020-09-14 600519.SH 1766.00 1733.00 1.904212 3.334994\n",
"2 2020-09-15 600519.SH 1760.00 1766.00 -0.339751 3.334994\n",
"3 2020-09-16 600519.SH 1725.10 1760.00 -1.982955 3.334994\n",
"4 2020-09-17 600519.SH 1670.52 1725.10 -3.163875 3.334994\n",
"5 2020-09-18 600519.SH 1695.00 1670.52 1.465412 3.334994"
]
},
"execution_count": 59,
"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(\"select top 100 code, m_nDate, log(amount + 1) as log_amount from loadTable('dfs://daily_stock_ts', 'daily_kline')\")\n",
"#sess.run(\"select top 100 * from loadTable('dfs://daily_stock_ts', 'daily_kline') where IsGoDelist>0\")\n",
"#sess.run(\"select m_nDate, count(code) from loadTable('dfs://daily_stock_ts', 'daily_kline') group by m_nDate order by m_nDate desc\")\n",
"sess.run(\"select top 100 m_nDate, code, close, yclose, PctChg, factor from loadTable('dfs://daily_stock_ts', 'daily_kline') where code='600519.SH' and m_nDate>2020.09.10 and m_nDate<2020.09.20 order by m_nDate asc\")"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "988f7b87-e221-4847-ad21-88844a1a7349",
"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>yclose</th>\n",
" <th>close</th>\n",
" <th>factor</th>\n",
" </tr>\n",
" <tr>\n",
" <th>instrument</th>\n",
" <th>datetime</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"11\" valign=\"top\">000300.SH</th>\n",
" <th>2010-01-04</th>\n",
" <td>3575.6840</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-01-05</th>\n",
" <td>3535.2290</td>\n",
" <td>3535.2290</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-01-06</th>\n",
" <td>3564.0380</td>\n",
" <td>3564.0380</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-01-07</th>\n",
" <td>3541.7270</td>\n",
" <td>3541.7270</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-01-08</th>\n",
" <td>3471.4560</td>\n",
" <td>3471.4560</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-29</th>\n",
" <td>4107.5455</td>\n",
" <td>4107.5455</td>\n",
" <td>1.000698</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-30</th>\n",
" <td>4089.5205</td>\n",
" <td>4089.5205</td>\n",
" <td>1.000698</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-08-31</th>\n",
" <td>4075.7937</td>\n",
" <td>4075.7937</td>\n",
" <td>1.000698</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-09-01</th>\n",
" <td>4078.8402</td>\n",
" <td>4078.8402</td>\n",
" <td>1.000698</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-09-02</th>\n",
" <td>4043.7395</td>\n",
" <td>4043.7395</td>\n",
" <td>1.000698</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3080 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" yclose close factor\n",
"instrument datetime \n",
"000300.SH 2010-01-04 3575.6840 NaN NaN\n",
" 2010-01-05 3535.2290 3535.2290 1.000000\n",
" 2010-01-06 3564.0380 3564.0380 1.000000\n",
" 2010-01-07 3541.7270 3541.7270 1.000000\n",
" 2010-01-08 3471.4560 3471.4560 1.000000\n",
"... ... ... ...\n",
" 2022-08-29 4107.5455 4107.5455 1.000698\n",
" 2022-08-30 4089.5205 4089.5205 1.000698\n",
" 2022-08-31 4075.7937 4075.7937 1.000698\n",
" 2022-09-01 4078.8402 4078.8402 1.000698\n",
" 2022-09-02 4043.7395 4043.7395 1.000698\n",
"\n",
"[3080 rows x 3 columns]"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = sess.run(\"\"\"\n",
" base = select code, m_nDate, close, yclose \n",
" from loadTable('dfs://daily_stock_ts', 'idx_daily_kline') where code='000300.SH' \n",
" order by m_nDate asc;\n",
" previous = select code, temporalAdd(m_nDate, 1, \"d\") as m_nDate, close, yclose \n",
" from loadTable('dfs://daily_stock_ts', 'idx_daily_kline') where code='000300.SH' \n",
" order by m_nDate asc;\n",
" select code as instrument, m_nDate as datetime, base.yclose, previous.close, cumprod(previous.close/base.yclose) as factor from aj(base, previous, `code`m_nDate);\n",
"\"\"\")\n",
"df.set_index(['instrument', 'datetime'], inplace=True)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "d1228611-d953-425e-bbfa-d3d91418e3aa",
"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>yclose</th>\n",
" <th>close</th>\n",
" <th>factor2</th>\n",
" <th>factor</th>\n",
" </tr>\n",
" <tr>\n",
" <th>instrument</th>\n",
" <th>datetime</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>600519.SH</th>\n",
" <th>2020-09-16</th>\n",
" <td>1760.0</td>\n",
" <td>1760.0</td>\n",
" <td>3.334994</td>\n",
" <td>3.334994</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" yclose close factor2 factor\n",
"instrument datetime \n",
"600519.SH 2020-09-16 1760.0 1760.0 3.334994 3.334994"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"row = df[df.index.get_level_values(\"datetime\") == '2020-09-16']\n",
"row"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "4f73a4a0-e828-40c1-92c3-8bfe6491fa08",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"instrument datetime \n",
"600519.SH 2020-09-16 527.737026\n",
"dtype: float64"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"row['close'] / row['factor']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a5ddd8f-0bb2-4427-b5af-b32d80d6b3cf",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" tbl = loadTable(\"dfs://hft_stock_ts\", \"KLinePartitioned\");\n",
" select * from (\n",
" select code, m_nDate, count(*) from tbl where code='600009.SH' group by code, m_nDate map\n",
" );\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 131,
"id": "06efcf17-b210-452f-a5fb-d4f97b5eae6b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 131,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"# backup(backup_path, sql_obj, force, parallel)\n",
"code = \"\"\"\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://info_stock_ts\", \"info_list_delist\")>, true, false);\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://info_stock_ts\", \"info_industry\")>, true, false);\n",
"\"\"\"\n",
"\n",
"sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "8af3381d-9fdc-4cb0-b3a9-d6538db97476",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" backup('/data/dolphindb/backup/', <select * from loadTable(\"dfs://daily_stock_ts\", \"daily_kline\") >, true, false);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "bf3bc38e-74cb-4549-bdca-6a3d2a601488",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2287.0"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"114350 / 50"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "11275975-af43-4123-973a-f75096eb4e43",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2311.0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"115550 / 50"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "155735c7-bdad-4c64-a2a1-514fe54e088c",
"metadata": {},
"outputs": [],
"source": [
"import dolphindb as ddb\n",
"\n",
"sess = ddb.session('localhost', 8848)\n",
"sess.login('admin', '123456')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a2e95bc5-c1d5-47f5-9488-9b8702947afc",
"metadata": {},
"outputs": [],
"source": [
"# migrate(backupDir, [backupDBPath], [backupTableName], [newDBPath=backupDBPath], [newTableName=backupTableName])\n",
"code = \"\"\"\n",
" migrate('/data/dolphindb/backup/',\"dfs://hft_stock_ts\", \"KLinePartitioned\")\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a6198ef-e7f1-4f58-ba24-32dc429c9803",
"metadata": {},
"outputs": [],
"source": [
"sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "60f71516-33fc-4147-9740-c493ccb6b6a8",
"metadata": {},
"outputs": [],
"source": [
"def make_kurto_code_partition(partition_num):\n",
" code = \"\"\"\n",
" tbl = loadTable(\"dfs://hft_stock_ts\", \"KLinePartitioned\");\n",
" ret = select \n",
" code, m_nDate, eachPre(\\, m_nClose)-1.0 as ret \n",
" from tbl \n",
" where partition(code, {partition_num}) \n",
" context by m_nDate;\n",
" kurto = select \n",
" code, m_nDate, sqrt(239) * sum(pow(ret, 3)) / pow(sum(pow(ret, 2)), 1.5) as kurto \n",
" from ret \n",
" group by code, m_nDate;\n",
" \"\"\".format(\n",
" partition_num = partition_num\n",
" )\n",
" sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "1397c1b7-f81a-465e-868a-894b3ef818fc",
"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>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2305</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000558.SZ</td>\n",
" <td>2063</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000602.SZ</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000677.SZ</td>\n",
" <td>2009</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000731.SZ</td>\n",
" <td>2311</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
" <td>688039.SH</td>\n",
" <td>624</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>688052.SH</td>\n",
" <td>52</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>688091.SH</td>\n",
" <td>198</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>688368.SH</td>\n",
" <td>656</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>688396.SH</td>\n",
" <td>575</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>99 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" code count\n",
"0 000400.SZ 2305\n",
"1 000558.SZ 2063\n",
"2 000602.SZ 47\n",
"3 000677.SZ 2009\n",
"4 000731.SZ 2311\n",
".. ... ...\n",
"94 688039.SH 624\n",
"95 688052.SH 52\n",
"96 688091.SH 198\n",
"97 688368.SH 656\n",
"98 688396.SH 575\n",
"\n",
"[99 rows x 2 columns]"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select code, count(*) from kurto group by code\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "59758901-3728-4355-bbb8-15b3eb537cdf",
"metadata": {},
"outputs": [],
"source": [
"def create_daily_ddb_database():\n",
" code = \"\"\"\n",
" daily_stock_ts = database(\n",
" \"dfs://daily_stock_ts\", \n",
" HASH, [SYMBOL, 50], \n",
" engine = 'TSDB'\n",
" )\n",
" \"\"\"\n",
" sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "d8fa94ae-6ca4-41f3-8b13-47ab8876ba95",
"metadata": {},
"outputs": [],
"source": [
"def load_daily_ddb_database():\n",
" code = \"\"\"\n",
" daily_stock_ts = database(\"dfs://daily_stock_ts\")\n",
" \"\"\"\n",
" sess.run(code)\n",
"\n",
"load_daily_ddb_database()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "84eb237e-959c-419f-bce1-6779acda86d4",
"metadata": {},
"outputs": [],
"source": [
"def create_kurto_partition_table():\n",
" # createPartitionedTable(dbHandle, table, tableName, [partitionColumns], [compressMethods], [sortColumns], [keepDuplicates=ALL], [sortKeyMappingFunction])\n",
" code = \"\"\"\n",
" dropTable(daily_stock_ts, \"kurto_partitioned\");\n",
" kurto_partitioned = createPartitionedTable(\n",
" daily_stock_ts,\n",
" kurto, \n",
" \"kurto_partitioned\",\n",
" partitionColumns = 'code',\n",
" compressMethods = {'m_nDate' : 'delta'},\n",
" sortColumns = `code`m_nDate\n",
" );\n",
" \"\"\"\n",
" sess.run(code)\n",
" \n",
"create_kurto_partition_table()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "0d93b3d1-39b7-4e23-8abf-eda86dcd2a23",
"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>kurto</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-0.317991</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000558.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-15.387820</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000677.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-15.459625</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000731.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>15.443339</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000752.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>15.396262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>000789.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-14.801720</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>000903.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-15.405085</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>000912.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>14.755241</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>000935.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>15.413214</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>000970.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>15.458413</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" code m_nDate kurto\n",
"0 000400.SZ 2013-01-04 -0.317991\n",
"1 000558.SZ 2013-01-04 -15.387820\n",
"2 000677.SZ 2013-01-04 -15.459625\n",
"3 000731.SZ 2013-01-04 15.443339\n",
"4 000752.SZ 2013-01-04 15.396262\n",
"5 000789.SZ 2013-01-04 -14.801720\n",
"6 000903.SZ 2013-01-04 -15.405085\n",
"7 000912.SZ 2013-01-04 14.755241\n",
"8 000935.SZ 2013-01-04 15.413214\n",
"9 000970.SZ 2013-01-04 15.458413"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" kurto_partitioned.tableInsert(kurto);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "eea5cb0b-8452-41a9-a0ad-7cf52c856c25",
"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>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>154953</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count\n",
"0 154953"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select count(*) from kurto_partitioned;\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "9e7bc856-517b-4bf9-866d-4fe85b9705a3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'partitionType': 5,\n",
" 'partitionColumnType': 17,\n",
" 'partitionColumnIndex': 0,\n",
" 'chunkPath': None,\n",
" 'colDefs': name typeString typeInt comment\n",
" 0 code SYMBOL 17 \n",
" 1 m_nDate DATE 6 \n",
" 2 kurto DOUBLE 16 ,\n",
" 'chunkGranularity': 'TABLE',\n",
" 'partitionTypeName': 'HASH',\n",
" 'keepDuplicates': 'ALL',\n",
" 'engineType': 'TSDB',\n",
" 'partitionColumnName': 'code',\n",
" 'partitionSchema': 50,\n",
" 'sortColumns': array(['code', 'm_nDate'], dtype=object),\n",
" 'partitionSites': None}"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" schema(loadTable(\"dfs://daily_stock_ts\", \"kurto_partitioned\"));\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "94ae00b5-ba42-48b9-b114-012cf306d871",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"m_table = table(kurto)\")"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "e30134f9-5110-421d-8f71-1bef25e7ef17",
"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>kurto</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-04</td>\n",
" <td>-0.317991</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-07</td>\n",
" <td>0.790872</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-08</td>\n",
" <td>0.655005</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-09</td>\n",
" <td>0.965054</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000400.SZ</td>\n",
" <td>2013-01-10</td>\n",
" <td>-0.116488</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154948</th>\n",
" <td>688396.SH</td>\n",
" <td>2022-07-04</td>\n",
" <td>-15.420192</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154949</th>\n",
" <td>688396.SH</td>\n",
" <td>2022-07-05</td>\n",
" <td>-15.426922</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154950</th>\n",
" <td>688396.SH</td>\n",
" <td>2022-07-06</td>\n",
" <td>-15.389434</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154951</th>\n",
" <td>688396.SH</td>\n",
" <td>2022-07-07</td>\n",
" <td>-15.411602</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154952</th>\n",
" <td>688396.SH</td>\n",
" <td>2022-07-08</td>\n",
" <td>-15.401453</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>154953 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nDate kurto\n",
"0 000400.SZ 2013-01-04 -0.317991\n",
"1 000400.SZ 2013-01-07 0.790872\n",
"2 000400.SZ 2013-01-08 0.655005\n",
"3 000400.SZ 2013-01-09 0.965054\n",
"4 000400.SZ 2013-01-10 -0.116488\n",
"... ... ... ...\n",
"154948 688396.SH 2022-07-04 -15.420192\n",
"154949 688396.SH 2022-07-05 -15.426922\n",
"154950 688396.SH 2022-07-06 -15.389434\n",
"154951 688396.SH 2022-07-07 -15.411602\n",
"154952 688396.SH 2022-07-08 -15.401453\n",
"\n",
"[154953 rows x 3 columns]"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"m_table\")"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "947e3346-15f6-4fb5-b2d6-b97b013a3b36",
"metadata": {},
"outputs": [],
"source": [
"code = \"\"\"\n",
" // 保证创建新的分区表不会和已经存在表冲突\n",
" if (existsTable(\"{ddb_daily_path}\", \"{partition_tbl_name}\")) {{\n",
" dropTable({ddb_daily_dbname}, \"{partition_tbl_name}\");\n",
" }}\n",
"\n",
" {partition_tbl_name} = createPartitionedTable(\n",
" dbHandle = {ddb_daily_dbname},\n",
" table = {memory_tbl_name}, \n",
" \"{partition_tbl_name}\",\n",
" partitionColumns = 'code',\n",
" compressMethods = {{'m_nDate' : 'delta'}},\n",
" sortColumns = `code`m_nDate\n",
" );\n",
"\"\"\".format(\n",
" ddb_daily_path = \"A\",\n",
" ddb_daily_dbname = \"B\",\n",
" partition_tbl_name = \"C\",\n",
" memory_tbl_name = \"D\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "5d758c68-301a-47a7-9cd2-b7dd7edf1a55",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('\\n'\n",
" ' // 保证创建新的分区表不会和已经存在表冲突\\n'\n",
" ' if (existsTable(\"A\", \"C\")) {\\n'\n",
" ' dropTable(B, \"C\");\\n'\n",
" ' }\\n'\n",
" '\\n'\n",
" ' C = createPartitionedTable(\\n'\n",
" ' dbHandle = B,\\n'\n",
" ' table = D, \\n'\n",
" ' \"C\",\\n'\n",
" \" partitionColumns = 'code',\\n\"\n",
" \" compressMethods = {'m_nDate' : 'delta'},\\n\"\n",
" ' sortColumns = `code`m_nDate\\n'\n",
" ' );\\n')\n"
]
}
],
"source": [
"from pprint import pprint\n",
"pprint(code)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "400424d9-9c58-4417-94e4-fe1569522b03",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'chunkGranularity': 'TABLE',\n",
" 'chunkPath': None,\n",
" 'colDefs': name typeString typeInt comment\n",
"0 code SYMBOL 17 \n",
"1 m_nDate DATE 6 \n",
"2 kurto DOUBLE 16 ,\n",
" 'engineType': 'TSDB',\n",
" 'keepDuplicates': 'ALL',\n",
" 'partitionColumnIndex': 0,\n",
" 'partitionColumnName': 'code',\n",
" 'partitionColumnType': 17,\n",
" 'partitionSchema': 50,\n",
" 'partitionSites': None,\n",
" 'partitionType': 5,\n",
" 'partitionTypeName': 'HASH',\n",
" 'sortColumns': array(['code', 'm_nDate'], dtype=object)}\n"
]
}
],
"source": [
"pprint(\n",
" sess.run(\"\"\"\n",
" schema(loadTable(\"dfs://daily_stock_ts\", \"hft_daily_factor\"));\n",
" \"\"\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "68e74de8-359c-4c47-a361-2c006896211c",
"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>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>309906</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count\n",
"0 309906"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" select count(*) from loadTable(\"dfs://daily_stock_ts\", \"hft_daily_factor\");\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "b1bd7605-c347-44f2-a90f-bc949cde0ef0",
"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>report_period</th>\n",
" <th>appear_in_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>TOT_OPER_REV</th>\n",
" <th>OPER_REV</th>\n",
" <th>INT_INC</th>\n",
" <th>INSUR_PREM_UNEARNED</th>\n",
" <th>HANDLING_CHRG_COMM_INC</th>\n",
" <th>NET_INC_OTHER_OPS</th>\n",
" <th>...</th>\n",
" <th>OTHER_INCOME</th>\n",
" <th>MEMO</th>\n",
" <th>ASSET_DISPOSAL_INCOME</th>\n",
" <th>CONTINUED_NET_PROFIT</th>\n",
" <th>END_NET_PROFIT</th>\n",
" <th>CREDIT_IMPAIRMENT_LOSS</th>\n",
" <th>RD_EXPENSE</th>\n",
" <th>STMNOTE_FINEXP</th>\n",
" <th>FIN_EXP_INT_INC</th>\n",
" <th>TOT_OPER_COST2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000677.SZ</td>\n",
" <td>2009-12-31</td>\n",
" <td>2009-12-31</td>\n",
" <td>2010-04-26</td>\n",
" <td>3.514495e+09</td>\n",
" <td>3.514495e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>26392229.68</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>3.474455e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000677.SZ</td>\n",
" <td>2009-12-31</td>\n",
" <td>2009-12-31</td>\n",
" <td>2011-12-10</td>\n",
" <td>3.514495e+09</td>\n",
" <td>3.514495e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>26392229.68</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>3.460335e+09</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2 rows × 69 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period appear_in_period appear_at_date TOT_OPER_REV \\\n",
"0 000677.SZ 2009-12-31 2009-12-31 2010-04-26 3.514495e+09 \n",
"1 000677.SZ 2009-12-31 2009-12-31 2011-12-10 3.514495e+09 \n",
"\n",
" OPER_REV INT_INC INSUR_PREM_UNEARNED HANDLING_CHRG_COMM_INC \\\n",
"0 3.514495e+09 0.0 0.0 0.0 \n",
"1 3.514495e+09 0.0 0.0 0.0 \n",
"\n",
" NET_INC_OTHER_OPS ... OTHER_INCOME MEMO ASSET_DISPOSAL_INCOME \\\n",
"0 26392229.68 ... 0.0 nan 0.0 \n",
"1 26392229.68 ... 0.0 nan 0.0 \n",
"\n",
" CONTINUED_NET_PROFIT END_NET_PROFIT CREDIT_IMPAIRMENT_LOSS RD_EXPENSE \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"\n",
" STMNOTE_FINEXP FIN_EXP_INT_INC TOT_OPER_COST2 \n",
"0 0.0 0.0 3.474455e+09 \n",
"1 0.0 0.0 3.460335e+09 \n",
"\n",
"[2 rows x 69 columns]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dolphindb as ddb \n",
"\n",
"sess = ddb.session('192.168.1.167', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"sess.run(\"\"\"\n",
" is_common_adj = loadTable(\"dfs://pit_stock_ts\", \"is_common_adj\")\n",
" is_common_ori = loadTable(\"dfs://pit_stock_ts\", \"is_common_ori\")\n",
" select * from is_common_ori where code='000677.SZ' and report_period=2009.12.31\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "f0b3928d-c06f-4976-b568-091d98293a6e",
"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>report_period</th>\n",
" <th>appear_in_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>TOT_OPER_REV</th>\n",
" <th>OPER_REV</th>\n",
" <th>INT_INC</th>\n",
" <th>INSUR_PREM_UNEARNED</th>\n",
" <th>HANDLING_CHRG_COMM_INC</th>\n",
" <th>NET_INC_OTHER_OPS</th>\n",
" <th>...</th>\n",
" <th>OTHER_INCOME</th>\n",
" <th>MEMO</th>\n",
" <th>ASSET_DISPOSAL_INCOME</th>\n",
" <th>CONTINUED_NET_PROFIT</th>\n",
" <th>END_NET_PROFIT</th>\n",
" <th>CREDIT_IMPAIRMENT_LOSS</th>\n",
" <th>RD_EXPENSE</th>\n",
" <th>STMNOTE_FINEXP</th>\n",
" <th>FIN_EXP_INT_INC</th>\n",
" <th>TOT_OPER_COST2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000677.SZ</td>\n",
" <td>2009-12-31</td>\n",
" <td>2010-12-31</td>\n",
" <td>2011-04-29</td>\n",
" <td>3.514495e+09</td>\n",
" <td>3.514495e+09</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>26392229.68</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>nan</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>3.474455e+09</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1 rows × 69 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period appear_in_period appear_at_date TOT_OPER_REV \\\n",
"0 000677.SZ 2009-12-31 2010-12-31 2011-04-29 3.514495e+09 \n",
"\n",
" OPER_REV INT_INC INSUR_PREM_UNEARNED HANDLING_CHRG_COMM_INC \\\n",
"0 3.514495e+09 0.0 0.0 0.0 \n",
"\n",
" NET_INC_OTHER_OPS ... OTHER_INCOME MEMO ASSET_DISPOSAL_INCOME \\\n",
"0 26392229.68 ... 0.0 nan 0.0 \n",
"\n",
" CONTINUED_NET_PROFIT END_NET_PROFIT CREDIT_IMPAIRMENT_LOSS RD_EXPENSE \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"\n",
" STMNOTE_FINEXP FIN_EXP_INT_INC TOT_OPER_COST2 \n",
"0 0.0 0.0 3.474455e+09 \n",
"\n",
"[1 rows x 69 columns]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"select * from is_common_adj where code='000677.SZ' and report_period=2009.12.31\")"
]
},
{
"cell_type": "code",
"execution_count": 138,
"id": "d68ea326-82c3-4a7c-97cf-c04dd8aee56b",
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "<Exception> in run: Server response: 'tbl = loadTable(\"dfs://hft_stock_ts\", \"OrderPartitioned\") => FileBlock[/hft_stock_ts/domain, e56bb91f-d4d8-48be-6c4c-df3c1eb96dc4, {}, v1, 9413, c1] returned from name node didn't contain any site' script: '\ntbl = loadTable(\"dfs://hft_stock_ts\", 'OrderPartitioned');\nselect sum(cnt) from (select count(*) as cnt from tbl map);\n'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [138]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m sess \u001b[38;5;241m=\u001b[39m ddb\u001b[38;5;241m.\u001b[39msession(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m192.168.1.7\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m8848\u001b[39m)\n\u001b[1;32m 2\u001b[0m sess\u001b[38;5;241m.\u001b[39mlogin(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124madmin\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m123456\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 3\u001b[0m \u001b[43msess\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\"\"\u001b[39;49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124;43mtbl = loadTable(\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdfs://hft_stock_ts\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m, \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mOrderPartitioned\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m);\u001b[39;49m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;43mselect sum(cnt) from (select count(*) as cnt from tbl map);\u001b[39;49m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124;43m\"\"\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.venv/tinysoft/lib/python3.8/site-packages/dolphindb/session.py:161\u001b[0m, in \u001b[0;36msession.run\u001b[0;34m(self, script, *args, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfetchSize\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 160\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m BlockReader(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcpp\u001b[38;5;241m.\u001b[39mrunBlock(script, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs))\n\u001b[0;32m--> 161\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcpp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mscript\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mRuntimeError\u001b[0m: <Exception> in run: Server response: 'tbl = loadTable(\"dfs://hft_stock_ts\", \"OrderPartitioned\") => FileBlock[/hft_stock_ts/domain, e56bb91f-d4d8-48be-6c4c-df3c1eb96dc4, {}, v1, 9413, c1] returned from name node didn't contain any site' script: '\ntbl = loadTable(\"dfs://hft_stock_ts\", 'OrderPartitioned');\nselect sum(cnt) from (select count(*) as cnt from tbl map);\n'"
]
}
],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"sess.run(\"\"\"\n",
"tbl = loadTable(\"dfs://hft_stock_ts\", 'OrderPartitioned');\n",
"select sum(cnt) from (select count(*) as cnt from tbl map);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "7cbc4906-7756-424a-9ce5-9d2b6d1bab4b",
"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>sum_cnt</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1483910</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" sum_cnt\n",
"0 1483910"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"sess.run(\"\"\"\n",
" tbl = loadTable(\"dfs://hft_stock_ts\", 'TickQueuePartitioned');\n",
" select sum(cnt) from (select count(*) as cnt from tbl where code='689009.SH' map);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "e9ab5e57-dce5-4426-9bac-4238cd067197",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Will retrieve partition 0\n",
"Will retrieve partition 1\n",
"Will retrieve partition 2\n",
"Will retrieve partition 3\n",
"Will retrieve partition 4\n",
"Will retrieve partition 5\n",
"Will retrieve partition 6\n",
"Will retrieve partition 7\n",
"Will retrieve partition 8\n",
"Will retrieve partition 9\n",
"Will retrieve partition 10\n",
"Will retrieve partition 11\n",
"Will retrieve partition 12\n",
"Will retrieve partition 13\n",
"Will retrieve partition 14\n",
"Will retrieve partition 15\n",
"Will retrieve partition 16\n",
"Will retrieve partition 17\n",
"Will retrieve partition 18\n",
"Will retrieve partition 19\n",
"Will retrieve partition 20\n",
"Will retrieve partition 21\n",
"Will retrieve partition 22\n",
"Will retrieve partition 23\n",
"Will retrieve partition 24\n",
"Will retrieve partition 25\n",
"Will retrieve partition 26\n",
"Will retrieve partition 27\n",
"Will retrieve partition 28\n",
"Will retrieve partition 29\n",
"Will retrieve partition 30\n",
"Will retrieve partition 31\n",
"Will retrieve partition 32\n",
"Will retrieve partition 33\n",
"Will retrieve partition 34\n",
"Will retrieve partition 35\n",
"Will retrieve partition 36\n",
"Will retrieve partition 37\n",
"Will retrieve partition 38\n",
"Will retrieve partition 39\n",
"Will retrieve partition 40\n",
"Will retrieve partition 41\n",
"Will retrieve partition 42\n",
"Will retrieve partition 43\n",
"Will retrieve partition 44\n",
"Will retrieve partition 45\n",
"Will retrieve partition 46\n",
"Will retrieve partition 47\n",
"Will retrieve partition 48\n",
"Will retrieve partition 49\n"
]
},
{
"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>000558.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000602.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000677.SZ</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000731.SZ</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" code\n",
"0 000400.SZ\n",
"1 000558.SZ\n",
"2 000602.SZ\n",
"3 000677.SZ\n",
"4 000731.SZ"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"df_list = []\n",
"for i in range(50):\n",
" print(f\"Will retrieve partition {i}\")\n",
" df_list.append(\n",
" sess.run(f\"\"\"\n",
" select code from tbl where partition(code, {i}) group by code;\n",
" \"\"\")\n",
" )\n",
"df = pd.concat(df_list, axis=0)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "10eb9af7-739f-4b77-aa92-9abfba875370",
"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>cnt</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>689009.SH</td>\n",
" <td>2021-08-19</td>\n",
" <td>2728</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-02-16</td>\n",
" <td>2570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-03-02</td>\n",
" <td>2428</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-03-31</td>\n",
" <td>2584</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-04-08</td>\n",
" <td>2872</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-04-12</td>\n",
" <td>2902</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-04-18</td>\n",
" <td>2766</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-04-20</td>\n",
" <td>2584</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>689009.SH</td>\n",
" <td>2022-04-22</td>\n",
" <td>2858</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" code m_nDate cnt\n",
"0 689009.SH 2021-08-19 2728\n",
"1 689009.SH 2022-02-16 2570\n",
"2 689009.SH 2022-03-02 2428\n",
"3 689009.SH 2022-03-31 2584\n",
"4 689009.SH 2022-04-08 2872\n",
"5 689009.SH 2022-04-12 2902\n",
"6 689009.SH 2022-04-18 2766\n",
"7 689009.SH 2022-04-20 2584\n",
"8 689009.SH 2022-04-22 2858"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
" tbl = loadTable(\"dfs://hft_stock_ts\", 'TickQueuePartitioned');\n",
" select code, m_nDate, count(*) as cnt from tbl where code='689009.SH' and count(*) < 3000 group by code, m_nDate map;\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "09332a23-4c1b-4d9f-8e7b-c7ef74611700",
"metadata": {},
"outputs": [],
"source": [
"df.sort_values('code').to_csv('../assets/TickQueuePartitioned.log.csv')"
]
},
{
"cell_type": "code",
"execution_count": 136,
"id": "4ba45027-bbb5-4b27-99da-3452cc8d2f1c",
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "<Exception> in run: Couldn't send script/function to the remote host because the connection has been closed",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [136]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43msess\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\"\"\u001b[39;49m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124;43m select count(*) from (\u001b[39;49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124;43m select code, m_nDate, count(*) as cnt from tbl where code=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m300065.SZ\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m group by code, m_nDate map\u001b[39;49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124;43m );\u001b[39;49m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;43m\"\"\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.venv/tinysoft/lib/python3.8/site-packages/dolphindb/session.py:161\u001b[0m, in \u001b[0;36msession.run\u001b[0;34m(self, script, *args, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfetchSize\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 160\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m BlockReader(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcpp\u001b[38;5;241m.\u001b[39mrunBlock(script, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs))\n\u001b[0;32m--> 161\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcpp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mscript\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mRuntimeError\u001b[0m: <Exception> in run: Couldn't send script/function to the remote host because the connection has been closed"
]
}
],
"source": [
"sess.run(\"\"\"\n",
" select count(*) from (\n",
" select code, m_nDate, count(*) as cnt from tbl where code='300065.SZ' group by code, m_nDate map\n",
" );\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 126,
"id": "29ab8af5-e571-4064-b691-a186d9fb4d08",
"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>count</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_nDate</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [count]\n",
"Index: []"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = sess.run(\"\"\"\n",
" select m_nDate, count(*) from tbl where code='300066.SZ' group by m_nDate map;\n",
"\"\"\").set_index('m_nDate')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "013d191b-2a41-4d7b-8382-b6ee8764c2d0",
"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": 54,
"id": "c90e8e9d-cde0-4a7a-afd3-ea771483f001",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'20130104'"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with engine.connect() as conn:\n",
" rows = conn.execute(\"select * from [Level2BytesTick].dbo.[Tick] where S_INFO_WINDCODE='002182.SZ'\").fetchall()\n",
" rows = [row for row in rows]\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "525dfcf1-720a-4b65-90b5-28d0c2118cf5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"dt = pd.to_datetime(rows[0][1], format='%Y%m%d')\n",
"dt in df.index"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "0e6e949b-ff25-40eb-a70a-72a3a6639aec",
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "<Exception> in run: Failed to read response header from the socket with IO error type 13",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [31]\u001b[0m, in \u001b[0;36m<cell line: 15>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m code \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124mtbl = loadTable(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdfs://hft_stock_ts\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTickPartitioned\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m)\u001b[39m\n\u001b[1;32m 3\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124m}\u001b[39m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[0;32m---> 15\u001b[0m \u001b[43msess\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcode\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.venv/tinysoft/lib/python3.8/site-packages/dolphindb/session.py:161\u001b[0m, in \u001b[0;36msession.run\u001b[0;34m(self, script, *args, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfetchSize\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 160\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m BlockReader(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcpp\u001b[38;5;241m.\u001b[39mrunBlock(script, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs))\n\u001b[0;32m--> 161\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcpp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mscript\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mRuntimeError\u001b[0m: <Exception> in run: Failed to read response header from the socket with IO error type 13"
]
}
],
"source": [
"code = \"\"\"\n",
"tbl = loadTable(\"dfs://hft_stock_ts\", 'TickPartitioned')\n",
"\n",
"for (code in ['000666.SZ' , '000667.SZ', '000668.SZ', '000669.SZ']) {\n",
"\tdel_date = 2013.01.01\n",
"\t//end_date = 2013.01.31\n",
"\tdo {\n",
"\t\t//print('Deleting ' + code + ' from ' + start_date + ' to ' + end_date);\n",
"\t\tprint('Deleting ' + code + ' of ' + del_date);\n",
"\t\tdelete from tbl where m_nDate=del_date and code=code;\n",
"\t\tdel_date = temporalAdd(del_date, 1, \"d\");\n",
"\t} while (del_date <= 2022.12.31)\n",
"}\n",
"\"\"\"\n",
"# 这段代码运行好赶紧注释掉,非常危险\n",
"# sess.run(code)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "ea0501e7-d416-45ce-add5-e443c55f158c",
"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>industry_code</th>\n",
" <th>industry_name</th>\n",
" <th>industry_level</th>\n",
" <th>enter_date</th>\n",
" <th>exit_date</th>\n",
" <th>is_new</th>\n",
" <th>industry_class</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000017.SZ</td>\n",
" <td>SWHY310000</td>\n",
" <td>申万交运设备</td>\n",
" <td>1</td>\n",
" <td>1992-03-31</td>\n",
" <td>2011-10-10</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000017.SZ</td>\n",
" <td>SWHY310300</td>\n",
" <td>申万非汽车交运设备</td>\n",
" <td>2</td>\n",
" <td>1992-03-31</td>\n",
" <td>2011-10-10</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000017.SZ</td>\n",
" <td>SWHY310301</td>\n",
" <td>申万摩托车</td>\n",
" <td>3</td>\n",
" <td>1992-03-31</td>\n",
" <td>2011-10-10</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000017.SZ</td>\n",
" <td>SWHY310000</td>\n",
" <td>申万交运设备</td>\n",
" <td>1</td>\n",
" <td>2011-10-10</td>\n",
" <td>2014-02-21</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000017.SZ</td>\n",
" <td>SWHY310300</td>\n",
" <td>申万非汽车交运设备</td>\n",
" <td>2</td>\n",
" <td>2011-10-10</td>\n",
" <td>2014-02-21</td>\n",
" <td>0</td>\n",
" <td>SWHY</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>95</th>\n",
" <td>000157.SZ</td>\n",
" <td>SWHY260202</td>\n",
" <td>申万工程机械</td>\n",
" <td>3</td>\n",
" <td>2000-10-12</td>\n",
" <td>2014-02-21</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>000157.SZ</td>\n",
" <td>SWHY640000</td>\n",
" <td>申万机械设备</td>\n",
" <td>1</td>\n",
" <td>2014-02-21</td>\n",
" <td>2021-12-13</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>000157.SZ</td>\n",
" <td>SWHY640200</td>\n",
" <td>申万专用设备</td>\n",
" <td>2</td>\n",
" <td>2014-02-21</td>\n",
" <td>2021-12-13</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>000157.SZ</td>\n",
" <td>SWHY640201</td>\n",
" <td>申万工程机械</td>\n",
" <td>3</td>\n",
" <td>2014-02-21</td>\n",
" <td>2021-12-13</td>\n",
" <td>0</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>000157.SZ</td>\n",
" <td>SWHY640000</td>\n",
" <td>申万机械设备</td>\n",
" <td>1</td>\n",
" <td>2021-12-13</td>\n",
" <td>NaT</td>\n",
" <td>1</td>\n",
" <td>SWHY</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
" code industry_code industry_name industry_level enter_date \\\n",
"0 000017.SZ SWHY310000 申万交运设备 1 1992-03-31 \n",
"1 000017.SZ SWHY310300 申万非汽车交运设备 2 1992-03-31 \n",
"2 000017.SZ SWHY310301 申万摩托车 3 1992-03-31 \n",
"3 000017.SZ SWHY310000 申万交运设备 1 2011-10-10 \n",
"4 000017.SZ SWHY310300 申万非汽车交运设备 2 2011-10-10 \n",
".. ... ... ... ... ... \n",
"95 000157.SZ SWHY260202 申万工程机械 3 2000-10-12 \n",
"96 000157.SZ SWHY640000 申万机械设备 1 2014-02-21 \n",
"97 000157.SZ SWHY640200 申万专用设备 2 2014-02-21 \n",
"98 000157.SZ SWHY640201 申万工程机械 3 2014-02-21 \n",
"99 000157.SZ SWHY640000 申万机械设备 1 2021-12-13 \n",
"\n",
" exit_date is_new industry_class \n",
"0 2011-10-10 0 SWHY \n",
"1 2011-10-10 0 SWHY \n",
"2 2011-10-10 0 SWHY \n",
"3 2014-02-21 0 SWHY \n",
"4 2014-02-21 0 SWHY \n",
".. ... ... ... \n",
"95 2014-02-21 0 SWHY \n",
"96 2021-12-13 0 SWHY \n",
"97 2021-12-13 0 SWHY \n",
"98 2021-12-13 0 SWHY \n",
"99 NaT 1 SWHY \n",
"\n",
"[100 rows x 8 columns]"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
"tbl = loadTable(\"dfs://info_stock_ts\", 'info_industry');\n",
"select top 100 * from tbl map;\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16dd860d-049f-420e-8d04-d1f8969e5ed1",
"metadata": {},
"outputs": [],
"source": [
"sess = ddb.session('192.168.1.7', 8848)\n",
"sess.login('admin', '123456')\n",
"\n",
"code = \"\"\"\n",
"tbl = loadTable(\"dfs://hft_stock_ts\", 'TickQueuePartitioned')\n",
"code = '689009.SH'\n",
"\n",
"del_date = 2013.01.01\n",
"do {\n",
" //print('Deleting ' + code + ' from ' + start_date + ' to ' + end_date);\n",
" print('Deleting ' + code + ' of ' + del_date);\n",
" delete from tbl where m_nDate=del_date and code=code;\n",
" del_date = temporalAdd(del_date, 1, \"d\");\n",
"} while (del_date <= 2022.12.31)\n",
"\"\"\"\n",
"# 这段代码运行好赶紧注释掉,非常危险\n",
"# sess.run(code)"
]
}
],
"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
}