Commit 70b16fcb authored by Dr.李's avatar Dr.李

update db models

parent e8f3cb15
......@@ -2385,8 +2385,30 @@ class FactorLog(Base):
minimum = Column(Float(53))
class FactorCorrelation(Base):
__tablename__ = 'factor_correlation'
__table_args__ = (
Index('factor_correlation_idx', 'trade_date', 'factor', 'source', unique=True),
)
trade_date = Column(DateTime, primary_key=True, nullable=False)
factor = Column(String(30), primary_key=True, nullable=False)
source = Column(String(30), primary_key=True, nullable=False)
BETA = Column(Float(53))
MOMENTUM = Column(Float(53))
SIZE = Column(Float(53))
EARNYILD = Column(Float(53))
RESVOL = Column(Float(53))
GROWTH = Column(Float(53))
BTOP = Column(Float(53))
LEVERAGE = Column(Float(53))
LIQUIDTY = Column(Float(53))
SIZENL = Column(Float(53))
if __name__ == '__main__':
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://postgres:we083826@192.168.0.102/alpha')
engine = create_engine('postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha')
Base.metadata.create_all(engine)
......@@ -626,7 +626,7 @@ if __name__ == '__main__':
from alphamind.api import alpha_logger
# db_url = 'postgresql+psycopg2://postgres:we083826@localhost/alpha'
db_url = 'postgresql+psycopg2://postgres:we083826@192.168.0.102/alpha'
db_url = 'postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
universe = Universe('custom', ['zz500'])
engine = SqlEngine(db_url)
......@@ -651,5 +651,7 @@ if __name__ == '__main__':
alpha_logger.info('end')
data2 = engine.fetch_codes_range(universe, start_date=start_date, end_date=end_date, dates=dates)
alpha_logger.info('end')
data2 = engine.fetch_dx_return_range(universe, start_date=start_date, end_date=end_date, dates=dates)
alpha_logger.info('end')
print(data1)
......@@ -17,13 +17,17 @@ import datetime as dt
start = dt.datetime.now()
# formula1 = CSRank(DIFF(LOG("turnoverVol")))
# formula2 = CSRank((LAST('highestPrice') - LAST('lowestPrice')) / LAST('lowestPrice'))
# expression = -CORR(6, formula1 ^ formula2)
formula1 = CSRank(DIFF(LOG("turnoverVol")))
formula2 = CSRank((LAST('closePrice') - LAST('openPrice')) / LAST('openPrice'))
expression = -CORR(6, formula1 ^ formula2)
# expression1 = -0.6 * LAST('con_pe_rolling') - 0.6 * LAST('con_pb_rolling') + 0.6 * LAST('con_eps') + 1.2 * LAST('con_target_price')
# expression2 = LAST("IVR")
factor1 = LAST('RVOL')
factor2 = LAST('IVR')
expression = RES(20, factor2 ^ factor1)
#expression = expression1 + expression2
# factor1 = LAST('RVOL')
# factor2 = LAST('IVR')
# expression = RES(20, factor2 ^ factor1)
# expression = MA(1, "EPS")
......@@ -33,14 +37,14 @@ alpha_factor = {alpha_factor_name: expression}
# end of formula definition
engine = SqlEngine('postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha')
universe = Universe('custom', ['zz500'])
universe = Universe('custom', ['ashare_ex'])
benchmark_code = 905
neutralize_risk = ['SIZE'] + industry_styles
freq = '1w'
n_bins = 5
dates = makeSchedule('2012-01-01',
'2017-09-18',
'2017-10-11',
tenor=freq,
calendar='china.sse')
......@@ -71,7 +75,7 @@ for i, value in enumerate(factor_groups):
er = factor_processing(total_data[[alpha_factor_name]].values,
pre_process=[winsorize_normal, standardize],
risk_factors=risk_exp,
post_process=[standardize])
post_process=[winsorize_normal, standardize])
res = er_quantile_analysis(er,
n_bins=n_bins,
dx_return=dx_return,
......
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