Commit 3e50b6a9 authored by Dr.李's avatar Dr.李

added style attribution

parent 6eee2118
This diff is collapsed.
This diff is collapsed.
import pandas as pd
from .utility import RISK_STYLES, INDUSTRY_STYLES
def single_style(portfolio, risk_exposure, risk_returns, specific_returns):
risk_combined = pd.merge(portfolio[["security_code", "weight"]], risk_exposure, on=["security_code"])
risk_combined[RISK_STYLES + INDUSTRY_STYLES] \
= (risk_combined[RISK_STYLES + INDUSTRY_STYLES].values.T * risk_combined["weight"].values).T
portfolio_risk_style_exposure = risk_combined[RISK_STYLES].sum()
portfolio_exposure = risk_combined[RISK_STYLES + INDUSTRY_STYLES].sum()
risk_attributed_rtn = risk_returns[RISK_STYLES + INDUSTRY_STYLES] * portfolio_exposure
risk_combined = pd.merge(risk_combined, specific_returns[["security_code", "spret"]], on=["security_code"])
spec_attributed_rtn = risk_combined["weight"] @ risk_combined["spret"] / 100.0
risk_attributed_rtn["SPECIFIC"] = spec_attributed_rtn
attributed_rtn = risk_attributed_rtn.copy()
return portfolio_risk_style_exposure, attributed_rtn
......@@ -247,7 +247,7 @@ def fd_skdetail(security_ids, trade_dt):
p_id_strs = _security_ids(security_ids)
query = f"""
SELECT SECODE as pid, SKCODE as security_code, SKNAME, HOLDMKTCAP, HOLDAMT FROM TQ_FD_SKDETAIL
SELECT SECODE as pid, SKCODE as security_code, SKNAME, HOLDMKTCAP, HOLDAMT, NAVRTO FROM TQ_FD_SKDETAIL
WHERE
ENDDATE = '{trade_dt}' AND
ISVALID = 1 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