Commit 9ae414ab authored by Dr.李's avatar Dr.李
parents e686a434 b6923004
......@@ -843,13 +843,13 @@ class SqlEngine(object):
if __name__ == '__main__':
from PyFin.api import *
from alphamind.api import *
from PyFin.api import bizDatesList
engine = SqlEngine()
ref_date = '2017-05-03'
freq = "1m"
universe = Universe('zz800')
dates = bizDatesList('china.sse', '2018-05-01', '2018-05-10')
codes = engine.fetch_codes(ref_date, universe)
engine = SqlEngine('postgresql+psycopg2://alpha:alpha@180.166.26.82:8889')
rebalance_dates = makeSchedule('2015-01-31', '2019-05-30', freq, 'china.sse', BizDayConventions.Preceding)
res = engine.fetch_dx_return_range(universe, dates=dates, horizon=4, benchmark=300)
print(res)
\ No newline at end of file
formula = CSTopN(LAST('EP'), 5, groups='sw1')
factors = engine.fetch_factor_range(universe, {'alpha': formula}, dates=rebalance_dates)
\ No newline at end of file
......@@ -36,15 +36,17 @@ def _map_risk_model_table(risk_model: str) -> tuple:
def _map_factors(factors: Iterable[str], used_factor_tables) -> Dict:
factor_cols = {}
excluded = {'trade_date', 'code', 'isOpen'}
factors = set(factors).difference({'trade_date', 'code', 'isOpen'})
to_keep = factors.copy()
for f in factors:
for t in used_factor_tables:
if f not in excluded and f in t.__table__.columns:
if f in t.__table__.columns:
factor_cols[t.__table__.columns[f]] = t
to_keep.remove(f)
break
if not factor_cols:
raise ValueError("some factors in <{0}> can't be find".format(factors))
if to_keep:
raise ValueError("factors in <{0}> can't be find".format(to_keep))
return factor_cols
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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