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

added something about risk attribution

parent 8b7a000b
...@@ -4,3 +4,6 @@ __pycache__ ...@@ -4,3 +4,6 @@ __pycache__
.virtual_documents .virtual_documents
*.xlsx *.xlsx
.idea .idea
*.docx
*.zip
*.pdf
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8b4b7eaa-4778-4adb-bf1c-622794cd5027",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../\")\n",
"from fof.utility import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b547e094-4e2a-4ce8-b6c3-16b84f7d7d43",
"metadata": {},
"outputs": [],
"source": [
"df = fd_skdetail(\"1030000006\", trade_dt=\"20210630\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5f3f9f46-6b93-4e1d-b941-3df4d0974662",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3384590848.7"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"total_value = df.HOLDMKTCAP.sum()\n",
"total_value"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "04f7ce63-8c83-4526-8893-2232eef6e097",
"metadata": {},
"outputs": [],
"source": [
"df[\"pct\"] = df.HOLDMKTCAP / total_value"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "37d007b9-c688-4f3c-8050-9f2c4bdff305",
"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>SKCODE</th>\n",
" <th>SKNAME</th>\n",
" <th>HOLDMKTCAP</th>\n",
" <th>HOLDAMT</th>\n",
" <th>NAVRTO</th>\n",
" <th>pct</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1030000006</td>\n",
" <td>2010000438</td>\n",
" <td>贵州茅台</td>\n",
" <td>1.363078e+08</td>\n",
" <td>66275.0</td>\n",
" <td>3.08</td>\n",
" <td>0.040273</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>1030000006</td>\n",
" <td>2010034058</td>\n",
" <td>中红医疗</td>\n",
" <td>5.432439e+04</td>\n",
" <td>601.0</td>\n",
" <td>NaN</td>\n",
" <td>0.000016</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>1030000006</td>\n",
" <td>2010034057</td>\n",
" <td>苏文电能</td>\n",
" <td>1.435693e+04</td>\n",
" <td>317.0</td>\n",
" <td>NaN</td>\n",
" <td>0.000004</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>1030000006</td>\n",
" <td>2010034045</td>\n",
" <td>华利集团</td>\n",
" <td>8.093750e+04</td>\n",
" <td>925.0</td>\n",
" <td>NaN</td>\n",
" <td>0.000024</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>1030000006</td>\n",
" <td>2010034043</td>\n",
" <td>商络电子</td>\n",
" <td>6.410760e+03</td>\n",
" <td>492.0</td>\n",
" <td>NaN</td>\n",
" <td>0.000002</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",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>1030000006</td>\n",
" <td>2010009830</td>\n",
" <td>益丰药房</td>\n",
" <td>4.356965e+07</td>\n",
" <td>776781.0</td>\n",
" <td>0.98</td>\n",
" <td>0.012873</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>1030000006</td>\n",
" <td>2010009541</td>\n",
" <td>芒果超媒</td>\n",
" <td>7.366405e+07</td>\n",
" <td>1073820.0</td>\n",
" <td>1.66</td>\n",
" <td>0.021765</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>1030000006</td>\n",
" <td>2010008723</td>\n",
" <td>九洲药业</td>\n",
" <td>1.447684e+07</td>\n",
" <td>298000.0</td>\n",
" <td>0.33</td>\n",
" <td>0.004277</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>1030000006</td>\n",
" <td>2010029637</td>\n",
" <td>科沃斯</td>\n",
" <td>8.508479e+07</td>\n",
" <td>373048.0</td>\n",
" <td>1.92</td>\n",
" <td>0.025139</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>1030000006</td>\n",
" <td>2010034373</td>\n",
" <td>英科再生</td>\n",
" <td>5.421924e+04</td>\n",
" <td>2469.0</td>\n",
" <td>NaN</td>\n",
" <td>0.000016</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>118 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" SECURITYID SKCODE SKNAME HOLDMKTCAP HOLDAMT NAVRTO pct\n",
"0 1030000006 2010000438 贵州茅台 1.363078e+08 66275.0 3.08 0.040273\n",
"85 1030000006 2010034058 中红医疗 5.432439e+04 601.0 NaN 0.000016\n",
"84 1030000006 2010034057 苏文电能 1.435693e+04 317.0 NaN 0.000004\n",
"83 1030000006 2010034045 华利集团 8.093750e+04 925.0 NaN 0.000024\n",
"82 1030000006 2010034043 商络电子 6.410760e+03 492.0 NaN 0.000002\n",
".. ... ... ... ... ... ... ...\n",
"33 1030000006 2010009830 益丰药房 4.356965e+07 776781.0 0.98 0.012873\n",
"32 1030000006 2010009541 芒果超媒 7.366405e+07 1073820.0 1.66 0.021765\n",
"31 1030000006 2010008723 九洲药业 1.447684e+07 298000.0 0.33 0.004277\n",
"43 1030000006 2010029637 科沃斯 8.508479e+07 373048.0 1.92 0.025139\n",
"117 1030000006 2010034373 英科再生 5.421924e+04 2469.0 NaN 0.000016\n",
"\n",
"[118 rows x 7 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "15ce5cca-312b-4ef5-8178-580ec9c440da",
"metadata": {},
"outputs": [],
"source": [
"ddf = risk_exposure(df.SKCODE, \"20210630\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a0e18d45-c6c7-45e5-bc83-9ae80575125e",
"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>trade_date</th>\n",
" <th>security_code</th>\n",
" <th>secShortName</th>\n",
" <th>symbol</th>\n",
" <th>SRISK</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000045</td>\n",
" <td>海信视像</td>\n",
" <td>600060.XSHG</td>\n",
" <td>43.597</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000121</td>\n",
" <td>中青旅</td>\n",
" <td>600138.XSHG</td>\n",
" <td>20.325</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000171</td>\n",
" <td>复星医药</td>\n",
" <td>600196.XSHG</td>\n",
" <td>49.067</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000377</td>\n",
" <td>片仔癀</td>\n",
" <td>600436.XSHG</td>\n",
" <td>36.564</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000438</td>\n",
" <td>贵州茅台</td>\n",
" <td>600519.XSHG</td>\n",
" <td>24.513</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010034304</td>\n",
" <td>C利和兴</td>\n",
" <td>301013.XSHE</td>\n",
" <td>40.330</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010034305</td>\n",
" <td>C嘉益</td>\n",
" <td>301004.XSHE</td>\n",
" <td>42.886</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010034317</td>\n",
" <td>税友股份</td>\n",
" <td>603171.XSHG</td>\n",
" <td>40.035</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010034318</td>\n",
" <td>杭州热电</td>\n",
" <td>605011.XSHG</td>\n",
" <td>35.420</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010034324</td>\n",
" <td>C百洋</td>\n",
" <td>301015.XSHE</td>\n",
" <td>39.727</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>109 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" trade_date security_code secShortName symbol SRISK\n",
"0 2021-06-30 2010000045 海信视像 600060.XSHG 43.597\n",
"1 2021-06-30 2010000121 中青旅 600138.XSHG 20.325\n",
"2 2021-06-30 2010000171 复星医药 600196.XSHG 49.067\n",
"3 2021-06-30 2010000377 片仔癀 600436.XSHG 36.564\n",
"4 2021-06-30 2010000438 贵州茅台 600519.XSHG 24.513\n",
".. ... ... ... ... ...\n",
"104 2021-06-30 2010034304 C利和兴 301013.XSHE 40.330\n",
"105 2021-06-30 2010034305 C嘉益 301004.XSHE 42.886\n",
"106 2021-06-30 2010034317 税友股份 603171.XSHG 40.035\n",
"107 2021-06-30 2010034318 杭州热电 605011.XSHG 35.420\n",
"108 2021-06-30 2010034324 C百洋 301015.XSHE 39.727\n",
"\n",
"[109 rows x 5 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"special_risk(df.SKCODE, \"20210630\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90957b2b-fc4c-4e7f-b50b-b2189573f1d9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "a1fbf6c8-e22a-4d0d-b3d8-c6c54d60bce1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
...@@ -3,11 +3,58 @@ import calendar ...@@ -3,11 +3,58 @@ import calendar
import sqlalchemy as sa import sqlalchemy as sa
import pandas as pd import pandas as pd
CONN = "mssql+pymssql://readdnds:reader%402021@121.37.138.1:14331/dnds"
MSSQL_CONN = "mssql+pymssql://readdnds:reader%402021@121.37.138.1:14331/dnds"
MYSQL_CONN = "mysql+pymysql://reader:Reader#2020@121.37.138.1:13316/vision_product"
def read_sql(query): RISK_STYLES = ['BETA',
engine = sa.create_engine(CONN, connect_args={"charset": "GBK"}) 'MOMENTUM',
'SIZE',
'EARNYILD',
'RESVOL',
'GROWTH',
'BTOP',
'LEVERAGE',
'LIQUIDTY',
'SIZENL']
INDUSTRY_STYLES = [
'Bank',
'RealEstate',
'Health',
'Transportation',
'Mining',
'NonFerMetal',
'HouseApp',
'LeiService',
'MachiEquip',
'BuildDeco',
'CommeTrade',
'CONMAT',
'Auto',
'Textile',
'FoodBever',
'Electronics',
'Computer',
'LightIndus',
'Utilities',
'Telecom',
'AgriForest',
'CHEM',
'Media',
'IronSteel',
'NonBankFinan',
'ELECEQP',
'AERODEF',
'Conglomerates'
]
def read_sql(query, source="mssql"):
if source == "mssql":
engine = sa.create_engine(MSSQL_CONN, connect_args={"charset": "GBK"})
elif source == "mysql":
engine = sa.create_engine(MYSQL_CONN)
return pd.read_sql(query, con=engine) return pd.read_sql(query, con=engine)
...@@ -27,7 +74,7 @@ def nearest_report_date(date): ...@@ -27,7 +74,7 @@ def nearest_report_date(date):
def fd_alive_funds(trade_dt, class_code=None): def fd_alive_funds(trade_dt, class_code=None):
if class_code: if class_code:
query = f""" query = f"""
select SECODE from TQ_FD_TYPE select SECODE FROM TQ_FD_TYPE
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
TYPESTYLE = '{str(class_code)[0]}' AND TYPESTYLE = '{str(class_code)[0]}' AND
...@@ -38,7 +85,7 @@ def fd_alive_funds(trade_dt, class_code=None): ...@@ -38,7 +85,7 @@ def fd_alive_funds(trade_dt, class_code=None):
""" """
else: else:
query = f""" query = f"""
select SECODE from TQ_FD_TYPE select SECODE FROM TQ_FD_TYPE
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
BEGINDATE <= '{trade_dt}' AND BEGINDATE <= '{trade_dt}' AND
...@@ -64,7 +111,7 @@ def fd_basicinfo(security_ids=None, trade_dt=None): ...@@ -64,7 +111,7 @@ def fd_basicinfo(security_ids=None, trade_dt=None):
if sec_id_strs: if sec_id_strs:
query = f""" query = f"""
select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE FROM TQ_FD_BASICINFO
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
SECODE in ({sec_id_strs}) AND SECODE in ({sec_id_strs}) AND
...@@ -72,7 +119,7 @@ def fd_basicinfo(security_ids=None, trade_dt=None): ...@@ -72,7 +119,7 @@ def fd_basicinfo(security_ids=None, trade_dt=None):
""" """
else: else:
query = f""" query = f"""
select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE FROM TQ_FD_BASICINFO
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101') (LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
...@@ -117,7 +164,7 @@ def fd_hshkiport(security_ids, report_dates_begin, report_dates_end=None): ...@@ -117,7 +164,7 @@ def fd_hshkiport(security_ids, report_dates_begin, report_dates_end=None):
if report_dates_end: if report_dates_end:
query = f""" query = f"""
select SECODE as SECURITYID, INDCLASSCODE, INDUSTRYCODE, INDUSTRYNAME, REPORTDATE, MVALUE, ACCNETMKTCAP from TQ_FD_HSHKIPORT select SECODE as SECURITYID, INDCLASSCODE, INDUSTRYCODE, INDUSTRYNAME, REPORTDATE, MVALUE, ACCNETMKTCAP FROM TQ_FD_HSHKIPORT
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
REPORTDATE <= '{report_dates_end}' AND REPORTDATE <= '{report_dates_end}' AND
...@@ -127,7 +174,7 @@ def fd_hshkiport(security_ids, report_dates_begin, report_dates_end=None): ...@@ -127,7 +174,7 @@ def fd_hshkiport(security_ids, report_dates_begin, report_dates_end=None):
""" """
else: else:
query = f""" query = f"""
select SECODE as SECURITYID, INDCLASSCODE, INDUSTRYCODE, INDUSTRYNAME, REPORTDATE, MVALUE, ACCNETMKTCAP from TQ_FD_HSHKIPORT select SECODE as SECURITYID, INDCLASSCODE, INDUSTRYCODE, INDUSTRYNAME, REPORTDATE, MVALUE, ACCNETMKTCAP FROM TQ_FD_HSHKIPORT
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
ISVALID = 1 AND ISVALID = 1 AND
...@@ -145,7 +192,7 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None): ...@@ -145,7 +192,7 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None):
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids]) sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
if report_dates_end: if report_dates_end:
query = f""" query = f"""
SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO FROM TQ_FD_ASSETPORTFOLIO
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
REPORTDATE <= '{report_dates_end}' AND REPORTDATE <= '{report_dates_end}' AND
...@@ -154,7 +201,7 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None): ...@@ -154,7 +201,7 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None):
""" """
else: else:
query = f""" query = f"""
SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO FROM TQ_FD_ASSETPORTFOLIO
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
ISVALID = 1 AND ISVALID = 1 AND
...@@ -170,10 +217,78 @@ def fd_qtfdnav(security_ids, trade_dt): ...@@ -170,10 +217,78 @@ def fd_qtfdnav(security_ids, trade_dt):
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids]) sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
query = f""" query = f"""
SELECT SECODE as SECURITYID, UNITNAV, UNITACCNAV, REPAIRUNITNAV, NAVGRTD from TQ_FD_DERIVEDN SELECT SECODE as SECURITYID, UNITNAV, UNITACCNAV, REPAIRUNITNAV, NAVGRTD FROM TQ_FD_DERIVEDN
WHERE WHERE
ENDDATE = '{trade_dt}' AND ENDDATE = '{trade_dt}' AND
ISVALID = 1 AND ISVALID = 1 AND
SECODE in ({sec_id_strs}) SECODE in ({sec_id_strs})
""" """
return read_sql(query).sort_values("SECURITYID") return read_sql(query).sort_values("SECURITYID")
def fd_skdetail(security_ids, trade_dt):
if isinstance(security_ids, str):
sec_id_strs = security_ids
else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
query = f"""
SELECT SECODE as SECURITYID, SKCODE, SKNAME, HOLDMKTCAP, HOLDAMT, NAVRTO FROM TQ_FD_SKDETAIL
WHERE
ENDDATE = '{trade_dt}' AND
ISVALID = 1 AND
SECODE in ({sec_id_strs})
"""
return read_sql(query).sort_values("SECURITYID")
def _to_yyyy_mm_dd(trade_dt):
if len(trade_dt) == 10:
return trade_dt
else:
return f"{trade_dt[0:4]}-{trade_dt[4:6]}-{trade_dt[6:8]}"
def risk_exposure(security_ids, trade_dt):
if isinstance(security_ids, str):
sec_id_strs = security_ids
else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
query = f"""
SELECT * FROM risk_exposure
WHERE
trade_date = '{_to_yyyy_mm_dd(trade_dt)}' AND
is_verify = 1 AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return read_sql(query, source="mysql").sort_values("security_code")
def risk_cov(trade_dt, model="short"):
query = f"""
SELECT * FROM risk_cov_{model}
WHERE
trade_date = '{_to_yyyy_mm_dd(trade_dt)}' AND
is_verify = 1 AND
flag = 1
"""
return read_sql(query, source="mysql").sort_values("FactorID")
def special_risk(security_ids, trade_dt, model="short"):
if isinstance(security_ids, str):
sec_id_strs = security_ids
else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
query = f"""
SELECT trade_date, security_code, secShortName, symbol, SRISK FROM specific_risk_{model}
WHERE
trade_date = '{_to_yyyy_mm_dd(trade_dt)}' AND
is_verify = 1 AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return read_sql(query, source="mysql").sort_values("security_code")
\ No newline at end of file
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