mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-13 07:46:53 +08:00
Pass basic tests
This commit is contained in:
@@ -18,7 +18,7 @@ from ..config import C, REG_CN
|
||||
from ..utils.resam import resam_ts_data, ts_data_last
|
||||
from ..log import get_module_logger
|
||||
from .order import Order, OrderDir, OrderHelper
|
||||
from .high_performance_ds import PandasQuote, CN1minNumpyQuote
|
||||
from .high_performance_ds import BaseQuote, PandasQuote, CN1minNumpyQuote
|
||||
|
||||
|
||||
class Exchange:
|
||||
@@ -185,7 +185,7 @@ class Exchange:
|
||||
|
||||
# init quote by quote_df
|
||||
self.quote_cls = quote_cls
|
||||
self.quote = self.quote_cls(self.quote_df)
|
||||
self.quote: BaseQuote = self.quote_cls(self.quote_df)
|
||||
|
||||
def get_quote_from_qlib(self):
|
||||
# get stock data from qlib
|
||||
|
||||
@@ -40,7 +40,7 @@ class BaseQuote:
|
||||
end_time: Union[pd.Timestamp, str],
|
||||
field: Union[str],
|
||||
method: Union[str, Callable, None] = None,
|
||||
) -> Union[None, int, float, bool, "IndexData"]:
|
||||
) -> Union[None, int, float, bool, IndexData]:
|
||||
"""get the specific field of stock data during start time and end_time,
|
||||
and apply method to the data.
|
||||
|
||||
@@ -154,7 +154,7 @@ class CN1minNumpyQuote(BaseQuote):
|
||||
# this is a very special case.
|
||||
# skip aggregating function to speed-up the query calculation
|
||||
try:
|
||||
self.data[stock_id].loc[start_time, field]
|
||||
return self.data[stock_id].loc[start_time, field]
|
||||
except KeyError:
|
||||
return None
|
||||
else:
|
||||
@@ -598,7 +598,7 @@ class NumpyOrderIndicator(BaseOrderIndicator):
|
||||
if isinstance(metrics, str):
|
||||
metrics = [metrics]
|
||||
for metric in metrics:
|
||||
tmp_metric = IndexData.SingleData()
|
||||
tmp_metric = idd.SingleData()
|
||||
for indicator in indicators:
|
||||
tmp_metric = tmp_metric.add(indicator.data[metric], fill_value)
|
||||
order_indicator.data[metric] = tmp_metric
|
||||
|
||||
@@ -395,8 +395,9 @@ class Indicator:
|
||||
# NOTE: there are some zeros in the trading price. These cases are known meaningless
|
||||
# for aligning the previous logic, remove it.
|
||||
# remove zero and negative values.
|
||||
price_s = price_s[~(price_s < 1e-08)]
|
||||
price_s = price_s.loc[(price_s > 1e-08).data.astype(np.bool)]
|
||||
# NOTE ~(price_s < 1e-08) is different from price_s >= 1e-8
|
||||
# ~(np.NaN < 1e-8) -> ~(False) -> True
|
||||
|
||||
if agg == "vwap":
|
||||
volume_s = trade_exchange.get_volume(inst, trade_start_time, trade_end_time, method=None)
|
||||
|
||||
Reference in New Issue
Block a user