mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-16 01:06:56 +08:00
black and doc
This commit is contained in:
@@ -150,12 +150,7 @@ class Exchange:
|
|||||||
if len(self.codes) == 0:
|
if len(self.codes) == 0:
|
||||||
self.codes = D.instruments()
|
self.codes = D.instruments()
|
||||||
self.quote_df = D.features(
|
self.quote_df = D.features(
|
||||||
self.codes,
|
self.codes, self.all_fields, self.start_time, self.end_time, freq=self.freq, disk_cache=True
|
||||||
self.all_fields,
|
|
||||||
self.start_time,
|
|
||||||
self.end_time,
|
|
||||||
freq=self.freq,
|
|
||||||
disk_cache=True
|
|
||||||
).dropna(subset=["$close"])
|
).dropna(subset=["$close"])
|
||||||
self.quote_df.columns = self.all_fields
|
self.quote_df.columns = self.all_fields
|
||||||
|
|
||||||
@@ -177,7 +172,6 @@ class Exchange:
|
|||||||
# The `factor.day.bin` file exists and all data `close` and `factor` are not `nan`
|
# The `factor.day.bin` file exists and all data `close` and `factor` are not `nan`
|
||||||
# Use normal price
|
# Use normal price
|
||||||
self.trade_w_adj_price = False
|
self.trade_w_adj_price = False
|
||||||
|
|
||||||
# update limit
|
# update limit
|
||||||
self._update_limit(self.limit_threshold)
|
self._update_limit(self.limit_threshold)
|
||||||
|
|
||||||
@@ -208,8 +202,7 @@ class Exchange:
|
|||||||
LT_NONE = "none" # none
|
LT_NONE = "none" # none
|
||||||
|
|
||||||
def _get_limit_type(self, limit_threshold):
|
def _get_limit_type(self, limit_threshold):
|
||||||
"""get limit type
|
"""get limit type"""
|
||||||
"""
|
|
||||||
if isinstance(limit_threshold, Tuple):
|
if isinstance(limit_threshold, Tuple):
|
||||||
return self.LT_TP_EXP
|
return self.LT_TP_EXP
|
||||||
elif isinstance(limit_threshold, float):
|
elif isinstance(limit_threshold, float):
|
||||||
@@ -603,7 +596,6 @@ class Exchange:
|
|||||||
|
|
||||||
|
|
||||||
class BaseQuote:
|
class BaseQuote:
|
||||||
|
|
||||||
def __init__(self, quote_df: pd.DataFrame):
|
def __init__(self, quote_df: pd.DataFrame):
|
||||||
self.logger = get_module_logger("online operator", level=logging.INFO)
|
self.logger = get_module_logger("online operator", level=logging.INFO)
|
||||||
|
|
||||||
@@ -617,7 +609,14 @@ class BaseQuote:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError(f"Please implement the `get_all_stock` method")
|
raise NotImplementedError(f"Please implement the `get_all_stock` method")
|
||||||
|
|
||||||
def get_data(self, stock_id: str, start_time, end_time, fields: Union[str, list]=None, method=None):
|
def get_data(
|
||||||
|
self,
|
||||||
|
stock_id: Union[str, list],
|
||||||
|
start_time: Union[pd.Timestamp, str],
|
||||||
|
end_time: Union[pd.Timestamp, str],
|
||||||
|
fields: Union[str, list] = None,
|
||||||
|
method: Union[str, Callable] = None,
|
||||||
|
):
|
||||||
"""get the specific fields of stock data during start time and end_time,
|
"""get the specific fields of stock data during start time and end_time,
|
||||||
and apply method to the data.
|
and apply method to the data.
|
||||||
|
|
||||||
@@ -637,6 +636,13 @@ class BaseQuote:
|
|||||||
2010-01-12 2788.688232 164587.937500
|
2010-01-12 2788.688232 164587.937500
|
||||||
2010-01-13 2790.604004 145460.453125
|
2010-01-13 2790.604004 145460.453125
|
||||||
|
|
||||||
|
print(get_data(stock_id=["SH600000", "SH600655"], start_time="2010-01-04", end_time="2010-01-05", fields=["$close", "$volume"], method="last"))
|
||||||
|
|
||||||
|
$close $volume
|
||||||
|
instrument
|
||||||
|
SH600000 87.433578 28117442.0
|
||||||
|
SH600655 2699.567383 158193.328125
|
||||||
|
|
||||||
print(get_data(stock_id="SH600000", start_time="2010-01-04", end_time="2010-01-05", fields=["$close", "$volume"], method="last"))
|
print(get_data(stock_id="SH600000", start_time="2010-01-04", end_time="2010-01-05", fields=["$close", "$volume"], method="last"))
|
||||||
|
|
||||||
$close 87.433578
|
$close 87.433578
|
||||||
@@ -649,27 +655,26 @@ class BaseQuote:
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
stock_id: Union[str, list]
|
stock_id: Union[str, list]
|
||||||
start_time : pd.Timestamp|str
|
start_time : Union[pd.Timestamp, str]
|
||||||
closed start time for backtest
|
closed start time for backtest
|
||||||
end_time : pd.Timestamp|str
|
end_time : Union[pd.Timestamp, str]
|
||||||
closed end time for backtest
|
closed end time for backtest
|
||||||
fields : Union[str, List]
|
fields : Union[str, List]
|
||||||
the columns of data to fetch
|
the columns of data to fetch
|
||||||
method : Union[str, Callable]
|
method : Union[str, Callable]
|
||||||
the method apply to data.
|
the method apply to data.
|
||||||
e.g ["None", "last", "all", "sum", "mean", qlib/utils/resam.py/ts_data_last]
|
e.g ["None", "last", "all", "sum", "mean", "any", qlib/utils/resam.py/ts_data_last]
|
||||||
|
|
||||||
Return
|
Return
|
||||||
----------
|
----------
|
||||||
Union[None, float, pd.Series]
|
Union[None, float, pd.Series, pd.DataFrame]
|
||||||
The resampled Series/value, return None when the resampled data is empty.
|
The resampled DataFrame/Series/value, return None when the resampled data is empty.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise NotImplementedError(f"Please implement the `get_data` method")
|
raise NotImplementedError(f"Please implement the `get_data` method")
|
||||||
|
|
||||||
|
|
||||||
class PandasQuote(BaseQuote):
|
class PandasQuote(BaseQuote):
|
||||||
|
|
||||||
def __init__(self, quote_df: pd.DataFrame):
|
def __init__(self, quote_df: pd.DataFrame):
|
||||||
super().__init__(quote_df=quote_df)
|
super().__init__(quote_df=quote_df)
|
||||||
quote_dict = {}
|
quote_dict = {}
|
||||||
@@ -680,10 +685,10 @@ class PandasQuote(BaseQuote):
|
|||||||
def get_all_stock(self):
|
def get_all_stock(self):
|
||||||
return self.data.keys()
|
return self.data.keys()
|
||||||
|
|
||||||
def get_data(self, stock_id, start_time, end_time, fields = None, method = None):
|
def get_data(self, stock_id, start_time, end_time, fields=None, method=None):
|
||||||
if(fields is None):
|
if fields is None:
|
||||||
return resam_ts_data(self.data[stock_id], start_time, end_time, method=method)
|
return resam_ts_data(self.data[stock_id], start_time, end_time, method=method)
|
||||||
elif(isinstance(fields, (str, list))):
|
elif isinstance(fields, (str, list)):
|
||||||
return resam_ts_data(self.data[stock_id][fields], start_time, end_time, method=method)
|
return resam_ts_data(self.data[stock_id][fields], start_time, end_time, method=method)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"fields must be None, str or list")
|
raise ValueError(f"fields must be None, str or list")
|
||||||
@@ -687,7 +687,9 @@ class FileOrderStrategy(BaseStrategy):
|
|||||||
- This class provides an interface for user to read orders from csv files.
|
- This class provides an interface for user to read orders from csv files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, file: Union[IO, str, Path], trade_range: Union[Tuple[int, int], TradeRange]= None, *args, **kwargs):
|
def __init__(
|
||||||
|
self, file: Union[IO, str, Path], trade_range: Union[Tuple[int, int], TradeRange] = None, *args, **kwargs
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|||||||
Reference in New Issue
Block a user