diff --git a/qlib/backtest/exchange.py b/qlib/backtest/exchange.py index 125f7daca..8b539de8b 100644 --- a/qlib/backtest/exchange.py +++ b/qlib/backtest/exchange.py @@ -424,7 +424,7 @@ class Exchange: else: raise NotImplementedError(f"This type of input is not supported") deal_price = self.quote.get_data(stock_id, start_time, end_time, field=pstr, method=method) - if method is not None and (deal_price is None or np.isclose(deal_price, 0.0) or np.isnan(deal_price)): + if method is not None and (deal_price is None or np.isnan(deal_price) or deal_price <= 1e-08): self.logger.warning(f"(stock_id:{stock_id}, trade_time:{(start_time, end_time)}, {pstr}): {deal_price}!!!") self.logger.warning(f"setting deal_price to close price") deal_price = self.get_close(stock_id, start_time, end_time, method) diff --git a/qlib/utils/index_data.py b/qlib/utils/index_data.py index 5594a27f9..52cc385e0 100644 --- a/qlib/utils/index_data.py +++ b/qlib/utils/index_data.py @@ -529,7 +529,8 @@ class SingleData(IndexData): tmp_data = np.full(len(index), fill_value, dtype=np.float64) for index_id, index_item in enumerate(index): try: - tmp_data[index_id] = self.loc[index_item] + item_data = self.loc[index_item] + tmp_data[index_id] = item_data if item_data != np.NaN else fill_value except KeyError: pass return SingleData(tmp_data, index) @@ -541,7 +542,7 @@ class SingleData(IndexData): common_index, _ = common_index.sort() tmp_data1 = self.reindex(common_index, fill_value) tmp_data2 = other.reindex(common_index, fill_value) - return tmp_data1.fillna(fill_value) + tmp_data2.fillna(fill_value) + return tmp_data1 + tmp_data2 def to_dict(self): """convert SingleData to dict.