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.
dataloader/dolphindb-test-clean.ipynb

1874 lines
75 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": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import dolphindb as ddb\n",
"import dolphindb.settings as keys\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"\n",
"sess = ddb.session('192.168.64.3',8848)\n",
"sess.login('admin','123456')\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'/hft_fm_combo': 'pt:2:0:pt_2; ',\n",
" '/db_compo_test': 'pt:2:0:pt_2; ',\n",
" '/compoDB': 'pt:2:0:pt_2; ',\n",
" '/daily_futuremarket_ts': 'db_daily_kline:2:0:db_daily_kline_2; '}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run('getAllDBs()')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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>StockID</th>\n",
" <th>open</th>\n",
" <th>high</th>\n",
" <th>low</th>\n",
" <th>close</th>\n",
" <th>vol</th>\n",
" <th>sectional_vol</th>\n",
" <th>cjbs</th>\n",
" <th>sectional_cjbs</th>\n",
" <th>price</th>\n",
" <th>yclose</th>\n",
" <th>buy_vol</th>\n",
" <th>buy_amount</th>\n",
" <th>sale_vol</th>\n",
" <th>sale_amount</th>\n",
" <th>zmm</th>\n",
" <th>amount</th>\n",
" <th>date</th>\n",
" <th>time1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>AP2212</td>\n",
" <td>8387.0</td>\n",
" <td>8387.0</td>\n",
" <td>8387.0</td>\n",
" <td>8387.0</td>\n",
" <td>9.0</td>\n",
" <td>9.0</td>\n",
" <td>-9.0</td>\n",
" <td>19565</td>\n",
" <td>8387.0</td>\n",
" <td>8413.0</td>\n",
" <td>4.5</td>\n",
" <td>37741.5</td>\n",
" <td>4.5</td>\n",
" <td>37741.5</td>\n",
" <td>3</td>\n",
" <td>75483.0</td>\n",
" <td>2022-09-19</td>\n",
" <td>08:59:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>AP2212</td>\n",
" <td>8361.0</td>\n",
" <td>8361.0</td>\n",
" <td>8361.0</td>\n",
" <td>8361.0</td>\n",
" <td>8.0</td>\n",
" <td>17.0</td>\n",
" <td>0.0</td>\n",
" <td>19565</td>\n",
" <td>8361.0</td>\n",
" <td>8387.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>8.0</td>\n",
" <td>66892.0</td>\n",
" <td>2</td>\n",
" <td>66892.0</td>\n",
" <td>2022-09-19</td>\n",
" <td>09:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>AP2212</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>6.0</td>\n",
" <td>23.0</td>\n",
" <td>0.0</td>\n",
" <td>19565</td>\n",
" <td>8356.0</td>\n",
" <td>8361.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>6.0</td>\n",
" <td>50158.0</td>\n",
" <td>2</td>\n",
" <td>50158.0</td>\n",
" <td>2022-09-19</td>\n",
" <td>09:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>AP2212</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>1.0</td>\n",
" <td>24.0</td>\n",
" <td>0.0</td>\n",
" <td>19565</td>\n",
" <td>8356.0</td>\n",
" <td>8356.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>8347.0</td>\n",
" <td>2</td>\n",
" <td>8347.0</td>\n",
" <td>2022-09-19</td>\n",
" <td>09:00:05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>AP2212</td>\n",
" <td>8397.0</td>\n",
" <td>8397.0</td>\n",
" <td>8397.0</td>\n",
" <td>8397.0</td>\n",
" <td>1.0</td>\n",
" <td>25.0</td>\n",
" <td>-1.0</td>\n",
" <td>19564</td>\n",
" <td>8397.0</td>\n",
" <td>8356.0</td>\n",
" <td>1.0</td>\n",
" <td>8395.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1</td>\n",
" <td>8395.0</td>\n",
" <td>2022-09-19</td>\n",
" <td>09:00:09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2336544</th>\n",
" <td>AP2212</td>\n",
" <td>8744.0</td>\n",
" <td>8744.0</td>\n",
" <td>8744.0</td>\n",
" <td>8744.0</td>\n",
" <td>1.0</td>\n",
" <td>2583.0</td>\n",
" <td>0.0</td>\n",
" <td>13718</td>\n",
" <td>8744.0</td>\n",
" <td>8756.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>8722.0</td>\n",
" <td>2</td>\n",
" <td>8722.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>09:25:28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2336547</th>\n",
" <td>AP2212</td>\n",
" <td>8746.0</td>\n",
" <td>8746.0</td>\n",
" <td>8746.0</td>\n",
" <td>8746.0</td>\n",
" <td>1.0</td>\n",
" <td>2584.0</td>\n",
" <td>0.0</td>\n",
" <td>13718</td>\n",
" <td>8746.0</td>\n",
" <td>8744.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>8722.0</td>\n",
" <td>2</td>\n",
" <td>8722.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>09:25:34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2336549</th>\n",
" <td>AP2212</td>\n",
" <td>8743.0</td>\n",
" <td>8743.0</td>\n",
" <td>8743.0</td>\n",
" <td>8743.0</td>\n",
" <td>1.0</td>\n",
" <td>2585.0</td>\n",
" <td>0.0</td>\n",
" <td>13718</td>\n",
" <td>8743.0</td>\n",
" <td>8746.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>8722.0</td>\n",
" <td>2</td>\n",
" <td>8722.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>09:25:37</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2336592</th>\n",
" <td>AP2212</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>2.0</td>\n",
" <td>2587.0</td>\n",
" <td>0.0</td>\n",
" <td>13718</td>\n",
" <td>8747.0</td>\n",
" <td>8743.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>17444.0</td>\n",
" <td>2</td>\n",
" <td>17444.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>09:26:59</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2336594</th>\n",
" <td>AP2212</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>3.0</td>\n",
" <td>2590.0</td>\n",
" <td>3.0</td>\n",
" <td>13721</td>\n",
" <td>8747.0</td>\n",
" <td>8747.0</td>\n",
" <td>3.0</td>\n",
" <td>26166.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1</td>\n",
" <td>26166.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>09:27:03</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>40456 rows × 19 columns</p>\n",
"</div>"
],
"text/plain": [
" StockID open high low close vol sectional_vol cjbs \\\n",
"17 AP2212 8387.0 8387.0 8387.0 8387.0 9.0 9.0 -9.0 \n",
"18 AP2212 8361.0 8361.0 8361.0 8361.0 8.0 17.0 0.0 \n",
"19 AP2212 8356.0 8356.0 8356.0 8356.0 6.0 23.0 0.0 \n",
"25 AP2212 8356.0 8356.0 8356.0 8356.0 1.0 24.0 0.0 \n",
"30 AP2212 8397.0 8397.0 8397.0 8397.0 1.0 25.0 -1.0 \n",
"... ... ... ... ... ... ... ... ... \n",
"2336544 AP2212 8744.0 8744.0 8744.0 8744.0 1.0 2583.0 0.0 \n",
"2336547 AP2212 8746.0 8746.0 8746.0 8746.0 1.0 2584.0 0.0 \n",
"2336549 AP2212 8743.0 8743.0 8743.0 8743.0 1.0 2585.0 0.0 \n",
"2336592 AP2212 8747.0 8747.0 8747.0 8747.0 2.0 2587.0 0.0 \n",
"2336594 AP2212 8747.0 8747.0 8747.0 8747.0 3.0 2590.0 3.0 \n",
"\n",
" sectional_cjbs price yclose buy_vol buy_amount sale_vol \\\n",
"17 19565 8387.0 8413.0 4.5 37741.5 4.5 \n",
"18 19565 8361.0 8387.0 0.0 0.0 8.0 \n",
"19 19565 8356.0 8361.0 0.0 0.0 6.0 \n",
"25 19565 8356.0 8356.0 0.0 0.0 1.0 \n",
"30 19564 8397.0 8356.0 1.0 8395.0 0.0 \n",
"... ... ... ... ... ... ... \n",
"2336544 13718 8744.0 8756.0 0.0 0.0 1.0 \n",
"2336547 13718 8746.0 8744.0 0.0 0.0 1.0 \n",
"2336549 13718 8743.0 8746.0 0.0 0.0 1.0 \n",
"2336592 13718 8747.0 8743.0 0.0 0.0 2.0 \n",
"2336594 13721 8747.0 8747.0 3.0 26166.0 0.0 \n",
"\n",
" sale_amount zmm amount date time1 \n",
"17 37741.5 3 75483.0 2022-09-19 08:59:00 \n",
"18 66892.0 2 66892.0 2022-09-19 09:00:00 \n",
"19 50158.0 2 50158.0 2022-09-19 09:00:00 \n",
"25 8347.0 2 8347.0 2022-09-19 09:00:05 \n",
"30 0.0 1 8395.0 2022-09-19 09:00:09 \n",
"... ... ... ... ... ... \n",
"2336544 8722.0 2 8722.0 2022-11-01 09:25:28 \n",
"2336547 8722.0 2 8722.0 2022-11-01 09:25:34 \n",
"2336549 8722.0 2 8722.0 2022-11-01 09:25:37 \n",
"2336592 17444.0 2 17444.0 2022-11-01 09:26:59 \n",
"2336594 0.0 1 26166.0 2022-11-01 09:27:03 \n",
"\n",
"[40456 rows x 19 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('data/trade_AP2211+AP2212+AP2301+AP2303+AP2304+AP2305+AP2310+CF2211+CF2301+CF2303+CF2305+CF2307+CF2309_20220919_20221101.csv',index_col=None)\n",
"df.drop(columns=['Unnamed: 0'],inplace=True)\n",
"df=df[df['time1']<'09:30:00']\n",
"df = df[df['vol']>0]\n",
"df['date']=df['date'].astype('datetime64[D]')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"df['init']=df['init'].astype('str')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"df['init']=df['StockID'].apply(lambda x:x[:-4])\n",
"df['finishm']=df['StockID'].apply(lambda x:x[-4:])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['AP'], dtype=object)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['init'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"71"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"all_init={'sc', 'v', 'TS', 'MA', 'AP', 'jm', 'bc', 'bb', 'fu', 'IM', 'IF', 'a', 'lu', 'FG', 'cu', 'al', 'IH', 'RS', 'pg', 'CF', 'SF', 'ni', 'hc', 'UR', 'm', 'SR', 'j', 'PF', 'RM', 'T', 'c', 'JR', 'l', 'p', 'sp', 'CY', 'pb', 'TF', 'b', 'eg', 'rb', 'PK', 'sn', 'nr', 'pp', 'CJ', 'eb', 'SA', 'y', 'RI', 'lh', 'jd', 'OI', 'WH', 'ss', 'ru', 'zn', 'fb', 'rr', 'PM', 'au', 'TA', 'ZC', 'IC', 'bu', 'SM', 'wr', 'cs', 'LR', 'ag', 'i'}\n",
"len(all_init)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"db_init = sess.database(dbName='db_init', partitionType=keys.VALUE, partitions=list(all_init),dbPath='')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"db_code = sess.database(dbName='db_code', partitionType=keys.HASH, partitions=list(all_init),dbPath='')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DatetimeIndex(['1990-01-31', '1990-02-28', '1990-03-31', '1990-04-30',\n",
" '1990-05-31', '1990-06-30', '1990-07-31', '1990-08-31',\n",
" '1990-09-30', '1990-10-31',\n",
" ...\n",
" '2050-03-31', '2050-04-30', '2050-05-31', '2050-06-30',\n",
" '2050-07-31', '2050-08-31', '2050-09-30', '2050-10-31',\n",
" '2050-11-30', '2050-12-31'],\n",
" dtype='datetime64[ns]', length=732, freq='M')\n"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"dr = pd.date_range(start='1990-01-01', end='2050-12-31', freq=\"M\")\n",
"months=np.array(dr, dtype=\"datetime64[M]\")\n",
"print(dr)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['1990-01' '1990-02' '1990-03' '1990-04' '1990-05' '1990-06' '1990-07'\n",
" '1990-08' '1990-09' '1990-10' '1990-11' '1990-12' '1991-01' '1991-02'\n",
" '1991-03' '1991-04' '1991-05' '1991-06' '1991-07' '1991-08' '1991-09'\n",
" '1991-10' '1991-11' '1991-12' '1992-01' '1992-02' '1992-03' '1992-04'\n",
" '1992-05' '1992-06' '1992-07' '1992-08' '1992-09' '1992-10' '1992-11'\n",
" '1992-12' '1993-01' '1993-02' '1993-03' '1993-04' '1993-05' '1993-06'\n",
" '1993-07' '1993-08' '1993-09' '1993-10' '1993-11' '1993-12' '1994-01'\n",
" '1994-02' '1994-03' '1994-04' '1994-05' '1994-06' '1994-07' '1994-08'\n",
" '1994-09' '1994-10' '1994-11' '1994-12' '1995-01' '1995-02' '1995-03'\n",
" '1995-04' '1995-05' '1995-06' '1995-07' '1995-08' '1995-09' '1995-10'\n",
" '1995-11' '1995-12' '1996-01' '1996-02' '1996-03' '1996-04' '1996-05'\n",
" '1996-06' '1996-07' '1996-08' '1996-09' '1996-10' '1996-11' '1996-12'\n",
" '1997-01' '1997-02' '1997-03' '1997-04' '1997-05' '1997-06' '1997-07'\n",
" '1997-08' '1997-09' '1997-10' '1997-11' '1997-12' '1998-01' '1998-02'\n",
" '1998-03' '1998-04' '1998-05' '1998-06' '1998-07' '1998-08' '1998-09'\n",
" '1998-10' '1998-11' '1998-12' '1999-01' '1999-02' '1999-03' '1999-04'\n",
" '1999-05' '1999-06' '1999-07' '1999-08' '1999-09' '1999-10' '1999-11'\n",
" '1999-12' '2000-01' '2000-02' '2000-03' '2000-04' '2000-05' '2000-06'\n",
" '2000-07' '2000-08' '2000-09' '2000-10' '2000-11' '2000-12' '2001-01'\n",
" '2001-02' '2001-03' '2001-04' '2001-05' '2001-06' '2001-07' '2001-08'\n",
" '2001-09' '2001-10' '2001-11' '2001-12' '2002-01' '2002-02' '2002-03'\n",
" '2002-04' '2002-05' '2002-06' '2002-07' '2002-08' '2002-09' '2002-10'\n",
" '2002-11' '2002-12' '2003-01' '2003-02' '2003-03' '2003-04' '2003-05'\n",
" '2003-06' '2003-07' '2003-08' '2003-09' '2003-10' '2003-11' '2003-12'\n",
" '2004-01' '2004-02' '2004-03' '2004-04' '2004-05' '2004-06' '2004-07'\n",
" '2004-08' '2004-09' '2004-10' '2004-11' '2004-12' '2005-01' '2005-02'\n",
" '2005-03' '2005-04' '2005-05' '2005-06' '2005-07' '2005-08' '2005-09'\n",
" '2005-10' '2005-11' '2005-12' '2006-01' '2006-02' '2006-03' '2006-04'\n",
" '2006-05' '2006-06' '2006-07' '2006-08' '2006-09' '2006-10' '2006-11'\n",
" '2006-12' '2007-01' '2007-02' '2007-03' '2007-04' '2007-05' '2007-06'\n",
" '2007-07' '2007-08' '2007-09' '2007-10' '2007-11' '2007-12' '2008-01'\n",
" '2008-02' '2008-03' '2008-04' '2008-05' '2008-06' '2008-07' '2008-08'\n",
" '2008-09' '2008-10' '2008-11' '2008-12' '2009-01' '2009-02' '2009-03'\n",
" '2009-04' '2009-05' '2009-06' '2009-07' '2009-08' '2009-09' '2009-10'\n",
" '2009-11' '2009-12' '2010-01' '2010-02' '2010-03' '2010-04' '2010-05'\n",
" '2010-06' '2010-07' '2010-08' '2010-09' '2010-10' '2010-11' '2010-12'\n",
" '2011-01' '2011-02' '2011-03' '2011-04' '2011-05' '2011-06' '2011-07'\n",
" '2011-08' '2011-09' '2011-10' '2011-11' '2011-12' '2012-01' '2012-02'\n",
" '2012-03' '2012-04' '2012-05' '2012-06' '2012-07' '2012-08' '2012-09'\n",
" '2012-10' '2012-11' '2012-12' '2013-01' '2013-02' '2013-03' '2013-04'\n",
" '2013-05' '2013-06' '2013-07' '2013-08' '2013-09' '2013-10' '2013-11'\n",
" '2013-12' '2014-01' '2014-02' '2014-03' '2014-04' '2014-05' '2014-06'\n",
" '2014-07' '2014-08' '2014-09' '2014-10' '2014-11' '2014-12' '2015-01'\n",
" '2015-02' '2015-03' '2015-04' '2015-05' '2015-06' '2015-07' '2015-08'\n",
" '2015-09' '2015-10' '2015-11' '2015-12' '2016-01' '2016-02' '2016-03'\n",
" '2016-04' '2016-05' '2016-06' '2016-07' '2016-08' '2016-09' '2016-10'\n",
" '2016-11' '2016-12' '2017-01' '2017-02' '2017-03' '2017-04' '2017-05'\n",
" '2017-06' '2017-07' '2017-08' '2017-09' '2017-10' '2017-11' '2017-12'\n",
" '2018-01' '2018-02' '2018-03' '2018-04' '2018-05' '2018-06' '2018-07'\n",
" '2018-08' '2018-09' '2018-10' '2018-11' '2018-12' '2019-01' '2019-02'\n",
" '2019-03' '2019-04' '2019-05' '2019-06' '2019-07' '2019-08' '2019-09'\n",
" '2019-10' '2019-11' '2019-12' '2020-01' '2020-02' '2020-03' '2020-04'\n",
" '2020-05' '2020-06' '2020-07' '2020-08' '2020-09' '2020-10' '2020-11'\n",
" '2020-12' '2021-01' '2021-02' '2021-03' '2021-04' '2021-05' '2021-06'\n",
" '2021-07' '2021-08' '2021-09' '2021-10' '2021-11' '2021-12' '2022-01'\n",
" '2022-02' '2022-03' '2022-04' '2022-05' '2022-06' '2022-07' '2022-08'\n",
" '2022-09' '2022-10' '2022-11' '2022-12' '2023-01' '2023-02' '2023-03'\n",
" '2023-04' '2023-05' '2023-06' '2023-07' '2023-08' '2023-09' '2023-10'\n",
" '2023-11' '2023-12' '2024-01' '2024-02' '2024-03' '2024-04' '2024-05'\n",
" '2024-06' '2024-07' '2024-08' '2024-09' '2024-10' '2024-11' '2024-12'\n",
" '2025-01' '2025-02' '2025-03' '2025-04' '2025-05' '2025-06' '2025-07'\n",
" '2025-08' '2025-09' '2025-10' '2025-11' '2025-12' '2026-01' '2026-02'\n",
" '2026-03' '2026-04' '2026-05' '2026-06' '2026-07' '2026-08' '2026-09'\n",
" '2026-10' '2026-11' '2026-12' '2027-01' '2027-02' '2027-03' '2027-04'\n",
" '2027-05' '2027-06' '2027-07' '2027-08' '2027-09' '2027-10' '2027-11'\n",
" '2027-12' '2028-01' '2028-02' '2028-03' '2028-04' '2028-05' '2028-06'\n",
" '2028-07' '2028-08' '2028-09' '2028-10' '2028-11' '2028-12' '2029-01'\n",
" '2029-02' '2029-03' '2029-04' '2029-05' '2029-06' '2029-07' '2029-08'\n",
" '2029-09' '2029-10' '2029-11' '2029-12' '2030-01' '2030-02' '2030-03'\n",
" '2030-04' '2030-05' '2030-06' '2030-07' '2030-08' '2030-09' '2030-10'\n",
" '2030-11' '2030-12' '2031-01' '2031-02' '2031-03' '2031-04' '2031-05'\n",
" '2031-06' '2031-07' '2031-08' '2031-09' '2031-10' '2031-11' '2031-12'\n",
" '2032-01' '2032-02' '2032-03' '2032-04' '2032-05' '2032-06' '2032-07'\n",
" '2032-08' '2032-09' '2032-10' '2032-11' '2032-12' '2033-01' '2033-02'\n",
" '2033-03' '2033-04' '2033-05' '2033-06' '2033-07' '2033-08' '2033-09'\n",
" '2033-10' '2033-11' '2033-12' '2034-01' '2034-02' '2034-03' '2034-04'\n",
" '2034-05' '2034-06' '2034-07' '2034-08' '2034-09' '2034-10' '2034-11'\n",
" '2034-12' '2035-01' '2035-02' '2035-03' '2035-04' '2035-05' '2035-06'\n",
" '2035-07' '2035-08' '2035-09' '2035-10' '2035-11' '2035-12' '2036-01'\n",
" '2036-02' '2036-03' '2036-04' '2036-05' '2036-06' '2036-07' '2036-08'\n",
" '2036-09' '2036-10' '2036-11' '2036-12' '2037-01' '2037-02' '2037-03'\n",
" '2037-04' '2037-05' '2037-06' '2037-07' '2037-08' '2037-09' '2037-10'\n",
" '2037-11' '2037-12' '2038-01' '2038-02' '2038-03' '2038-04' '2038-05'\n",
" '2038-06' '2038-07' '2038-08' '2038-09' '2038-10' '2038-11' '2038-12'\n",
" '2039-01' '2039-02' '2039-03' '2039-04' '2039-05' '2039-06' '2039-07'\n",
" '2039-08' '2039-09' '2039-10' '2039-11' '2039-12' '2040-01' '2040-02'\n",
" '2040-03' '2040-04' '2040-05' '2040-06' '2040-07' '2040-08' '2040-09'\n",
" '2040-10' '2040-11' '2040-12' '2041-01' '2041-02' '2041-03' '2041-04'\n",
" '2041-05' '2041-06' '2041-07' '2041-08' '2041-09' '2041-10' '2041-11'\n",
" '2041-12' '2042-01' '2042-02' '2042-03' '2042-04' '2042-05' '2042-06'\n",
" '2042-07' '2042-08' '2042-09' '2042-10' '2042-11' '2042-12' '2043-01'\n",
" '2043-02' '2043-03' '2043-04' '2043-05' '2043-06' '2043-07' '2043-08'\n",
" '2043-09' '2043-10' '2043-11' '2043-12' '2044-01' '2044-02' '2044-03'\n",
" '2044-04' '2044-05' '2044-06' '2044-07' '2044-08' '2044-09' '2044-10'\n",
" '2044-11' '2044-12' '2045-01' '2045-02' '2045-03' '2045-04' '2045-05'\n",
" '2045-06' '2045-07' '2045-08' '2045-09' '2045-10' '2045-11' '2045-12'\n",
" '2046-01' '2046-02' '2046-03' '2046-04' '2046-05' '2046-06' '2046-07'\n",
" '2046-08' '2046-09' '2046-10' '2046-11' '2046-12' '2047-01' '2047-02'\n",
" '2047-03' '2047-04' '2047-05' '2047-06' '2047-07' '2047-08' '2047-09'\n",
" '2047-10' '2047-11' '2047-12' '2048-01' '2048-02' '2048-03' '2048-04'\n",
" '2048-05' '2048-06' '2048-07' '2048-08' '2048-09' '2048-10' '2048-11'\n",
" '2048-12' '2049-01' '2049-02' '2049-03' '2049-04' '2049-05' '2049-06'\n",
" '2049-07' '2049-08' '2049-09' '2049-10' '2049-11' '2049-12' '2050-01'\n",
" '2050-02' '2050-03' '2050-04' '2050-05' '2050-06' '2050-07' '2050-08'\n",
" '2050-09' '2050-10' '2050-11' '2050-12']\n"
]
}
],
"source": [
"months=np.array(pd.date_range(start='2000-01-01', end='2050-12-31', freq=\"M\"), dtype=\"datetime64[M]\")\n",
"print(months)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"\n",
"db_date = sess.database('db_date', partitionType=keys.VALUE, partitions=months, dbPath='')\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"dbPath = 'dfs://hft_fm_combo'\n",
"if sess.existsDatabase(dbPath): \n",
" sess.dropDatabase(dbPath)\n",
"db = sess.database(dbName='db_hft_fm_3', partitionType=keys.COMPO, partitions=[db_date, db_init], dbPath=dbPath)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# sess.run(\"\"\"\n",
"# {dbName} = database(\n",
"# directory = '{dbPath}', \n",
"# partitionType = COMPO, \n",
"# partitionScheme = [db_date, db_init])\n",
"# \"\"\".format(\n",
"# dbName = 'db_hft_fm_3',\n",
"# dbPath = 'hft_futuremarket_ts_combo'\n",
"# ))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"t = sess.table(data=df,tableAliasName='table')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" {ddb_dbname}.createPartitionedTable(\n",
" table = {memory_table_name}, \n",
" tableName = `{partition_table_name}, \n",
" partitionColumns = `date`StockID, \n",
" sortColumns = `StockID`date,\n",
" compressMethods = {{date:\"delta\"}}\n",
" )\n",
" \"\"\".format(\n",
" ddb_dbname = 'db_hft_fm_3',\n",
" memory_table_name = 'testData',\n",
" partition_table_name = 'pt3'\n",
" ))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"pt =db.createPartitionedTable(table=t, tableName=\"pt\", partitionColumns=['date', 'init'])"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<dolphindb.table.Table at 0x12684d340>"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pt.append(t)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'/hft_fm_combo': 'pt:2:0:pt_2; ',\n",
" '/db_compo_test': 'pt:2:0:pt_2; ',\n",
" '/compoDB': 'pt:2:0:pt_2; ',\n",
" '/daily_futuremarket_ts': 'db_daily_kline:2:0:db_daily_kline_2; '}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run('getAllDBs()')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame({'date': np.array(['2012-01-01', '2012-02-01', '2012-05-01', '2012-06-01'], dtype=\"datetime64\"), 'val':[1,2,3,4],'code':['AP2313','FD1023','AP1023','ED2333']})\n",
"df\n",
"df['init']=df['code'].apply(lambda x: x[:2])\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"dbPath=\"dfs://db_compo_test\"\n",
"if sess.existsDatabase(dbPath):\n",
" sess.dropDatabase(dbPath)\n",
"\n",
"months=np.array(pd.date_range(start='2012-01', end='2012-10', freq=\"M\"), dtype=\"datetime64[M]\")\n",
"\n",
"db1 = sess.database('db1', partitionType=keys.VALUE,partitions=months, dbPath='')\n",
"\n",
"db2 = sess.database('db2', partitionType=keys.RANGE,partitions=[1, 6, 11], dbPath='')\n",
"# dbPath=\"dfs://db_compo_test\"\n",
"if sess.existsDatabase(dbPath):\n",
" sess.dropDatabase(dbPath)\n",
"db = sess.database(dbName='mydb', partitionType=keys.COMPO, partitions=[db1, db2], dbPath=dbPath)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df2 = pd.DataFrame({'date':np.array(['2012-01-01', '2012-01-01', '2012-02-06', '2012-03-06'], dtype='datetime64'), 'val': [1, 6, 1, 6]})\n",
"t = sess.table(data=df2)\n",
"# df['date'].dtype()\n",
"df2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"db.createPartitionedTable(table=t, tableName='pt', partitionColumns=['date', 'val']).append(t)\n",
"re = sess.loadTable(tableName='pt', dbPath=dbPath).toDF()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-11-09 14:48:51.524 | INFO | src.TSLfm:__enter__:18 - Logging in TSL.\n",
"2022-11-09 14:48:51.708 | DEBUG | src.TSLfm:get_mkt_min_k:209 - \n",
" SetSysParam(pn_cycle(), cy_1m());\n",
" stock_list := Array('CF2211', 'CF2301', 'CF2303', 'CF2305', 'CF2307', 'CF2309');\n",
" r := select \n",
" ['StockID'] as 'code',\n",
" DateTimeToStr(['date']) as 'm_nDatetime',\n",
"\n",
" ['price'] as 'm_nPrice',\n",
" ['open'] as 'm_nOpen',\n",
" ['high'] as 'm_nHigh',\n",
" ['low'] as 'm_nLow',\n",
" ['close'] as 'm_nClose',\n",
"\n",
" ['sectional_high'] as 'm_nAccHigh',\n",
" ['sectional_low'] as 'm_nAccLow',\n",
"\n",
" ['vol'] as 'm_iVolume', //成交量\n",
" ['sectional_vol'] as 'm_iAccVolume', //时点当日累计成交量\n",
"\n",
" ['cjbs'] as 'm_nMatchItems', // 成交笔数 周期内的持仓的变动量\n",
" ['sectional_cjbs'] as 'm_nAccMatchItems',\n",
"\n",
" ['amount'] as 'm_iTurnover', //成交金额\n",
" ['sectional_amount'] as 'm_iAccTurnover', \n",
"\n",
" ['yclose'] as 'm_nPreClose', //上一周期的收盘价\n",
" ['sectional_yclose'] as 'm_nAccPreClose', // 前日收盘\n",
" \n",
" ['buy1'] as 'm_nBidPrice', //买一价?叫卖价?\n",
" ['bc1'] as 'm_nBidVolume', //买一量 当前以买一价出价的委买量\n",
" ['sale1'] as 'm_nAskPrice', \n",
" ['sc1'] as 'm_nAskVolume', \n",
"\n",
" ['zmm'] as 'm_iABFlag', //买卖标识\n",
"\n",
" ['buy_vol'] as 'm_nActBidVolume', //主买量\n",
" ['sectional_buy_vol'] as 'm_nAccActBidVolume', //时点当日累计主买量\n",
" ['buy_amount'] as 'm_nActBidTurnover', //主买金额\n",
" ['sectional_buy_amount'] as 'm_nAccActBidTurnover', \n",
"\n",
" ['sale_vol'] as 'm_nActAskVolume', \n",
" ['sectional_sale_vol'] as 'm_nAccActAskVolume', \n",
" ['sale_amount'] as 'm_nActAskTurnover',\n",
" ['sectional_sale_amount'] as 'm_nAccActAskTurnover', \n",
"\n",
" ['w_buy'] as 'm_nBidOrder', //委买\n",
" ['sectional_w_buy'] as 'm_nAccBidOrder', \n",
" ['w_sale'] as 'm_nAskOrder',\n",
" ['sectional_w_sale'] as 'm_nAccAskOrder',\n",
"\n",
" ['wb'] as 'm_nABOrderRate', //委比\n",
" ['sectional_wb'] as 'm_nAccABOrderRate', //时点当日累计委比\n",
" ['lb'] as 'm_nMItemsVolRate'//量比\n",
"\n",
"\n",
" from markettable\n",
" datekey 20221001T to 20221101T+0.999 \n",
" of stock_list\n",
" end;\n",
" \n",
" return r; \n",
" \n",
"2022-11-09 14:49:05.395 | INFO | src.TSLfm:process_result_data_type:215 - Processing new df of shape (35910, 37), which looks like\n",
" code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n",
"0 CF2303 2022-10-07 21:01:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"1 CF2303 2022-10-07 21:02:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"2 CF2303 2022-10-07 21:03:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"3 CF2303 2022-10-07 21:04:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"4 CF2303 2022-10-07 21:05:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"\n",
" m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n",
"0 13445.0 13445.0 0.0 0.0 0.0 \n",
"1 13445.0 13445.0 0.0 0.0 0.0 \n",
"2 13445.0 13445.0 0.0 0.0 0.0 \n",
"3 13445.0 13445.0 0.0 0.0 0.0 \n",
"4 13445.0 13445.0 0.0 0.0 0.0 \n",
"\n",
" m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n",
"0 96132 0.0 0.0 13445.0 13445.0 \n",
"1 96132 0.0 0.0 13445.0 13445.0 \n",
"2 96132 0.0 0.0 13445.0 13445.0 \n",
"3 96132 0.0 0.0 13445.0 13445.0 \n",
"4 96132 0.0 0.0 13445.0 13445.0 \n",
"\n",
" m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n",
"0 0.0 0 0.0 0 0 \n",
"1 0.0 0 0.0 0 0 \n",
"2 0.0 0 0.0 0 0 \n",
"3 0.0 0 0.0 0 0 \n",
"4 0.0 0 0.0 0 0 \n",
"\n",
" m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n",
"0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 \n",
"\n",
" m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n",
"0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 \n",
"\n",
" m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nMItemsVolRate \n",
"0 0.0 \n",
"1 0.0 \n",
"2 0.0 \n",
"3 0.0 \n",
"4 0.0 \n",
"2022-11-09 14:49:05.493 | INFO | src.TSLfm:process_result_data_type:229 - Processing done, new df looks like\n",
" code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n",
"0 CF2303 2022-10-07 21:01:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"1 CF2303 2022-10-07 21:02:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"2 CF2303 2022-10-07 21:03:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"3 CF2303 2022-10-07 21:04:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"4 CF2303 2022-10-07 21:05:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"\n",
" m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n",
"0 13445.0 13445.0 0 0 0 \n",
"1 13445.0 13445.0 0 0 0 \n",
"2 13445.0 13445.0 0 0 0 \n",
"3 13445.0 13445.0 0 0 0 \n",
"4 13445.0 13445.0 0 0 0 \n",
"\n",
" m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n",
"0 30596 0.0 0.0 13445.0 13445.0 \n",
"1 30596 0.0 0.0 13445.0 13445.0 \n",
"2 30596 0.0 0.0 13445.0 13445.0 \n",
"3 30596 0.0 0.0 13445.0 13445.0 \n",
"4 30596 0.0 0.0 13445.0 13445.0 \n",
"\n",
" m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n",
"0 0.0 0 0.0 0 0 \n",
"1 0.0 0 0.0 0 0 \n",
"2 0.0 0 0.0 0 0 \n",
"3 0.0 0 0.0 0 0 \n",
"4 0.0 0 0.0 0 0 \n",
"\n",
" m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n",
"0 0 0 0.0 \n",
"1 0 0 0.0 \n",
"2 0 0 0.0 \n",
"3 0 0 0.0 \n",
"4 0 0 0.0 \n",
"\n",
" m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n",
"0 0.0 0 0 \n",
"1 0.0 0 0 \n",
"2 0.0 0 0 \n",
"3 0.0 0 0 \n",
"4 0.0 0 0 \n",
"\n",
" m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nMItemsVolRate m_nDate code_init \n",
"0 0.0 2022-10-07 CF \n",
"1 0.0 2022-10-07 CF \n",
"2 0.0 2022-10-07 CF \n",
"3 0.0 2022-10-07 CF \n",
"4 0.0 2022-10-07 CF \n",
"2022-11-09 14:49:05.501 | INFO | src.TSLfm:__exit__:24 - Logging out TSL.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"(35910, 39)\n",
" code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n",
"0 CF2303 2022-10-07 21:01:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"1 CF2303 2022-10-07 21:02:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"2 CF2303 2022-10-07 21:03:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"3 CF2303 2022-10-07 21:04:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"4 CF2303 2022-10-07 21:05:00 13445.0 13445.0 13445.0 13445.0 13445.0 \n",
"\n",
" m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n",
"0 13445.0 13445.0 0 0 0 \n",
"1 13445.0 13445.0 0 0 0 \n",
"2 13445.0 13445.0 0 0 0 \n",
"3 13445.0 13445.0 0 0 0 \n",
"4 13445.0 13445.0 0 0 0 \n",
"\n",
" m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n",
"0 30596 0.0 0.0 13445.0 13445.0 \n",
"1 30596 0.0 0.0 13445.0 13445.0 \n",
"2 30596 0.0 0.0 13445.0 13445.0 \n",
"3 30596 0.0 0.0 13445.0 13445.0 \n",
"4 30596 0.0 0.0 13445.0 13445.0 \n",
"\n",
" m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n",
"0 0.0 0 0.0 0 0 \n",
"1 0.0 0 0.0 0 0 \n",
"2 0.0 0 0.0 0 0 \n",
"3 0.0 0 0.0 0 0 \n",
"4 0.0 0 0.0 0 0 \n",
"\n",
" m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n",
"0 0 0 0.0 \n",
"1 0 0 0.0 \n",
"2 0 0 0.0 \n",
"3 0 0 0.0 \n",
"4 0 0 0.0 \n",
"\n",
" m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n",
"0 0.0 0 0 \n",
"1 0.0 0 0 \n",
"2 0.0 0 0 \n",
"3 0.0 0 0 \n",
"4 0.0 0 0 \n",
"\n",
" m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n",
"0 0.0 0.0 0.0 0.0 \n",
"1 0.0 0.0 0.0 0.0 \n",
"2 0.0 0.0 0.0 0.0 \n",
"3 0.0 0.0 0.0 0.0 \n",
"4 0.0 0.0 0.0 0.0 \n",
"\n",
" m_nMItemsVolRate m_nDate code_init \n",
"0 0.0 2022-10-07 CF \n",
"1 0.0 2022-10-07 CF \n",
"2 0.0 2022-10-07 CF \n",
"3 0.0 2022-10-07 CF \n",
"4 0.0 2022-10-07 CF \n"
]
}
],
"source": [
"\n",
"from src.TSLfm import TSLfm\n",
"import pandas as pd \n",
"import numpy as np\n",
"pd.set_option('display.max_columns', 100)\n",
"\n",
"with TSLfm() as tsl:\n",
" \n",
" # t_list= tsl.get_code_list()\n",
" t_list=['CF2211', 'CF2301', 'CF2303', 'CF2305', 'CF2307', 'CF2309']\n",
" # t_list=['AP2212']\n",
" # t_list=['CF2211']\n",
" df = tsl.process_result_data_type(tsl.get_mkt_min_k('20221001','20221101',t_list))\n",
" \n",
" print(df.shape)\n",
" print(df.head())\n",
"\n",
"df.to_csv('data/CF202210.csv')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"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_nPrice</th>\n",
" <th>m_nOpen</th>\n",
" <th>m_nHigh</th>\n",
" <th>m_nLow</th>\n",
" <th>m_nClose</th>\n",
" <th>m_nAccHigh</th>\n",
" <th>m_nAccLow</th>\n",
" <th>m_iVolume</th>\n",
" <th>m_iAccVolume</th>\n",
" <th>m_nMatchItems</th>\n",
" <th>m_nAccMatchItems</th>\n",
" <th>m_iTurover</th>\n",
" <th>m_iAccTurover</th>\n",
" <th>m_nPreClose</th>\n",
" <th>m_nAccPreClose</th>\n",
" <th>m_nBidPrice</th>\n",
" <th>m_nBidVolume</th>\n",
" <th>m_nAskPrice</th>\n",
" <th>m_nAskVolume</th>\n",
" <th>m_iABFlag</th>\n",
" <th>m_nActBidVolume</th>\n",
" <th>m_nAccActBidVolume</th>\n",
" <th>m_nActBidTurover</th>\n",
" <th>m_nAccActBidTurover</th>\n",
" <th>m_nActAskVolume</th>\n",
" <th>m_nAccActAskVolume</th>\n",
" <th>m_nActAskTurover</th>\n",
" <th>m_nAccActAskTurover</th>\n",
" <th>m_nBidOrder</th>\n",
" <th>m_nAccBidOrder</th>\n",
" <th>m_nAskOrder</th>\n",
" <th>m_nAccAskOrder</th>\n",
" <th>m_nABOrderRate</th>\n",
" <th>m_nAccABOrderRate</th>\n",
" <th>m_nMItemsVolRate</th>\n",
" <th>m_nDate</th>\n",
" <th>m_nTime</th>\n",
" <th>code_init</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>CF2211</td>\n",
" <td>13400.0</td>\n",
" <td>13550.0</td>\n",
" <td>13550.0</td>\n",
" <td>13400.0</td>\n",
" <td>13400.0</td>\n",
" <td>13645.0</td>\n",
" <td>13400.0</td>\n",
" <td>28</td>\n",
" <td>754</td>\n",
" <td>-22.0</td>\n",
" <td>4854</td>\n",
" <td>375910</td>\n",
" <td>10220470</td>\n",
" <td>13550.0</td>\n",
" <td>13580.0</td>\n",
" <td>13400.0</td>\n",
" <td>8</td>\n",
" <td>13550.0</td>\n",
" <td>20</td>\n",
" <td>1</td>\n",
" <td>22.0</td>\n",
" <td>348.0</td>\n",
" <td>294580.0</td>\n",
" <td>4718285.0</td>\n",
" <td>6.0</td>\n",
" <td>406.0</td>\n",
" <td>81330.0</td>\n",
" <td>5502185.0</td>\n",
" <td>266.0</td>\n",
" <td>40331.0</td>\n",
" <td>324.0</td>\n",
" <td>4755.0</td>\n",
" <td>0.400000</td>\n",
" <td>8.481809</td>\n",
" <td>0.0</td>\n",
" <td>2022-10-31</td>\n",
" <td>09:01:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>CF2211</td>\n",
" <td>13435.0</td>\n",
" <td>13400.0</td>\n",
" <td>13545.0</td>\n",
" <td>13400.0</td>\n",
" <td>13435.0</td>\n",
" <td>13645.0</td>\n",
" <td>13400.0</td>\n",
" <td>3</td>\n",
" <td>757</td>\n",
" <td>-1.0</td>\n",
" <td>4853</td>\n",
" <td>40665</td>\n",
" <td>10261135</td>\n",
" <td>13400.0</td>\n",
" <td>13580.0</td>\n",
" <td>13410.0</td>\n",
" <td>64</td>\n",
" <td>13550.0</td>\n",
" <td>20</td>\n",
" <td>0</td>\n",
" <td>2.0</td>\n",
" <td>350.0</td>\n",
" <td>27110.0</td>\n",
" <td>4745395.0</td>\n",
" <td>1.0</td>\n",
" <td>407.0</td>\n",
" <td>13555.0</td>\n",
" <td>5515740.0</td>\n",
" <td>741.0</td>\n",
" <td>41072.0</td>\n",
" <td>388.0</td>\n",
" <td>5143.0</td>\n",
" <td>3.200000</td>\n",
" <td>7.986000</td>\n",
" <td>0.0</td>\n",
" <td>2022-10-31</td>\n",
" <td>09:02:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>CF2211</td>\n",
" <td>13410.0</td>\n",
" <td>13435.0</td>\n",
" <td>13435.0</td>\n",
" <td>13410.0</td>\n",
" <td>13410.0</td>\n",
" <td>13645.0</td>\n",
" <td>13400.0</td>\n",
" <td>3</td>\n",
" <td>760</td>\n",
" <td>-3.0</td>\n",
" <td>4850</td>\n",
" <td>40665</td>\n",
" <td>10301800</td>\n",
" <td>13435.0</td>\n",
" <td>13580.0</td>\n",
" <td>13410.0</td>\n",
" <td>62</td>\n",
" <td>13545.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>350.0</td>\n",
" <td>0.0</td>\n",
" <td>4745395.0</td>\n",
" <td>3.0</td>\n",
" <td>410.0</td>\n",
" <td>40665.0</td>\n",
" <td>5556405.0</td>\n",
" <td>1335.0</td>\n",
" <td>42407.0</td>\n",
" <td>428.0</td>\n",
" <td>5571.0</td>\n",
" <td>62.000000</td>\n",
" <td>7.612098</td>\n",
" <td>0.0</td>\n",
" <td>2022-10-31</td>\n",
" <td>09:03:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>CF2211</td>\n",
" <td>13545.0</td>\n",
" <td>13410.0</td>\n",
" <td>13545.0</td>\n",
" <td>13410.0</td>\n",
" <td>13545.0</td>\n",
" <td>13645.0</td>\n",
" <td>13400.0</td>\n",
" <td>3</td>\n",
" <td>763</td>\n",
" <td>-1.0</td>\n",
" <td>4849</td>\n",
" <td>40665</td>\n",
" <td>10342465</td>\n",
" <td>13410.0</td>\n",
" <td>13580.0</td>\n",
" <td>13545.0</td>\n",
" <td>9</td>\n",
" <td>13550.0</td>\n",
" <td>37</td>\n",
" <td>0</td>\n",
" <td>2.0</td>\n",
" <td>352.0</td>\n",
" <td>27110.0</td>\n",
" <td>4772505.0</td>\n",
" <td>1.0</td>\n",
" <td>411.0</td>\n",
" <td>13555.0</td>\n",
" <td>5569960.0</td>\n",
" <td>580.0</td>\n",
" <td>42987.0</td>\n",
" <td>278.0</td>\n",
" <td>5849.0</td>\n",
" <td>0.243243</td>\n",
" <td>7.349461</td>\n",
" <td>0.0</td>\n",
" <td>2022-10-31</td>\n",
" <td>09:04:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>CF2211</td>\n",
" <td>13520.0</td>\n",
" <td>13545.0</td>\n",
" <td>13545.0</td>\n",
" <td>13410.0</td>\n",
" <td>13520.0</td>\n",
" <td>13645.0</td>\n",
" <td>13400.0</td>\n",
" <td>23</td>\n",
" <td>786</td>\n",
" <td>-16.0</td>\n",
" <td>4833</td>\n",
" <td>311765</td>\n",
" <td>10654230</td>\n",
" <td>13545.0</td>\n",
" <td>13580.0</td>\n",
" <td>13425.0</td>\n",
" <td>1</td>\n",
" <td>13515.0</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>8.0</td>\n",
" <td>360.0</td>\n",
" <td>108440.0</td>\n",
" <td>4880945.0</td>\n",
" <td>15.0</td>\n",
" <td>426.0</td>\n",
" <td>203325.0</td>\n",
" <td>5773285.0</td>\n",
" <td>759.0</td>\n",
" <td>43746.0</td>\n",
" <td>160.0</td>\n",
" <td>6009.0</td>\n",
" <td>0.200000</td>\n",
" <td>7.280080</td>\n",
" <td>0.0</td>\n",
" <td>2022-10-31</td>\n",
" <td>09:05:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>685</th>\n",
" <td>CF2211</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13725.0</td>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.0</td>\n",
" <td>1740</td>\n",
" <td>0</td>\n",
" <td>151360</td>\n",
" <td>13810.0</td>\n",
" <td>13600.0</td>\n",
" <td>13710.0</td>\n",
" <td>10</td>\n",
" <td>13800.0</td>\n",
" <td>40</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>11.0</td>\n",
" <td>0.0</td>\n",
" <td>151360.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>50.0</td>\n",
" <td>15596.0</td>\n",
" <td>200.0</td>\n",
" <td>13666.0</td>\n",
" <td>0.250000</td>\n",
" <td>1.141226</td>\n",
" <td>0.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>22:56:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>686</th>\n",
" <td>CF2211</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13725.0</td>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.0</td>\n",
" <td>1740</td>\n",
" <td>0</td>\n",
" <td>151360</td>\n",
" <td>13810.0</td>\n",
" <td>13600.0</td>\n",
" <td>13725.0</td>\n",
" <td>10</td>\n",
" <td>13800.0</td>\n",
" <td>40</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>11.0</td>\n",
" <td>0.0</td>\n",
" <td>151360.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>52.0</td>\n",
" <td>15648.0</td>\n",
" <td>280.0</td>\n",
" <td>13946.0</td>\n",
" <td>0.250000</td>\n",
" <td>1.122042</td>\n",
" <td>0.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>22:57:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>687</th>\n",
" <td>CF2211</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13725.0</td>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.0</td>\n",
" <td>1740</td>\n",
" <td>0</td>\n",
" <td>151360</td>\n",
" <td>13810.0</td>\n",
" <td>13600.0</td>\n",
" <td>13725.0</td>\n",
" <td>10</td>\n",
" <td>13800.0</td>\n",
" <td>40</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>11.0</td>\n",
" <td>0.0</td>\n",
" <td>151360.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>20.0</td>\n",
" <td>15668.0</td>\n",
" <td>80.0</td>\n",
" <td>14026.0</td>\n",
" <td>0.250000</td>\n",
" <td>1.117068</td>\n",
" <td>0.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>22:58:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>688</th>\n",
" <td>CF2211</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13725.0</td>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.0</td>\n",
" <td>1740</td>\n",
" <td>0</td>\n",
" <td>151360</td>\n",
" <td>13810.0</td>\n",
" <td>13600.0</td>\n",
" <td>13725.0</td>\n",
" <td>10</td>\n",
" <td>13800.0</td>\n",
" <td>40</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>11.0</td>\n",
" <td>0.0</td>\n",
" <td>151360.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>20.0</td>\n",
" <td>15688.0</td>\n",
" <td>80.0</td>\n",
" <td>14106.0</td>\n",
" <td>0.250000</td>\n",
" <td>1.112151</td>\n",
" <td>0.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>22:59:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" <tr>\n",
" <th>689</th>\n",
" <td>CF2211</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13810.0</td>\n",
" <td>13725.0</td>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>0.0</td>\n",
" <td>1740</td>\n",
" <td>0</td>\n",
" <td>151360</td>\n",
" <td>13810.0</td>\n",
" <td>13600.0</td>\n",
" <td>13740.0</td>\n",
" <td>10</td>\n",
" <td>13800.0</td>\n",
" <td>40</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>11.0</td>\n",
" <td>0.0</td>\n",
" <td>151360.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>84.0</td>\n",
" <td>15772.0</td>\n",
" <td>360.0</td>\n",
" <td>14466.0</td>\n",
" <td>0.250000</td>\n",
" <td>1.090281</td>\n",
" <td>0.0</td>\n",
" <td>2022-11-01</td>\n",
" <td>23:00:00</td>\n",
" <td>CF</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>690 rows × 39 columns</p>\n",
"</div>"
],
"text/plain": [
" code m_nPrice m_nOpen m_nHigh m_nLow m_nClose m_nAccHigh \\\n",
"0 CF2211 13400.0 13550.0 13550.0 13400.0 13400.0 13645.0 \n",
"1 CF2211 13435.0 13400.0 13545.0 13400.0 13435.0 13645.0 \n",
"2 CF2211 13410.0 13435.0 13435.0 13410.0 13410.0 13645.0 \n",
"3 CF2211 13545.0 13410.0 13545.0 13410.0 13545.0 13645.0 \n",
"4 CF2211 13520.0 13545.0 13545.0 13410.0 13520.0 13645.0 \n",
".. ... ... ... ... ... ... ... \n",
"685 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n",
"686 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n",
"687 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n",
"688 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n",
"689 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n",
"\n",
" m_nAccLow m_iVolume m_iAccVolume m_nMatchItems m_nAccMatchItems \\\n",
"0 13400.0 28 754 -22.0 4854 \n",
"1 13400.0 3 757 -1.0 4853 \n",
"2 13400.0 3 760 -3.0 4850 \n",
"3 13400.0 3 763 -1.0 4849 \n",
"4 13400.0 23 786 -16.0 4833 \n",
".. ... ... ... ... ... \n",
"685 13725.0 0 11 0.0 1740 \n",
"686 13725.0 0 11 0.0 1740 \n",
"687 13725.0 0 11 0.0 1740 \n",
"688 13725.0 0 11 0.0 1740 \n",
"689 13725.0 0 11 0.0 1740 \n",
"\n",
" m_iTurover m_iAccTurover m_nPreClose m_nAccPreClose m_nBidPrice \\\n",
"0 375910 10220470 13550.0 13580.0 13400.0 \n",
"1 40665 10261135 13400.0 13580.0 13410.0 \n",
"2 40665 10301800 13435.0 13580.0 13410.0 \n",
"3 40665 10342465 13410.0 13580.0 13545.0 \n",
"4 311765 10654230 13545.0 13580.0 13425.0 \n",
".. ... ... ... ... ... \n",
"685 0 151360 13810.0 13600.0 13710.0 \n",
"686 0 151360 13810.0 13600.0 13725.0 \n",
"687 0 151360 13810.0 13600.0 13725.0 \n",
"688 0 151360 13810.0 13600.0 13725.0 \n",
"689 0 151360 13810.0 13600.0 13740.0 \n",
"\n",
" m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag m_nActBidVolume \\\n",
"0 8 13550.0 20 1 22.0 \n",
"1 64 13550.0 20 0 2.0 \n",
"2 62 13545.0 1 0 0.0 \n",
"3 9 13550.0 37 0 2.0 \n",
"4 1 13515.0 5 0 8.0 \n",
".. ... ... ... ... ... \n",
"685 10 13800.0 40 0 0.0 \n",
"686 10 13800.0 40 0 0.0 \n",
"687 10 13800.0 40 0 0.0 \n",
"688 10 13800.0 40 0 0.0 \n",
"689 10 13800.0 40 0 0.0 \n",
"\n",
" m_nAccActBidVolume m_nActBidTurover m_nAccActBidTurover \\\n",
"0 348.0 294580.0 4718285.0 \n",
"1 350.0 27110.0 4745395.0 \n",
"2 350.0 0.0 4745395.0 \n",
"3 352.0 27110.0 4772505.0 \n",
"4 360.0 108440.0 4880945.0 \n",
".. ... ... ... \n",
"685 11.0 0.0 151360.0 \n",
"686 11.0 0.0 151360.0 \n",
"687 11.0 0.0 151360.0 \n",
"688 11.0 0.0 151360.0 \n",
"689 11.0 0.0 151360.0 \n",
"\n",
" m_nActAskVolume m_nAccActAskVolume m_nActAskTurover \\\n",
"0 6.0 406.0 81330.0 \n",
"1 1.0 407.0 13555.0 \n",
"2 3.0 410.0 40665.0 \n",
"3 1.0 411.0 13555.0 \n",
"4 15.0 426.0 203325.0 \n",
".. ... ... ... \n",
"685 0.0 0.0 0.0 \n",
"686 0.0 0.0 0.0 \n",
"687 0.0 0.0 0.0 \n",
"688 0.0 0.0 0.0 \n",
"689 0.0 0.0 0.0 \n",
"\n",
" m_nAccActAskTurover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n",
"0 5502185.0 266.0 40331.0 324.0 \n",
"1 5515740.0 741.0 41072.0 388.0 \n",
"2 5556405.0 1335.0 42407.0 428.0 \n",
"3 5569960.0 580.0 42987.0 278.0 \n",
"4 5773285.0 759.0 43746.0 160.0 \n",
".. ... ... ... ... \n",
"685 0.0 50.0 15596.0 200.0 \n",
"686 0.0 52.0 15648.0 280.0 \n",
"687 0.0 20.0 15668.0 80.0 \n",
"688 0.0 20.0 15688.0 80.0 \n",
"689 0.0 84.0 15772.0 360.0 \n",
"\n",
" m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n",
"0 4755.0 0.400000 8.481809 0.0 \n",
"1 5143.0 3.200000 7.986000 0.0 \n",
"2 5571.0 62.000000 7.612098 0.0 \n",
"3 5849.0 0.243243 7.349461 0.0 \n",
"4 6009.0 0.200000 7.280080 0.0 \n",
".. ... ... ... ... \n",
"685 13666.0 0.250000 1.141226 0.0 \n",
"686 13946.0 0.250000 1.122042 0.0 \n",
"687 14026.0 0.250000 1.117068 0.0 \n",
"688 14106.0 0.250000 1.112151 0.0 \n",
"689 14466.0 0.250000 1.090281 0.0 \n",
"\n",
" m_nDate m_nTime code_init \n",
"0 2022-10-31 09:01:00 CF \n",
"1 2022-10-31 09:02:00 CF \n",
"2 2022-10-31 09:03:00 CF \n",
"3 2022-10-31 09:04:00 CF \n",
"4 2022-10-31 09:05:00 CF \n",
".. ... ... ... \n",
"685 2022-11-01 22:56:00 CF \n",
"686 2022-11-01 22:57:00 CF \n",
"687 2022-11-01 22:58:00 CF \n",
"688 2022-11-01 22:59:00 CF \n",
"689 2022-11-01 23:00:00 CF \n",
"\n",
"[690 rows x 39 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from usrc.DDBfm import DDBfm\n",
"ddb=DDBfm('dev')\n",
"\n",
"db = ddb.create_ddb_database(ddb.ddb_hft_path,ddb.ddb_hft_mink_dbname)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"ddb.add_new_hft_table(db,ddb.ddf_hft_mink_tbname,df)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"ddb.append_hft_table(ddb.ddb_hft_path,ddb.ddf_hft_mink_tbname,df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ddb.ddb_sess.run(\"\"\"\n",
"# {table_name} = table({capacity}:0, {col_names}, [{col_types}]);\n",
"# \"\"\".format(\n",
"# table_name = ddb.ddf_hft_tick_tbname,\n",
"# capacity = 5000 * 1000,\n",
"# col_names = '`code`m_nDate',\n",
"# col_types = \"SYMBOL, DATE\"\n",
"# ))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.9 64-bit",
"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.9.6"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}