예제 #1
0
    def update_for_single_code(self, code, start, end):
        data = SECURITY_DATA_READ_SERVICE.read_qfq_security_data_for_single(code, start, end)
        if data is not None and len(data) > 1:
            data = dummy_appender.append_dummy_rows(data, 1)
            data = self.indicator_func(data)
            if data is None or data.shape[0] < 1:
                pass
            else:
                df_without_dummy = dummy_appender.exclude_dummy_rows(data)
                DB_CLIENT.update_data_append_newer(df_without_dummy, self.repo_name_for_backtest())

                df_with_dummy_for_trade = data.tail(self.dummy_rows)
                min_start_date = date_time_utils.Date.from_str(end). \
                    get_before(days=MasterIndicatorDB.MAX_CALENDAR_DAYS_TO_KEEP)
                df_with_dummy_for_trade = df_with_dummy_for_trade.reset_index(level=0)
                df_with_dummy_for_trade = df_with_dummy_for_trade.loc[df_with_dummy_for_trade.date > min_start_date.as_str()]
                DB_CLIENT.replace_data_by_codes(df_with_dummy_for_trade, self.repo_name_for_trade())
예제 #2
0
 def do_fetch_and_save_bars(self, code, typ: SeType, start, end,
                            freq: SeFreq):
     repo_name = typ.repo_name(freq)
     end_date = date_time_utils.Date().as_str()
     max_date_in_db = DB_CLIENT.read_max_date_for(code, repo_name)
     if max_date_in_db is None:
         start_date = MIN_START_TIME
     else:
         start_date = date_time_utils.Date.from_str(max_date_in_db).as_str()
     try:
         if start_date != end_date:
             df = self.fetcher.fetch_bars(typ, code, start, end, freq)
             if len(df) < 1:
                 self.failed_codes.append(code)
             else:
                 df = self.remove_columns_for_min_data(df, freq)
                 DB_CLIENT.update_data_append_newer(df, repo_name)
     except Exception as e:
         print('Failed to fetch bars for {} {}, reason={}'.format(
             code, freq, e))
         self.failed_codes.append(str(code))
예제 #3
0
def calc_qfq_and_update(code, start, end):
    stock_data = SECURITY_DATA_READ_SERVICE.read_security_data_for_single(
        code, start, end)
    if stock_data is not None and len(stock_data) > 0:
        qfq_data = stock_to_qfq(stock_data)
        DB_CLIENT.update_data_append_newer(qfq_data, DAY_QFQ_REPO)
예제 #4
0
def copy_stock_day_directly(code, start, end):
    stock_data = SECURITY_DATA_READ_SERVICE.read_security_data_for_single(
        code, start, end)
    DB_CLIENT.update_data_append_newer(stock_data, DAY_QFQ_REPO)
 def save(self, data):
     if data is not None and len(data) > 0:
         repo_name = self.repo_name()
         df = data.drop(columns=['open', 'low', 'high', 'amount', 'vol'
                               ], axis=1)
         DB_CLIENT.update_data_append_newer(df, repo_name)
예제 #6
0
 def do_update_xdxr(self, code):
     df = self.fetcher.fetch_xdxr(code)
     if len(df) > 0:
         DB_CLIENT.update_data_append_newer(df, REPO_XDXR)
예제 #7
0
 def save(self, data):
     DB_CLIENT.create_index(self.repo_name(), self.freq.keys_to_index())
     if data is not None and len(data) > 0:
         repo_name = self.repo_name()
         DB_CLIENT.update_data_append_newer(data, repo_name)