예제 #1
0
 def make_table(self, load_history_trade_data=False):
     DbMaker.create_table(table_name=self.table_name)
     if load_history_trade_data:
         df = pd.read_csv(self.csv_file_path, index_col=None)
         df = df[['date', 'close']]
         # unix timestamp转datetime
         df['date'] = df['date'].apply(lambda x: datetime.fromtimestamp(x))
         df['close_forecast'] = ''
         df.columns = ['time', 'close', 'close_forecast']
         DbMaker.update_table(table_name=self.table_name,
                              close_df=df,
                              close_forecast_df=None)
예제 #2
0
    def __update_table(self, realtime_df, predicts):
        realtime_df = realtime_df.loc[:, ['date', 'close']]
        realtime_df['date'] = realtime_df['date'].apply(
            lambda x: datetime.fromtimestamp(x))
        realtime_df['close_forecast'] = ''
        realtime_df.columns = ['time', 'close', 'close_forecast']

        latest_time = realtime_df.tail(1)['time'].values[0]
        logging.info('Latest time of trade is {}'.format(
            pd.to_datetime(str(latest_time)).strftime('%Y-%m-%d %H:%M:%S')))
        period = self.trade_data_opts['period']
        # 计算real_time_df最后一个时间之后output_size个周期
        # 返回格式为: [[time1,'',predict1], [time2,'',predict2]...]
        predicts_data = [[
            latest_time + np.timedelta64(((x + 1) * period), 'm'), '',
            predicts[x]
        ] for x in range(0, self.model_opts['output_size'])]
        close_forecast_df = pd.DataFrame(
            predicts_data, columns=['time', 'close', 'close_forecast'])

        # 将real_time_df最后一个时间之后output_size个周期的预测数据append到df中
        # df = df.append(pd.DataFrame(predicts_data, columns=['time', 'close', 'close_forecast']), ignore_index=True)
        DbMaker.update_table(self.table_name, realtime_df, close_forecast_df)