Commit 25b0127d authored by Dr.李's avatar Dr.李

fixed bug

parent d3bf7111
......@@ -41,6 +41,7 @@ def cross_section_analysis(ref_date,
dx_returns = engine.fetch_dx_return(ref_date, codes, horizon=horizon, offset=1)
target_pos = pd.merge(target_pos, dx_returns, on=['code'])
target_pos = pd.merge(target_pos, total_data[['code'] + constraint_risk], on=['code'])
activate_weight = target_pos.weight.values
excess_return = np.exp(target_pos.dx.values) - 1.
port_ret = np.log(activate_weight @ excess_return + 1.)
......@@ -50,5 +51,29 @@ def cross_section_analysis(ref_date,
t_stats = results.tvalues[1]
alpha_logger.info(f"{ref_date} is finished with {len(target_pos)} stocks for {factor_name}")
alpha_logger.info(f"{ref_date} risk_exposure {target_pos.weight.values @ total_risk_exp.values}")
return port_ret, ic, t_stats
\ No newline at end of file
alpha_logger.info(f"{ref_date} risk_exposure \n {target_pos.weight.values @ target_pos[constraint_risk].values}")
return port_ret, ic, t_stats
if __name__ == '__main__':
import numpy as np
import pandas as pd
import statsmodels.api as sm
from alphamind.api import *
from PyFin.api import *
factor_name = 'SIZE'
data_source = 'postgres+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
engine = SqlEngine(data_source)
risk_names = list(set(risk_styles).difference({factor_name}))
industry_names = list(set(industry_styles).difference({factor_name}))
constraint_risk = risk_names + industry_names
universe = Universe('custom', ['ashare_ex'])
horizon = 9
cross_section_analysis('2018-02-08',
factor_name,
universe,
horizon,
constraint_risk,
engine=engine)
\ 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