예제 #1
0
def mainfunc():
    with open (const.CFG_TARGET_FILE,'r') as f:
        tgt_json=json.load(f)

    print(tgt_json['symbols']) 
    bbid_dic=mc_dbapi.fetch_bbid(tgt_json['symbols'][0])
    df=mc_dbapi.fetch_ohlc(bbid_dic['bbid'],tgt_json['start_date'],tgt_json['end_date'])
    obj_strategy=strategy_pkg(tgt_json['symbols'][0],df[['middle']],tgt_json['strategy_start_date'],tgt_json['strategy_end_date'])
    obj_strategy.hindcast_up_in_down_out()
    obj_strategy.plot_funding_curve()
예제 #2
0
 def load_data(self):
     from dbapi import mc_dbapi
     self.df = pd.DataFrame()
     for tgt in self.target_names:
         print(tgt + ' loading...')
         bbid_dic = mc_dbapi.fetch_bbid(tgt)
         df = mc_dbapi.fetch_ohlc(bbid_dic['bbid'], self.data_start_date,
                                  self.strategy_end_time)
         df = df.loc[:, ['middle']]
         df = df.rename(columns={"middle": tgt})
         self.df = pd.concat([self.df, df], axis=1)
예제 #3
0
def mainfunc():
    date_lastday = datetime.datetime.now() + datetime.timedelta(days=-1)
    date_startday = datetime.datetime.now() + datetime.timedelta(days=-366 *
                                                                 11)
    date_strategy_startday = datetime.datetime.now() + datetime.timedelta(
        days=-366 * 10)
    date_str_last = date_lastday.strftime('%Y%m%d')
    date_str_start = date_startday.strftime('%Y%m%d')

    with open(const.CFG_PORTFOLIO_FILE, 'r') as f:
        tgt_json = json.load(f)

    web_dic = {}
    ii = 0
    for tgt in tgt_json['symbols']:
        ii = ii + 1
        print(tgt)
        bbid_dic = mc_dbapi.fetch_bbid(tgt)
        df = mc_dbapi.fetch_ohlc(bbid_dic['bbid'], date_str_start,
                                 date_str_last)
        date_strategy_startday = parse_trading_day(df.index,
                                                   date_strategy_startday)
        date_lastday = parse_trading_day(df.index, date_lastday)
        obj_strategy = strategy_pkg(tgt, df[['middle']],
                                    date_strategy_startday.strftime('%Y%m%d'),
                                    date_lastday.strftime('%Y%m%d'))
        obj_strategy.hindcast_up_in_down_out()
        obj_strategy.strategy_info()

        web_dic['target' + str(ii)] = obj_strategy.info

        obj_strategy.plot_funding_curve()
        plt.savefig(const.MERC_ROOT + '/routine_output/' + tgt + '.png')
        plt.close()
    with open(const.MERC_ROOT + '/routine_output/routine_info.json', 'w') as f:
        json.dump(web_dic, f)
def get_us_eq_hist():
    # search bbid
    bbid_dic=mc_dbapi.fetch_bbid('QQQ')
    df=mc_dbapi.fetch_ohlc(bbid_dic['bbid'],'20180304','20180905')
    print(df[['close']])