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

remove dependency on cvxpy and cvxopt

parent 11908f2e
...@@ -14,13 +14,15 @@ from PyFin.api import * ...@@ -14,13 +14,15 @@ from PyFin.api import *
strategies = { strategies = {
'prod': { 'prod': {
'factors': ['RVOL', 'EPS', 'DROEAfterNonRecurring', 'DivP', 'CFinc1', 'BDTO'], # 'factors': ['RVOL', 'EPS', 'DROEAfterNonRecurring', 'DivP', 'CFinc1', 'BDTO'],
'weights': [0.05, 0.3, 0.35, 0.075, 0.15, 0.05] # 'weights': [0.05, 0.3, 0.35, 0.075, 0.15, 0.05]
'factors': ['CHV'],
'weights': [1.]
}, },
'candidate': { # 'candidate': {
'factors': ['RVOL', 'EPS', 'CFinc1', 'BDTO', 'VAL', 'GREV', 'ROEDiluted'], # 'factors': ['RVOL', 'EPS', 'CFinc1', 'BDTO', 'VAL', 'GREV', 'ROEDiluted'],
'weights': [0.02, 0.2, 0.15, 0.05, 0.2, 0.2, 0.2] # 'weights': [0.02, 0.2, 0.15, 0.05, 0.2, 0.2, 0.2]
} # }
} }
...@@ -39,7 +41,7 @@ elif freq == '1d': ...@@ -39,7 +41,7 @@ elif freq == '1d':
horizon = 0 horizon = 0
dates = makeSchedule('2017-01-01', dates = makeSchedule('2017-01-01',
'2017-08-18', '2017-08-20',
tenor=freq, tenor=freq,
calendar='china.sse') calendar='china.sse')
...@@ -75,7 +77,7 @@ for strategy in strategies: ...@@ -75,7 +77,7 @@ for strategy in strategies:
risk_target = risk_exp_expand.T @ benchmark risk_target = risk_exp_expand.T @ benchmark
lbound = np.zeros(len(total_data)) lbound = np.zeros(len(total_data))
ubound = 0.02 + benchmark ubound = 0.01 + benchmark
constraint = Constraints(risk_exp_expand, risk_names) constraint = Constraints(risk_exp_expand, risk_names)
for i, name in enumerate(risk_names): for i, name in enumerate(risk_names):
......
...@@ -18,7 +18,7 @@ base_factors = ['EPS', 'ROEDiluted', 'VAL', 'CFinc1'] ...@@ -18,7 +18,7 @@ base_factors = ['EPS', 'ROEDiluted', 'VAL', 'CFinc1']
expression = 0. expression = 0.
for name in base_factors: for name in base_factors:
expression = expression + LAST(name) expression = expression + RSI(10, name)
alpha_factor_name = 'alpha_factor' alpha_factor_name = 'alpha_factor'
alpha_factor = {alpha_factor_name: expression} alpha_factor = {alpha_factor_name: expression}
......
...@@ -31,14 +31,15 @@ elif freq == '1d': ...@@ -31,14 +31,15 @@ elif freq == '1d':
horizon = 0 horizon = 0
start_date = '2017-01-01' start_date = '2017-01-01'
end_date = '2017-08-18' end_date = '2017-08-22'
dates = makeSchedule(start_date, dates = makeSchedule(start_date,
end_date, end_date,
tenor=freq, tenor=freq,
calendar='china.sse') calendar='china.sse',
dateRule=BizDayConventions.Following)
prod_factors = ['EPS'] prod_factors = ['CHV']
all_data = engine.fetch_data_range(universe, prod_factors, dates=dates, benchmark=905) all_data = engine.fetch_data_range(universe, prod_factors, dates=dates, benchmark=905)
factor_all_data = all_data['factor'] factor_all_data = all_data['factor']
...@@ -59,6 +60,7 @@ for factor in prod_factors: ...@@ -59,6 +60,7 @@ for factor in prod_factors:
returns = engine.fetch_dx_return(date, codes, horizon=horizon) returns = engine.fetch_dx_return(date, codes, horizon=horizon)
total_data = pd.merge(data, returns, on=['Code']).dropna() total_data = pd.merge(data, returns, on=['Code']).dropna()
print('{0}: {1}'.format(date, len(data)))
risk_exp = total_data[neutralize_risk].values.astype(float) risk_exp = total_data[neutralize_risk].values.astype(float)
dx_return = total_data.dx.values dx_return = total_data.dx.values
benchmark = total_data.weight.values benchmark = total_data.weight.values
......
cvxopt >= 1.1.9
cvxpy >= 0.4.9
cython >= 0.25.2 cython >= 0.25.2
finance-python >= 0.5.7 finance-python >= 0.5.7
mysqlclient >= 1.3.10 mysqlclient >= 1.3.10
......
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