Commit c66e3552 authored by Dr.李's avatar Dr.李

added wind category

parent 686b4f42
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "51382765-24b4-4e5e-a118-077b276e0774",
"metadata": {},
"outputs": [],
......@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 11,
"id": "47939edc-07d2-4c8e-b061-187806e124ea",
"metadata": {},
"outputs": [],
......@@ -33,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 12,
"id": "9a596482-dd98-49dc-b717-c17177f2cd64",
"metadata": {},
"outputs": [],
......@@ -46,19 +46,18 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 15,
"id": "5ccf2dc7-fea9-4d52-b15d-e8ff55fac3dc",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"security_info.loc[(security_info.CLASSCODE.str.startswith(\"220502\")), \"货币型(子类)\"] = \"场内货币型基金\"\n",
"security_info.loc[(~security_info.CLASSCODE.str.startswith(\"220502\")), \"货币型(子类)\"] = \"场外货币型基金\""
"security_info[\"货币型(子类)\"] = \"货币型基金\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 16,
"id": "9d34507e-9efd-479a-8b25-a095de5a552c",
"metadata": {},
"outputs": [
......@@ -98,18 +97,11 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>场内货币型基金</th>\n",
" <td>41</td>\n",
" <td>41</td>\n",
" <td>41</td>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>场外货币型基金</th>\n",
" <td>622</td>\n",
" <td>622</td>\n",
" <td>622</td>\n",
" <td>622</td>\n",
" <th>货币型基金</th>\n",
" <td>711</td>\n",
" <td>711</td>\n",
" <td>711</td>\n",
" <td>711</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
......@@ -118,11 +110,10 @@
"text/plain": [
" SECURITYID BEGINDATE ENDDATE CLASSCODE\n",
"货币型(子类) \n",
"场内货币型基金 41 41 41 41\n",
"场外货币型基金 622 622 622 622"
"货币型基金 711 711 711 711"
]
},
"execution_count": 10,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "76b46662-651d-4bcd-b554-f116051cf297",
"metadata": {},
"outputs": [],
......@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"id": "f5d4b805-d5a3-4b4c-8429-7044e9bef831",
"metadata": {},
"outputs": [],
......@@ -33,17 +33,17 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 7,
"id": "72d3f785-aee7-44d9-a393-3abbdb4d60a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"40"
"84"
]
},
"execution_count": 22,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
......@@ -51,14 +51,14 @@
"source": [
"# 获取所有目标基金(清算结束日期晚于当前日)\n",
"\n",
"security_info = fd_alive_funds(today, [2204, 22020803, 22021401])\n",
"security_info = fd_alive_funds(today, 2204)\n",
"security_ids = security_info.SECURITYID.unique().tolist()\n",
"len(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 8,
"id": "52607b95-9d62-4f68-8256-984827dd0bea",
"metadata": {},
"outputs": [],
......@@ -68,21 +68,21 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 9,
"id": "60fe66ee-a8d3-4a33-8c5a-555f68d9758c",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"df.loc[(~df.CLASSCODE.str.startswith(\"220409\")) & (df.CLASSCODE.str.startswith(\"2204\")), \"另类投资型(子类)\"] = \"商品型基金\"\n",
"df.loc[df.CLASSCODE.str.startswith(\"2202\"), \"另类投资型(子类)\"] = \"量化对冲基金\"\n",
"df.loc[df.CLASSCODE == \"220401\", \"另类投资型(子类)\"] = \"商品型基金\"\n",
"df.loc[df.CLASSCODE == \"220402\", \"另类投资型(子类)\"] = \"量化对冲基金\"\n",
"df.loc[pd.isnull(df[\"另类投资型(子类)\"]), \"另类投资型(子类)\"] = \"其他另类基金\"\n",
"# df.loc[(df[\"L3NAME\"] == \"对冲策略基金\"), \"另类投资型(子类)\"] = "
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 10,
"id": "1bb62bc7-2515-415a-8eec-087d2d1787b6",
"metadata": {},
"outputs": [
......@@ -122,25 +122,18 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>其他另类基金</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>商品型基金</th>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>量化对冲基金</th>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>36</td>\n",
" <td>36</td>\n",
" <td>36</td>\n",
" <td>36</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
......@@ -149,12 +142,11 @@
"text/plain": [
" SECURITYID BEGINDATE ENDDATE CLASSCODE\n",
"另类投资型(子类) \n",
"其他另类基金 1 1 1 1\n",
"商品型基金 14 14 14 14\n",
"量化对冲基金 25 25 25 25"
"商品型基金 48 48 48 48\n",
"量化对冲基金 36 36 36 36"
]
},
"execution_count": 25,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "de082674-0285-4894-905a-52da1ab1727d",
"metadata": {},
"outputs": [],
......@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "11d2dbfe-b1c7-41b1-8df3-b6f40b096f83",
"metadata": {},
"outputs": [],
......@@ -33,17 +33,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "004a8f9f-4011-48c6-a5dd-327cce42de51",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"13"
"351"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
......@@ -58,41 +58,113 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "fc897e0e-46f1-48a2-be9a-6381086c94bf",
"metadata": {},
"outputs": [],
"source": [
"df = security_info"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c3e8441c-d3c5-48f7-aa98-0b3aa7794767",
"metadata": {},
"outputs": [],
"source": [
"df.loc[df.CLASSCODE.str.startswith(\"221001\"), \"FOF型(子类)\"] = \"偏股混合型FOF基金\"\n",
"df.loc[df.CLASSCODE.str.startswith(\"221002\"), \"FOF型(子类)\"] = \"平衡混合型FOF基金\"\n",
"df.loc[df.CLASSCODE.str.startswith(\"221003\"), \"FOF型(子类)\"] = \"偏债混合型FOF基金\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2f43d675-50a9-4eb7-ae94-13cb235d93d7",
"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>SECURITYID</th>\n",
" <th>BEGINDATE</th>\n",
" <th>ENDDATE</th>\n",
" <th>CLASSCODE</th>\n",
" </tr>\n",
" <tr>\n",
" <th>FOF型(子类)</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>偏债混合型FOF基金</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>偏股混合型FOF基金</th>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>平衡混合型FOF基金</th>\n",
" <td>338</td>\n",
" <td>338</td>\n",
" <td>338</td>\n",
" <td>338</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"['1030010441',\n",
" '1030010443',\n",
" '1030010444',\n",
" '1030010446',\n",
" '1030010447',\n",
" '1030010449',\n",
" '1030010450',\n",
" '1030010451',\n",
" '1030010459',\n",
" '1030010460',\n",
" '1030011412',\n",
" '1030011413',\n",
" '1030011474']"
" SECURITYID BEGINDATE ENDDATE CLASSCODE\n",
"FOF型(子类) \n",
"偏债混合型FOF基金 4 4 4 4\n",
"偏股混合型FOF基金 9 9 9 9\n",
"平衡混合型FOF基金 338 338 338 338"
]
},
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"security_ids"
"df.groupby(\"FOF型(子类)\").count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3e8441c-d3c5-48f7-aa98-0b3aa7794767",
"id": "2234dfb1-5b08-44d4-91bf-e52a43bf4076",
"metadata": {},
"outputs": [],
"source": []
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,7 @@ import pymssql
import sqlalchemy as sa
import numpy as np
import pandas as pd
from pathlib import Path
MSSQL_CONN = "mssql+pymssql://readdnds:reader%402021@121.37.138.1:14331/dnds"
......@@ -90,39 +91,48 @@ def nearest_report_date(date, freq="Q", method="forward"):
def fd_alive_funds(trade_dt, class_code=None):
# if class_code:
# if isinstance(class_code, str) or isinstance(class_code, int):
# condition = f" CLASSCODE like '{class_code}%' AND "
# else:
# condition = []
# for c in class_code:
# condition.append(f" CLASSCODE like '{c}%' ")
# condition = "OR".join(condition)
# condition = "(" + condition + ") AND"
# query = f"""
# select SECODE as SECURITYID, BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
# WHERE
# ISVALID = 1 AND
# {condition}
# TYPESTYLE = '22' AND
# BEGINDATE <= '{trade_dt}' AND
# (ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
# ORDER BY SECODE;
# """
# else:
# query = f"""
# select SECODE as SECURITYID,BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
# WHERE
# ISVALID = 1 AND
# BEGINDATE <= '{trade_dt}' AND
# TYPESTYLE = '22' AND
# (ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
# ORDER BY SECODE;
# """
# return read_sql(query)
df = pd.read_csv(str(Path(__file__).parents[0] / "wind_table.csv"))
df["SECODE"] = df["SECODE"].astype(str)
df["CLASSCODE"] = df["CLASSCODE"].astype(str)
if class_code:
if isinstance(class_code, str) or isinstance(class_code, int):
condition = f" CLASSCODE like '{class_code}%' AND "
else:
condition = []
for c in class_code:
condition.append(f" CLASSCODE like '{c}%' ")
condition = "OR".join(condition)
condition = "(" + condition + ") AND"
query = f"""
select SECODE as SECURITYID, BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
WHERE
ISVALID = 1 AND
{condition}
TYPESTYLE = '22' AND
BEGINDATE <= '{trade_dt}' AND
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
ORDER BY SECODE;
"""
else:
query = f"""
select SECODE as SECURITYID,BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
WHERE
ISVALID = 1 AND
BEGINDATE <= '{trade_dt}' AND
TYPESTYLE = '22' AND
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
ORDER BY SECODE;
"""
return read_sql(query)
df = df[df.CLASSCODE.str.contains(str(class_code))]
df.rename(columns={"SECODE": "SECURITYID"}, inplace=True)
df = df.sort_values("CLASSCODE").groupby("SECURITYID", as_index=False).last()
return df
def fd_basicinfo(security_ids=None, trade_dt=None):
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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