Commit 686b4f42 authored by Dr.李's avatar Dr.李

addded 选股能力

parent df441253
......@@ -32,26 +32,17 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 3,
"id": "11f4ac54-8a1e-4a23-abb0-785416ff45ed",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "closing parenthesis ']' does not match opening parenthesis '(' (Temp/ipykernel_52620/96406359.py, line 6)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"C:\\Users\\wegam\\AppData\\Local\\Temp/ipykernel_52620/96406359.py\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m asset_portfolios = asset_portfolios[asset_portfolios.REPORTDATE.isin([last_report_date.replace(\"-\", \"\"), report_date.replace(\"-\", \"\")]]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m closing parenthesis ']' does not match opening parenthesis '('\n"
]
}
],
"outputs": [],
"source": [
"def create_timing_analysis(security_ids, reprot_date, benchmark=\"2070000191\"):\n",
" last_report_date = nearest_report_date(advanceDate(report_date, \"-1d\").strftime(\"%Y%m%d\"), freq=\"Q\", method=\"backward\")\n",
"\n",
" index_return = index_rtn(benchmark, last_report_date, report_date)[\"rtn\"].at[0]\n",
" asset_portfolios = fd_assetportfolio(security_ids, last_report_date, report_date).sort_values(\"REPORTDATE\").fillna(0)\n",
" asset_portfolios = asset_portfolios[asset_portfolios.REPORTDATE.isin([last_report_date.replace(\"-\", \"\"), report_date.replace(\"-\", \"\")]]\n",
" asset_portfolios = asset_portfolios[asset_portfolios.REPORTDATE.isin([last_report_date.replace(\"-\", \"\"), report_date.replace(\"-\", \"\")])]\n",
"\n",
" periods_count = asset_portfolios.groupby(\"SECURITYID\")[\"REPORTDATE\"].count()\n",
" periods_count = periods_count[periods_count >= 2]\n",
......@@ -76,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"id": "7995d877-d609-4cca-97aa-e7acd73850d0",
"metadata": {},
"outputs": [],
......@@ -87,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"id": "4f833e84-1224-47cb-a811-a6d18e7077ff",
"metadata": {},
"outputs": [],
......@@ -109,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"id": "ed8f853b-0ac7-49eb-9840-422f2ccfd23e",
"metadata": {},
"outputs": [
......@@ -219,68 +210,68 @@
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13465</th>\n",
" <td>2030019986</td>\n",
" <th>13362</th>\n",
" <td>2030019067</td>\n",
" <td>0.028536</td>\n",
" <td>20211203</td>\n",
" <td>20210930</td>\n",
" <td>20211231</td>\n",
" <td>2.20</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>False</td>\n",
" <td>-0.000628</td>\n",
" <td>98.91</td>\n",
" <td>96.165857</td>\n",
" <td>True</td>\n",
" <td>0.027441</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13466</th>\n",
" <td>2030020009</td>\n",
" <th>13363</th>\n",
" <td>2030019069</td>\n",
" <td>0.028536</td>\n",
" <td>20211222</td>\n",
" <td>20210930</td>\n",
" <td>20211231</td>\n",
" <td>1.02</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>False</td>\n",
" <td>-0.000291</td>\n",
" <td>97.46</td>\n",
" <td>94.756086</td>\n",
" <td>True</td>\n",
" <td>0.027039</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13467</th>\n",
" <td>2030020055</td>\n",
" <th>13364</th>\n",
" <td>2030019083</td>\n",
" <td>0.028536</td>\n",
" <td>20211230</td>\n",
" <td>20210930</td>\n",
" <td>20211231</td>\n",
" <td>79.39</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>False</td>\n",
" <td>-0.022654</td>\n",
" <td>97.62</td>\n",
" <td>94.911647</td>\n",
" <td>True</td>\n",
" <td>0.027084</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13468</th>\n",
" <td>2030020163</td>\n",
" <th>13365</th>\n",
" <td>2030019096</td>\n",
" <td>0.028536</td>\n",
" <td>20211216</td>\n",
" <td>20210930</td>\n",
" <td>20211231</td>\n",
" <td>13.01</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>False</td>\n",
" <td>-0.003712</td>\n",
" <td>98.72</td>\n",
" <td>95.981129</td>\n",
" <td>True</td>\n",
" <td>0.027389</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13469</th>\n",
" <td>2030020298</td>\n",
" <th>13366</th>\n",
" <td>2030019121</td>\n",
" <td>0.028536</td>\n",
" <td>20211230</td>\n",
" <td>20210930</td>\n",
" <td>20211231</td>\n",
" <td>18.13</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>False</td>\n",
" <td>-0.005173</td>\n",
" <td>96.19</td>\n",
" <td>93.521321</td>\n",
" <td>True</td>\n",
" <td>0.026687</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>13470 rows × 9 columns</p>\n",
"<p>13367 rows × 9 columns</p>\n",
"</div>"
],
"text/plain": [
......@@ -291,11 +282,11 @@
"3 1030000006 0.028536 20210930 20211231 70.60 67.78 \n",
"4 1030000007 0.028536 20210930 20211231 89.93 91.63 \n",
"... ... ... ... ... ... ... \n",
"13465 2030019986 0.028536 20211203 20211231 2.20 0.00 \n",
"13466 2030020009 0.028536 20211222 20211231 1.02 0.00 \n",
"13467 2030020055 0.028536 20211230 20211231 79.39 0.00 \n",
"13468 2030020163 0.028536 20211216 20211231 13.01 0.00 \n",
"13469 2030020298 0.028536 20211230 20211231 18.13 0.00 \n",
"13362 2030019067 0.028536 20210930 20211231 0.00 98.91 \n",
"13363 2030019069 0.028536 20210930 20211231 0.00 97.46 \n",
"13364 2030019083 0.028536 20210930 20211231 0.00 97.62 \n",
"13365 2030019096 0.028536 20210930 20211231 0.00 98.72 \n",
"13366 2030019121 0.028536 20210930 20211231 0.00 96.19 \n",
"\n",
" adjusted_equity_end is_win timing_rtn \n",
"0 89.253116 False -0.000487 \n",
......@@ -304,16 +295,16 @@
"3 65.899523 False -0.001341 \n",
"4 89.087833 False -0.000240 \n",
"... ... ... ... \n",
"13465 0.000000 False -0.000628 \n",
"13466 0.000000 False -0.000291 \n",
"13467 0.000000 False -0.022654 \n",
"13468 0.000000 False -0.003712 \n",
"13469 0.000000 False -0.005173 \n",
"13362 96.165857 True 0.027441 \n",
"13363 94.756086 True 0.027039 \n",
"13364 94.911647 True 0.027084 \n",
"13365 95.981129 True 0.027389 \n",
"13366 93.521321 True 0.026687 \n",
"\n",
"[13470 rows x 9 columns]"
"[13367 rows x 9 columns]"
]
},
"execution_count": 12,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
......
This diff is collapsed.
security_code,index_name,end_date,industry_code,entry_date
2070008337,申万农林牧渔指数,19000101,110000,2021-12-10 00:00:00
2070008339,申万基础化工指数,19000101,220000,2021-12-10 00:00:00
2070008340,申万钢铁指数,19000101,230000,2015-04-21 00:00:00
2070008341,申万有色金属指数,19000101,240000,2021-12-10 00:00:00
2070008344,申万电子指数,19000101,270000,2015-04-21 00:00:00
2070008347,申万家用电器指数,19000101,330000,2021-12-10 00:00:00
2070008348,申万食品饮料指数,19000101,340000,2021-12-10 00:00:00
2070008349,申万纺织服饰指数,19000101,350000,2021-12-10 00:00:00
2070008350,申万轻工制造指数,19000101,360000,2021-12-10 00:00:00
2070008351,申万医药生物指数,19000101,370000,2021-12-10 00:00:00
2070008352,申万公用事业指数,19000101,410000,2021-12-10 00:00:00
2070008353,申万交通运输指数,19000101,420000,2021-12-10 00:00:00
2070008354,申万房地产指数,19000101,430000,2021-12-10 00:00:00
2070008356,申万商贸零售指数,19000101,450000,2021-12-10 00:00:00
2070008357,申万社会服务指数,19000101,460000,2021-12-10 00:00:00
2070008359,申万综合指数,19000101,510000,2021-12-10 00:00:00
2070008716,申万机械设备指数,19000101,640000,2014-09-30 00:00:00
2070008717,申万国防军工指数,19000101,650000,2014-09-30 00:00:00
2070008718,申万汽车指数,19000101,280000,2014-09-30 00:00:00
2070008719,申万计算机指数,19000101,710000,2014-09-30 00:00:00
2070008720,申万通信指数,19000101,730000,2014-09-30 00:00:00
2070008721,申万银行指数,19000101,480000,2014-09-30 00:00:00
2070008722,申万非银金融指数,19000101,490000,2014-09-30 00:00:00
2070008787,申万建筑材料指数,19000101,610000,2014-09-30 00:00:00
2070008788,申万建筑装饰指数,19000101,620000,2014-09-30 00:00:00
2070008789,申万电力设备指数,19000101,630000,2021-12-10 00:00:00
2070008790,申万传媒指数,19000101,720000,2014-09-30 00:00:00
2070020439,申万煤炭指数,19000101,740000,2022-03-10 00:00:00
2070020440,申万石油石化指数,19000101,750000,2022-03-10 00:00:00
2070020441,申万环保指数,19000101,760000,2022-03-10 00:00:00
2070020442,申万美容护理指数,19000101,770000,2022-03-10 00:00:00
......@@ -285,7 +285,7 @@ def fd_skdetail(security_ids, trade_dt):
query = f"""
SELECT SECODE as pid, PUBLISHDATE, SKCODE as security_code, SKNAME, HOLDMKTCAP, HOLDAMT, NAVRTO FROM TQ_FD_SKDETAIL
WHERE
ENDDATE = '{trade_dt}' AND
ENDDATE = '{_to_yyyymmdd(trade_dt)}' AND
ISVALID = 1 AND
SECODE in ({p_id_strs})
"""
......@@ -435,7 +435,7 @@ def stk_return(start_date, end_date, security_ids=None):
sec_id_strs = _join_ids(security_ids)
if sec_id_strs:
query = f"""
SELECT security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(log(1.0 + change_pct / 100.))) AS chg_pct FROM stk_daily_price_pro
SELECT security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(ln(1.0 + change_pct / 100.))) - 1.0 AS chg_pct FROM stk_daily_price_pro
WHERE
trade_date >= '{_to_yyyy_mm_dd(start_date)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
......@@ -445,7 +445,7 @@ def stk_return(start_date, end_date, security_ids=None):
"""
else:
query = f"""
SELECT security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(log(1.0 + change_pct / 100.))) - 1.0 AS chg_pct FROM stk_daily_price_pro
SELECT security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(ln(1.0 + change_pct / 100.))) - 1.0 AS chg_pct FROM stk_daily_price_pro
WHERE
trade_date >= '{_to_yyyy_mm_dd(start_date)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment