{ "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/', , true, false);\n", " backup('/data/dolphindb/backup/', , true, false);\n", " backup('/data/dolphindb/backup/', , true, false);\n", " backup('/data/dolphindb/backup/', , true, false);\n", " backup('/data/dolphindb/backup/', , 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/', , false, false);\n", " // backup('/data/dolphindb/backup/', , true, true);\n", " backup('/data/dolphindb/backup/', , false, false);\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": 128, "id": "84f99b12-e868-425e-bcd3-1733feea7524", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dbNametableNamesuccesserrorMsg
0dfs://daily_stock_tshft_daily_factorTrue
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
tableNamephysicalIndex
0daily_factor1ffH
1idx_daily_kline1eZs
2idx_daily_concept1esb
3hft_daily_factor1eYB
4daily_klineuoH
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dbNametableNamesuccesserrorMsg
0dfs://daily_stock_tsidx_daily_conceptFalsetable named idx_daily_concept already existed ...
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codereport_periodappear_at_dateS_PROFITNOTICE_STYLES_PROFITNOTICE_CHANGEMINS_PROFITNOTICE_CHANGEMAXS_PROFITNOTICE_NETPROFITMINS_PROFITNOTICE_NETPROFITMAXS_PROFITNOTICE_REASON
0600000.SH2002-12-312002-08-17预增10.0001.000000e+010.000000e+000.000000e+00nan
1600000.SH2004-12-312005-01-08预增23.2372.323700e+011.930000e+091.930000e+09nan
2600000.SH2007-06-302007-07-20预增50.0001.000000e+080.000000e+000.000000e+00nan
3600000.SH2008-03-312008-04-14预增180.0001.000000e+080.000000e+000.000000e+00nan
4600000.SH2008-06-302008-04-26预警0.0000.000000e+000.000000e+000.000000e+00公司资产规模增长.利差提高.非利息收入增长.有效所得税率降低.资产质量持续优化.拨备计提减少等。
5600000.SH2008-06-302008-07-04预增140.0001.000000e+080.000000e+000.000000e+00nan
6600000.SH2008-09-302008-08-23预增0.0000.000000e+000.000000e+000.000000e+00nan
7600000.SH2008-09-302008-10-14预增150.0001.500000e+020.000000e+000.000000e+00公司2008年一至三季度同比资产规模增长,资产质量稳定使风险成本下降,利差扩大,非利息收入增...
8600000.SH2008-12-312008-10-30预警0.0000.000000e+000.000000e+000.000000e+00实施新税法,有效所得税率降低;公司资产规模进一步扩大,利息收入增加;非利息收入持续增长;资产...
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
S_PROFITNOTICE_STYLE
0减亏
1增亏
2预亏
3预减
4预增
5预平
6预盈
7预警
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codereport_periodappear_at_dateEQY_RECORD_DTEX_DTDVD_PAYOUT_DTS_DIV_PRELANDATES_DIV_SMTGDATEDVD_ANN_DTS_DIV_BASESHARES_DIV_BONUSRATES_DIV_CONVERSEDRATEMEMOS_DIV_PREANNDT
0600000.SH2001-12-312002-03-212002-08-212002-08-222002-08-272002-03-212002-06-292002-08-170.000000e+000.50.5nanNaT
1600000.SH2002-12-312003-03-292003-06-202003-06-232003-06-272003-03-292003-04-302003-06-170.000000e+000.00.0nanNaT
2600000.SH2003-12-312004-02-272004-05-192004-05-202004-05-252004-02-272004-03-312004-05-150.000000e+000.00.0nanNaT
3600000.SH2004-12-312005-02-262005-05-112005-05-122005-05-162005-02-262005-04-272005-04-303.915000e+090.00.0nanNaT
4600000.SH2005-12-312006-03-022006-05-242006-05-252006-05-292006-03-022006-04-062006-05-193.915000e+090.00.0nanNaT
5600000.SH2006-12-312007-03-242007-07-172007-07-182007-07-202007-03-242007-05-222007-07-134.354883e+090.00.0nanNaT
6600000.SH2007-12-312008-02-282008-04-232008-04-242008-04-292008-02-282008-03-202008-04-184.354883e+090.30.0nanNaT
7600000.SH2008-12-312009-04-102009-06-082009-06-092009-06-162009-04-102009-05-052009-06-035.661348e+090.40.0nanNaT
8600000.SH2009-12-312010-04-072010-06-092010-06-102010-06-182010-04-072010-04-282010-06-048.830046e+090.30.0nanNaT
9600000.SH2010-12-312011-03-302011-06-022011-06-032011-06-132011-03-302011-04-282011-05-301.434882e+100.30.0nanNaT
10600000.SH2011-12-312012-03-162012-06-252012-06-262012-06-292012-03-162012-06-132012-06-191.865347e+100.00.0nanNaT
11600000.SH2012-12-312013-03-142013-05-312013-06-032013-06-072013-03-142013-05-162013-05-271.865347e+100.00.0nanNaT
12600000.SH2013-12-312014-03-202014-06-232014-06-242014-06-242014-03-202014-05-262014-06-171.865347e+100.00.0nanNaT
13600000.SH2014-12-312015-03-192015-06-192015-06-232015-06-232015-03-192015-05-152015-06-161.865347e+100.00.0nanNaT
14600000.SH2015-12-312016-04-072016-06-222016-06-232016-06-232016-04-072016-04-282016-06-161.965298e+100.10.1nanNaT
15600000.SH2016-12-312017-04-012017-05-242017-05-252017-05-252017-04-012017-04-252017-05-192.161828e+100.30.3nanNaT
16600000.SH2017-12-312018-04-282018-07-122018-07-132018-07-132018-04-282018-05-282018-07-062.935208e+100.00.0nanNaT
17600000.SH2018-12-312019-03-262019-06-102019-06-112019-06-112019-03-262019-04-242019-06-042.935208e+100.00.0nanNaT
18600000.SH2019-12-312020-04-252020-07-222020-07-232020-07-232020-04-252020-06-192020-07-162.935212e+100.00.0nanNaT
19600000.SH2020-12-312021-03-272021-07-202021-07-212021-07-212021-03-272021-06-112021-07-132.935216e+100.00.0nanNaT
20600000.SH2021-12-312022-04-28NaTNaTNaT2022-04-28NaTNaT2.935217e+100.00.0nanNaT
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codecount
0000106.SH3080
1000844.SH2350
2000919.SH3080
3399210.SZ765
4399300.SZ3080
.........
980857244.SW3079
981857421.SW3080
982859512.SW3079
983859852.SW3080
984I899001.CS1862
\n", "

985 rows × 2 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
m_nDatecodecloseyclosePctChgfactor
02020-09-11600519.SH1733.001705.801.5945603.334994
12020-09-14600519.SH1766.001733.001.9042123.334994
22020-09-15600519.SH1760.001766.00-0.3397513.334994
32020-09-16600519.SH1725.101760.00-1.9829553.334994
42020-09-17600519.SH1670.521725.10-3.1638753.334994
52020-09-18600519.SH1695.001670.521.4654123.334994
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ycloseclosefactor
instrumentdatetime
000300.SH2010-01-043575.6840NaNNaN
2010-01-053535.22903535.22901.000000
2010-01-063564.03803564.03801.000000
2010-01-073541.72703541.72701.000000
2010-01-083471.45603471.45601.000000
............
2022-08-294107.54554107.54551.000698
2022-08-304089.52054089.52051.000698
2022-08-314075.79374075.79371.000698
2022-09-014078.84024078.84021.000698
2022-09-024043.73954043.73951.000698
\n", "

3080 rows × 3 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ycloseclosefactor2factor
instrumentdatetime
600519.SH2020-09-161760.01760.03.3349943.334994
\n", "
" ], "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/', , 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/',