Exemplo n.º 1
0
def main():
    from data.const import get_trade_calendar
    from datetime import time

    trade_cal = get_trade_calendar()

    def transform_tick(tick):
        ret = None
        if tick in ['000001', '000300']:
            ret = ''.join((tick, '_SH_IX'))
        else:
            ret = ''.join((tick, '_SZ_IX'))
        return ret

    today = str(datetime.now().date())
    today_idx = trade_cal.index.searchsorted(today)
    yesterday = str(trade_cal.index[today_idx - 1].date())
    tomorrow = str(trade_cal.index[today_idx + 1].date())

    from_date, to_date = None, None
    if datetime.now().time() > time(15, 10, 0, 0):  # 过了15:10
        from_date, to_date = today, tomorrow
    else:
        from_date, to_date = yesterday, today

    index_list = ['000001', '000300', '399001', '399005', '399006']

    get_config_func = make_config(CONFIG_FILE)
    ret = predict(ticks=index_list, look_back=519, index=True,
                  get_config_func=get_config_func)
    ret = ret.sort_values(by='dt')
    print(ret)
    engines = [engine_company_local,
               engine_company_outer]
    for engine in engines:
        Base.metadata.bind = engine
        # Base.metadata.create_all(engine)
        Session.configure(bind=engine)
        session = Session()
        IndexPrediction().to_sql(session, ret)

    hist_rec = pd.read_sql_table('index_prediction', engine_company_outer)

    win_ratio = (hist_rec.dropna()
                 .query('dt>"2014-01-01"')
                 .groupby('secu')
                 .apply(lambda df: np.sum(
                     np.isclose(df.pred, df.fact)) * 1.0 / len(df))
                 .to_frame()
                 .rename(columns={0: 'accuracy'})
                 .reset_index()
                 )

    tomorrow_pred = ret.query("""dt == '{}'""".format(to_date))

    to_seven_liu = pd.merge(tomorrow_pred, win_ratio, on='secu')
    logger.info(u'明日预测结果:\n{}'.format(to_seven_liu))
Exemplo n.º 2
0
def main():

    stock_list = get_duanxianbao_b10()

    get_config_func = make_config(CONFIG_FILE)
    ret = predict(ticks=stock_list, look_back=519, index=False,
                  get_config_func=get_config_func)
    ret = ret.sort_values(by='dt')
    ret.loc[:, 'st'] = 'b10'
    print(ret)
    engines = [engine_company_local,
               engine_company_outer]
    for engine in engines:
        Base.metadata.bind = engine
        # Base.metadata.create_all(engine)
        Session.configure(bind=engine)
        session = Session()
        Duanxianbao().to_sql(session, ret)
Exemplo n.º 3
0
                   EquityPrediction)
import json
import os
import logging
import pickle
import numpy as np
fmt = '%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(message)s'
logging.basicConfig(formatter=fmt)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
CONFIG_FILE = 'predict_all_stock_feature5.csv'



if __name__ == '__main__':
    all_stocks = pd.read_csv(CONFIG_FILE, index_col=0,
                             dtype={'tick':object}).tick.unique().tolist()

    get_config_func = make_config(CONFIG_FILE)
    ret = predict(ticks=all_stocks, look_back=519, index=False,
                  get_config_func=get_config_func)
    ret = ret.sort_values(by='dt')
    print(ret)
    engines = [engine_company_local,
               engine_company_outer]
    for engine in engines:
        Base.metadata.bind = engine
        # Base.metadata.create_all(engine)
        Session.configure(bind=engine)
        session = Session()
        EquityPrediction().to_sql(session, ret)