code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def gen_dataset_cache(self, cache_path: Union[str, Path], instruments, fields, freq, inst_processors=[]): """gen_dataset_cache .. note:: This function does not consider the cache read write lock. Please acquire the lock outside this function The format the cache contains 3 parts(fo...
gen_dataset_cache .. note:: This function does not consider the cache read write lock. Please acquire the lock outside this function The format the cache contains 3 parts(followed by typical filename). - index : cache/d41366901e25de3ec47297f12e2ba11d.index - The conte...
gen_dataset_cache
python
microsoft/qlib
qlib/data/cache.py
https://github.com/microsoft/qlib/blob/master/qlib/data/cache.py
MIT
def send_request(self, request_type, request_content, msg_queue, msg_proc_func=None): """Send a certain request to server. Parameters ---------- request_type : str type of proposed request, 'calendar'/'instrument'/'feature'. request_content : dict records...
Send a certain request to server. Parameters ---------- request_type : str type of proposed request, 'calendar'/'instrument'/'feature'. request_content : dict records the information of the request. msg_proc_func : func the function to process...
send_request
python
microsoft/qlib
qlib/data/client.py
https://github.com/microsoft/qlib/blob/master/qlib/data/client.py
MIT
def request_callback(*args): """callback_wrapper :param *args: args[0] is the response content """ # args[0] is the response content self.logger.debug("receive data and enter queue") msg = dict(args[0]) if msg["detailed_info"] is not N...
callback_wrapper :param *args: args[0] is the response content
request_callback
python
microsoft/qlib
qlib/data/client.py
https://github.com/microsoft/qlib/blob/master/qlib/data/client.py
MIT
def calendar(self, start_time=None, end_time=None, freq="day", future=False): """Get calendar of certain market in given time range. Parameters ---------- start_time : str start of the time range. end_time : str end of the time range. freq : str ...
Get calendar of certain market in given time range. Parameters ---------- start_time : str start of the time range. end_time : str end of the time range. freq : str time frequency, available: year/quarter/month/week/day. future : bool ...
calendar
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def locate_index( self, start_time: Union[pd.Timestamp, str], end_time: Union[pd.Timestamp, str], freq: str, future: bool = False ): """Locate the start time index and end time index in a calendar under certain frequency. Parameters ---------- start_time : pd.Timestamp ...
Locate the start time index and end time index in a calendar under certain frequency. Parameters ---------- start_time : pd.Timestamp start of the time range. end_time : pd.Timestamp end of the time range. freq : str time frequency, available:...
locate_index
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def _get_calendar(self, freq, future): """Load calendar using memcache. Parameters ---------- freq : str frequency of read calendar file. future : bool whether including future trading day. Returns ------- list list of...
Load calendar using memcache. Parameters ---------- freq : str frequency of read calendar file. future : bool whether including future trading day. Returns ------- list list of timestamps. dict dict compose...
_get_calendar
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def instruments(market: Union[List, str] = "all", filter_pipe: Union[List, None] = None): """Get the general config dictionary for a base market adding several dynamic filters. Parameters ---------- market : Union[List, str] str: market/industry/index shortna...
Get the general config dictionary for a base market adding several dynamic filters. Parameters ---------- market : Union[List, str] str: market/industry/index shortname, e.g. all/sse/szse/sse50/csi300/csi500. list: ["ID1", "ID2"]. A list o...
instruments
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def period_feature( self, instrument, field, start_index: int, end_index: int, cur_time: pd.Timestamp, period: Optional[int] = None, ) -> pd.Series: """ get the historical periods data series between `start_index` and `end_index` Param...
get the historical periods data series between `start_index` and `end_index` Parameters ---------- start_index: int start_index is a relative index to the latest period to cur_time end_index: int end_index is a relative index to the latest period to cur...
period_feature
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def _uri( self, instruments, fields, start_time=None, end_time=None, freq="day", disk_cache=1, inst_processors=[], **kwargs, ): """Get task uri, used when generating rabbitmq task in qlib_server Parameters ---------- ...
Get task uri, used when generating rabbitmq task in qlib_server Parameters ---------- instruments : list or dict list/dict of instruments or dict of stockpool config. fields : list list of feature instances. start_time : str start of the time ...
_uri
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def get_instruments_d(instruments, freq): """ Parse different types of input instruments to output instruments_d Wrong format of input instruments will lead to exception. """ if isinstance(instruments, dict): if "market" in instruments: # dict of stoc...
Parse different types of input instruments to output instruments_d Wrong format of input instruments will lead to exception.
get_instruments_d
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def get_column_names(fields): """ Get column names from input fields """ if len(fields) == 0: raise ValueError("fields cannot be empty") column_names = [str(f) for f in fields] return column_names
Get column names from input fields
get_column_names
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def dataset_processor(instruments_d, column_names, start_time, end_time, freq, inst_processors=[]): """ Load and process the data, return the data set. - default using multi-kernel method. """ normalize_column_names = normalize_cache_fields(column_names) # One process fo...
Load and process the data, return the data set. - default using multi-kernel method.
dataset_processor
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def inst_calculator(inst, start_time, end_time, freq, column_names, spans=None, g_config=None, inst_processors=[]): """ Calculate the expressions for **one** instrument, return a df result. If the expression has been calculated before, load from cache. return value: A data frame with in...
Calculate the expressions for **one** instrument, return a df result. If the expression has been calculated before, load from cache. return value: A data frame with index 'datetime' and other data columns.
inst_calculator
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def load_calendar(self, freq, future): """Load original calendar timestamp from file. Parameters ---------- freq : str frequency of read calendar file. future: bool Returns ---------- list list of timestamps """ try...
Load original calendar timestamp from file. Parameters ---------- freq : str frequency of read calendar file. future: bool Returns ---------- list list of timestamps
load_calendar
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def __init__(self, align_time: bool = True): """ Parameters ---------- align_time : bool Will we align the time to calendar the frequency is flexible in some dataset and can't be aligned. For the data with fixed frequency with a shared calendar, the al...
Parameters ---------- align_time : bool Will we align the time to calendar the frequency is flexible in some dataset and can't be aligned. For the data with fixed frequency with a shared calendar, the align data to the calendar will provides following benefit...
__init__
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def multi_cache_walker(instruments, fields, start_time=None, end_time=None, freq="day"): """ This method is used to prepare the expression cache for the client. Then the client will load the data from expression cache by itself. """ instruments_d = DatasetProvider.get_instrument...
This method is used to prepare the expression cache for the client. Then the client will load the data from expression cache by itself.
multi_cache_walker
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def cache_walker(inst, start_time, end_time, freq, column_names): """ If the expressions of one instrument haven't been calculated before, calculate it and write it into expression cache. """ for field in column_names: ExpressionD.expression(inst, field, start_time, ...
If the expressions of one instrument haven't been calculated before, calculate it and write it into expression cache.
cache_walker
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def features( self, instruments, fields, start_time=None, end_time=None, freq="day", disk_cache=None, inst_processors=[], ): """ Parameters ---------- disk_cache : int whether to skip(0)/use(1)/replace(2) dis...
Parameters ---------- disk_cache : int whether to skip(0)/use(1)/replace(2) disk_cache This function will try to use cache method which has a keyword `disk_cache`, and will use provider method if a type error is raised because the DatasetD instance is a pro...
features
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def _uri(self, type, **kwargs): """_uri The server hope to get the uri of the request. The uri will be decided by the dataprovider. For ex, different cache layer has different uri. :param type: The type of resource for the uri :param **kwargs: """ if type == "cal...
_uri The server hope to get the uri of the request. The uri will be decided by the dataprovider. For ex, different cache layer has different uri. :param type: The type of resource for the uri :param **kwargs:
_uri
python
microsoft/qlib
qlib/data/data.py
https://github.com/microsoft/qlib/blob/master/qlib/data/data.py
MIT
def __init__(self, fstart_time=None, fend_time=None, keep=False): """Init function for filter base class. Filter a set of instruments based on a certain rule within a certain period assigned by fstart_time and fend_time. Parameters ---------- fstart_time: str the...
Init function for filter base class. Filter a set of instruments based on a certain rule within a certain period assigned by fstart_time and fend_time. Parameters ---------- fstart_time: str the time for the filter rule to start filter the instruments. fend_time:...
__init__
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def _getTimeBound(self, instruments): """Get time bound for all instruments. Parameters ---------- instruments: dict the dict of instruments in the form {instrument_name => list of timestamp tuple}. Returns ---------- pd.Timestamp, pd.Timestamp ...
Get time bound for all instruments. Parameters ---------- instruments: dict the dict of instruments in the form {instrument_name => list of timestamp tuple}. Returns ---------- pd.Timestamp, pd.Timestamp the lower time bound and upper time bound ...
_getTimeBound
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def _toSeries(self, time_range, target_timestamp): """Convert the target timestamp to a pandas series of bool value within a time range. Make the time inside the target_timestamp range TRUE, others FALSE. Parameters ---------- time_range : D.calendar the time ran...
Convert the target timestamp to a pandas series of bool value within a time range. Make the time inside the target_timestamp range TRUE, others FALSE. Parameters ---------- time_range : D.calendar the time range of the instruments. target_timestamp : list ...
_toSeries
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def _filterSeries(self, timestamp_series, filter_series): """Filter the timestamp series with filter series by using element-wise AND operation of the two series. Parameters ---------- timestamp_series : pd.Series the series of bool value indicating existing time. fi...
Filter the timestamp series with filter series by using element-wise AND operation of the two series. Parameters ---------- timestamp_series : pd.Series the series of bool value indicating existing time. filter_series : pd.Series the series of bool value indicati...
_filterSeries
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def _toTimestamp(self, timestamp_series): """Convert the timestamp series to a list of tuple (timestamp, timestamp) indicating a continuous range of TRUE. Parameters ---------- timestamp_series: pd.Series the series of bool value after being filtered. Returns ...
Convert the timestamp series to a list of tuple (timestamp, timestamp) indicating a continuous range of TRUE. Parameters ---------- timestamp_series: pd.Series the series of bool value after being filtered. Returns ---------- list the list of tup...
_toTimestamp
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def __call__(self, instruments, start_time=None, end_time=None, freq="day"): """Call this filter to get filtered instruments list""" self.filter_freq = freq return self.filter_main(instruments, start_time, end_time)
Call this filter to get filtered instruments list
__call__
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def filter_main(self, instruments, start_time=None, end_time=None): """Implement this method to filter the instruments. Parameters ---------- instruments: dict input instruments to be filtered. start_time: str start of the time range. end_time: st...
Implement this method to filter the instruments. Parameters ---------- instruments: dict input instruments to be filtered. start_time: str start of the time range. end_time: str end of the time range. Returns ---------- ...
filter_main
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def __init__(self, name_rule_re, fstart_time=None, fend_time=None): """Init function for name filter class Parameters ---------- name_rule_re: str regular expression for the name rule. """ super(NameDFilter, self).__init__(fstart_time, fend_time) self...
Init function for name filter class Parameters ---------- name_rule_re: str regular expression for the name rule.
__init__
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def __init__(self, rule_expression, fstart_time=None, fend_time=None, keep=False): """Init function for expression filter class Parameters ---------- fstart_time: str filter the feature starting from this time. fend_time: str filter the feature ending by ...
Init function for expression filter class Parameters ---------- fstart_time: str filter the feature starting from this time. fend_time: str filter the feature ending by this time. rule_expression: str an input expression for the rule.
__init__
python
microsoft/qlib
qlib/data/filter.py
https://github.com/microsoft/qlib/blob/master/qlib/data/filter.py
MIT
def __call__(self, df: pd.DataFrame, instrument, *args, **kwargs): """ process the data NOTE: **The processor could change the content of `df` inplace !!!!! ** User should keep a copy of data outside Parameters ---------- df : pd.DataFrame The raw_df...
process the data NOTE: **The processor could change the content of `df` inplace !!!!! ** User should keep a copy of data outside Parameters ---------- df : pd.DataFrame The raw_df of handler or result from previous processor.
__call__
python
microsoft/qlib
qlib/data/inst_processor.py
https://github.com/microsoft/qlib/blob/master/qlib/data/inst_processor.py
MIT
def _load_internal(self, instrument, start_index, end_index, *args): """ To avoid error raised by bool type input, we transform the data into float32. """ series = self.feature.load(instrument, start_index, end_index, *args) # TODO: More precision types should be configurable ...
To avoid error raised by bool type input, we transform the data into float32.
_load_internal
python
microsoft/qlib
qlib/data/ops.py
https://github.com/microsoft/qlib/blob/master/qlib/data/ops.py
MIT
def __init__(self, feature, freq, func): """ Resampling the data to target frequency. The resample function of pandas is used. - the timestamp will be at the start of the time span after resample. Parameters ---------- feature : Expression An express...
Resampling the data to target frequency. The resample function of pandas is used. - the timestamp will be at the start of the time span after resample. Parameters ---------- feature : Expression An expression for calculating the feature freq : str ...
__init__
python
microsoft/qlib
qlib/data/ops.py
https://github.com/microsoft/qlib/blob/master/qlib/data/ops.py
MIT
def register(self, ops_list: List[Union[Type[ExpressionOps], dict]]): """register operator Parameters ---------- ops_list : List[Union[Type[ExpressionOps], dict]] - if type(ops_list) is List[Type[ExpressionOps]], each element of ops_list represents the operator class, which ...
register operator Parameters ---------- ops_list : List[Union[Type[ExpressionOps], dict]] - if type(ops_list) is List[Type[ExpressionOps]], each element of ops_list represents the operator class, which should be the subclass of `ExpressionOps`. - if type(ops_list) is Lis...
register
python
microsoft/qlib
qlib/data/ops.py
https://github.com/microsoft/qlib/blob/master/qlib/data/ops.py
MIT
def __init__( self, instruments=None, start_time=None, end_time=None, data_loader: Union[dict, str, DataLoader] = None, init_data=True, fetch_orig=True, ): """ Parameters ---------- instruments : The stock list to re...
Parameters ---------- instruments : The stock list to retrieve. start_time : start_time of the original data. end_time : end_time of the original data. data_loader : Union[dict, str, DataLoader] data loader to load the data...
__init__
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def config(self, **kwargs): """ configuration of data. # what data to be loaded from data source This method will be used when loading pickled handler from dataset. The data will be initialized with different time range. """ attr_list = {"instruments", "start_ti...
configuration of data. # what data to be loaded from data source This method will be used when loading pickled handler from dataset. The data will be initialized with different time range.
config
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def setup_data(self, enable_cache: bool = False): """ Set Up the data in case of running initialization for multiple time It is responsible for maintaining following variable 1) self._data Parameters ---------- enable_cache : bool default value is fa...
Set Up the data in case of running initialization for multiple time It is responsible for maintaining following variable 1) self._data Parameters ---------- enable_cache : bool default value is false: - if `enable_cache` == True: ...
setup_data
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def fetch( self, selector: Union[pd.Timestamp, slice, str, pd.Index] = slice(None, None), level: Union[str, int] = "datetime", col_set: Union[str, List[str]] = CS_ALL, squeeze: bool = False, proc_func: Callable = None, ) -> pd.DataFrame: """ fetch data...
fetch data from underlying data source Design motivation: - providing a unified interface for underlying data. - Potential to make the interface more friendly. - User can improve performance when fetching data in this extra layer Parameters ---------- s...
fetch
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def get_cols(self, col_set=CS_ALL) -> list: """ get the column names Parameters ---------- col_set : str select a set of meaningful columns.(e.g. features, columns) Returns ------- list: list of column names """ df...
get the column names Parameters ---------- col_set : str select a set of meaningful columns.(e.g. features, columns) Returns ------- list: list of column names
get_cols
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def get_range_selector(self, cur_date: Union[pd.Timestamp, str], periods: int) -> slice: """ get range selector by number of periods Args: cur_date (pd.Timestamp or str): current date periods (int): number of periods """ trading_dates = self._data.index.u...
get range selector by number of periods Args: cur_date (pd.Timestamp or str): current date periods (int): number of periods
get_range_selector
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def get_range_iterator( self, periods: int, min_periods: Optional[int] = None, **kwargs ) -> Iterator[Tuple[pd.Timestamp, pd.DataFrame]]: """ get an iterator of sliced data with given periods Args: periods (int): number of periods. min_periods (int): minimum ...
get an iterator of sliced data with given periods Args: periods (int): number of periods. min_periods (int): minimum periods for sliced dataframe. kwargs (dict): will be passed to `self.fetch`.
get_range_iterator
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def __init__( self, instruments=None, start_time=None, end_time=None, data_loader: Union[dict, str, DataLoader] = None, infer_processors: List = [], learn_processors: List = [], shared_processors: List = [], process_type=PTYPE_A, drop_raw=F...
Parameters ---------- infer_processors : list - list of <description info> of processors to generate data for inference - example of <description info>: .. code-block:: 1) classname & kwargs: { "c...
__init__
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def fit(self): """ fit data without processing the data """ for proc in self.get_all_processors(): with TimeInspector.logt(f"{proc.__class__.__name__}"): proc.fit(self._data)
fit data without processing the data
fit
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def _is_proc_readonly(proc_l: List[processor_module.Processor]): """ NOTE: it will return True if `len(proc_l) == 0` """ for p in proc_l: if not p.readonly(): return False return True
NOTE: it will return True if `len(proc_l) == 0`
_is_proc_readonly
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def process_data(self, with_fit: bool = False): """ process_data data. Fun `processor.fit` if necessary Notation: (data) [processor] # data processing flow of self.process_type == DataHandlerLP.PTYPE_I .. code-block:: text (self._data)-[shared_processors]-(_share...
process_data data. Fun `processor.fit` if necessary Notation: (data) [processor] # data processing flow of self.process_type == DataHandlerLP.PTYPE_I .. code-block:: text (self._data)-[shared_processors]-(_shared_df)-[learn_processors]-(_learn_df) ...
process_data
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def setup_data(self, init_type: str = IT_FIT_SEQ, **kwargs): """ Set up the data in case of running initialization for multiple time Parameters ---------- init_type : str The type `IT_*` listed above. enable_cache : bool default value is false: ...
Set up the data in case of running initialization for multiple time Parameters ---------- init_type : str The type `IT_*` listed above. enable_cache : bool default value is false: - if `enable_cache` == True: the processed d...
setup_data
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def fetch( self, selector: Union[pd.Timestamp, slice, str] = slice(None, None), level: Union[str, int] = "datetime", col_set=DataHandler.CS_ALL, data_key: DATA_KEY_TYPE = DK_I, squeeze: bool = False, proc_func: Callable = None, ) -> pd.DataFrame: """ ...
fetch data from underlying data source Parameters ---------- selector : Union[pd.Timestamp, slice, str] describe how to select data by index. level : Union[str, int] which index level to select the data. col_set : str select a set of ...
fetch
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def get_cols(self, col_set=DataHandler.CS_ALL, data_key: DATA_KEY_TYPE = DK_I) -> list: """ get the column names Parameters ---------- col_set : str select a set of meaningful columns.(e.g. features, columns). data_key : DATA_KEY_TYPE the data to ...
get the column names Parameters ---------- col_set : str select a set of meaningful columns.(e.g. features, columns). data_key : DATA_KEY_TYPE the data to fetch: DK_*. Returns ------- list: list of column names ...
get_cols
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def cast(cls, handler: "DataHandlerLP") -> "DataHandlerLP": """ Motivation - A user creates a datahandler in his customized package. Then he wants to share the processed handler to other users without introduce the package dependency and complicated data processing logic. - Th...
Motivation - A user creates a datahandler in his customized package. Then he wants to share the processed handler to other users without introduce the package dependency and complicated data processing logic. - This class make it possible by casting the class to DataHandlerLP and onl...
cast
python
microsoft/qlib
qlib/data/dataset/handler.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/handler.py
MIT
def load(self, instruments, start_time=None, end_time=None) -> pd.DataFrame: """ load the data as pd.DataFrame. Example of the data (The multi-index of the columns is optional.): .. code-block:: text feature ...
load the data as pd.DataFrame. Example of the data (The multi-index of the columns is optional.): .. code-block:: text feature label $close $vol...
load
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def __init__(self, config: Union[list, tuple, dict]): """ Parameters ---------- config : Union[list, tuple, dict] Config will be used to describe the fields and column names .. code-block:: <config> := { "group_name1": <fields...
Parameters ---------- config : Union[list, tuple, dict] Config will be used to describe the fields and column names .. code-block:: <config> := { "group_name1": <fields_info1> "group_name2": <fields_info2> ...
__init__
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def load_group_df( self, instruments, exprs: list, names: list, start_time: Union[str, pd.Timestamp] = None, end_time: Union[str, pd.Timestamp] = None, gp_name: str = None, ) -> pd.DataFrame: """ load the dataframe for specific group P...
load the dataframe for specific group Parameters ---------- instruments : the instruments. exprs : list the expressions to describe the content of the data. names : list the name of the data. Returns ------- p...
load_group_df
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def __init__( self, config: Tuple[list, tuple, dict], filter_pipe: List = None, swap_level: bool = True, freq: Union[str, dict] = "day", inst_processors: Union[dict, list] = None, ): """ Parameters ---------- config : Tuple[list, tuple,...
Parameters ---------- config : Tuple[list, tuple, dict] Please refer to the doc of DLWParser filter_pipe : Filter pipe for the instruments swap_level : Whether to swap level of MultiIndex freq: dict or str If type(config) ...
__init__
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def __init__(self, config: Union[dict, str, pd.DataFrame], join="outer"): """ Parameters ---------- config : dict {fields_group: <path or object>} join : str How to align different dataframes """ self._config = config # using "_" to avoid ...
Parameters ---------- config : dict {fields_group: <path or object>} join : str How to align different dataframes
__init__
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def __init__(self, dataloader_l: List[Dict], join="left") -> None: """ Parameters ---------- dataloader_l : list[dict] A list of dataloader, for exmaple .. code-block:: python nd = NestedDataLoader( dataloader_l=[ ...
Parameters ---------- dataloader_l : list[dict] A list of dataloader, for exmaple .. code-block:: python nd = NestedDataLoader( dataloader_l=[ { "class": "qlib.contrib.data.loader....
__init__
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def __init__(self, handler_config: dict, fetch_kwargs: dict = {}, is_group=False): """ Parameters ---------- handler_config : dict handler_config will be used to describe the handlers .. code-block:: <handler_config> := { "gro...
Parameters ---------- handler_config : dict handler_config will be used to describe the handlers .. code-block:: <handler_config> := { "group_name1": <handler> "group_name2": <handler> } ...
__init__
python
microsoft/qlib
qlib/data/dataset/loader.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/loader.py
MIT
def get_group_columns(df: pd.DataFrame, group: Union[Text, None]): """ get a group of columns from multi-index columns DataFrame Parameters ---------- df : pd.DataFrame with multi of columns. group : str the name of the feature group, i.e. the first level value of the group inde...
get a group of columns from multi-index columns DataFrame Parameters ---------- df : pd.DataFrame with multi of columns. group : str the name of the feature group, i.e. the first level value of the group index.
get_group_columns
python
microsoft/qlib
qlib/data/dataset/processor.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/processor.py
MIT
def fit(self, df: pd.DataFrame = None): """ learn data processing parameters Parameters ---------- df : pd.DataFrame When we fit and process data with processor one by one. The fit function reiles on the output of previous processor, i.e. `df`. "...
learn data processing parameters Parameters ---------- df : pd.DataFrame When we fit and process data with processor one by one. The fit function reiles on the output of previous processor, i.e. `df`.
fit
python
microsoft/qlib
qlib/data/dataset/processor.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/processor.py
MIT
def __init__( self, start_time: Optional[Union[pd.Timestamp, str]] = None, end_time: Optional[Union[pd.Timestamp, str]] = None, freq: str = "day", ): """ Parameters ---------- start_time : Optional[Union[pd.Timestamp, str]] The data must st...
Parameters ---------- start_time : Optional[Union[pd.Timestamp, str]] The data must start earlier (or equal) than `start_time` None indicates data will not be filtered based on `start_time` end_time : Optional[Union[pd.Timestamp, str]] similar to star...
__init__
python
microsoft/qlib
qlib/data/dataset/processor.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/processor.py
MIT
def fetch( self, selector: Union[pd.Timestamp, slice, str, list] = slice(None, None), level: Union[str, int] = "datetime", col_set: Union[str, List[str]] = DataHandler.CS_ALL, fetch_orig: bool = True, proc_func: Callable = None, **kwargs, ) -> pd.DataFrame: ...
fetch data from the data storage Parameters ---------- selector : Union[pd.Timestamp, slice, str] describe how to select data by index level : Union[str, int] which index level to select the data - if level is None, apply selector to df directly ...
fetch
python
microsoft/qlib
qlib/data/dataset/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/storage.py
MIT
def _fetch_hash_df_by_stock(self, selector, level): """fetch the data with stock selector Parameters ---------- selector : Union[pd.Timestamp, slice, str] describe how to select data by index level : Union[str, int] which index level to select the data ...
fetch the data with stock selector Parameters ---------- selector : Union[pd.Timestamp, slice, str] describe how to select data by index level : Union[str, int] which index level to select the data - if level is None, apply selector to df directly ...
_fetch_hash_df_by_stock
python
microsoft/qlib
qlib/data/dataset/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/storage.py
MIT
def get_level_index(df: pd.DataFrame, level: Union[str, int]) -> int: """ get the level index of `df` given `level` Parameters ---------- df : pd.DataFrame data level : Union[str, int] index level Returns ------- int: The level index in the multiple index ...
get the level index of `df` given `level` Parameters ---------- df : pd.DataFrame data level : Union[str, int] index level Returns ------- int: The level index in the multiple index
get_level_index
python
microsoft/qlib
qlib/data/dataset/utils.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/utils.py
MIT
def fetch_df_by_index( df: pd.DataFrame, selector: Union[pd.Timestamp, slice, str, list, pd.Index], level: Union[str, int], fetch_orig=True, ) -> pd.DataFrame: """ fetch data from `data` with `selector` and `level` selector are assumed to be well processed. `fetch_df_by_index` is only r...
fetch data from `data` with `selector` and `level` selector are assumed to be well processed. `fetch_df_by_index` is only responsible for get the right level Parameters ---------- selector : Union[pd.Timestamp, slice, str, list] selector level : Union[int, str] the level t...
fetch_df_by_index
python
microsoft/qlib
qlib/data/dataset/utils.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/utils.py
MIT
def convert_index_format(df: Union[pd.DataFrame, pd.Series], level: str = "datetime") -> Union[pd.DataFrame, pd.Series]: """ Convert the format of df.MultiIndex according to the following rules: - If `level` is the first level of df.MultiIndex, do nothing - If `level` is the second level of df.M...
Convert the format of df.MultiIndex according to the following rules: - If `level` is the first level of df.MultiIndex, do nothing - If `level` is the second level of df.MultiIndex, swap the level of index. NOTE: the number of levels of df.MultiIndex should be 2 Parameters ---...
convert_index_format
python
microsoft/qlib
qlib/data/dataset/utils.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/utils.py
MIT
def init_task_handler(task: dict) -> DataHandler: """ initialize the handler part of the task **inplace** Parameters ---------- task : dict the task to be handled Returns ------- Union[DataHandler, None]: returns """ # avoid recursive import from .handler im...
initialize the handler part of the task **inplace** Parameters ---------- task : dict the task to be handled Returns ------- Union[DataHandler, None]: returns
init_task_handler
python
microsoft/qlib
qlib/data/dataset/utils.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/utils.py
MIT
def setup_data(self, **kwargs): """ Setup the data. We split the setup_data function for following situation: - User have a Dataset object with learned status on disk. - User load the Dataset object from the disk. - User call `setup_data` to load new data. - ...
Setup the data. We split the setup_data function for following situation: - User have a Dataset object with learned status on disk. - User load the Dataset object from the disk. - User call `setup_data` to load new data. - User prepare data for model based on previo...
setup_data
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def prepare(self, **kwargs) -> object: """ The type of dataset depends on the model. (It could be pd.DataFrame, pytorch.DataLoader, etc.) The parameters should specify the scope for the prepared data The method should: - process the data - return the processed data ...
The type of dataset depends on the model. (It could be pd.DataFrame, pytorch.DataLoader, etc.) The parameters should specify the scope for the prepared data The method should: - process the data - return the processed data Returns ------- object: ...
prepare
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def __init__( self, handler: Union[Dict, DataHandler], segments: Dict[Text, Tuple], fetch_kwargs: Dict = {}, **kwargs, ): """ Setup the underlying data. Parameters ---------- handler : Union[dict, DataHandler] handler could...
Setup the underlying data. Parameters ---------- handler : Union[dict, DataHandler] handler could be: - instance of `DataHandler` - config of `DataHandler`. Please refer to `DataHandler` segments : dict Describe the options to...
__init__
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def config(self, handler_kwargs: dict = None, **kwargs): """ Initialize the DatasetH Parameters ---------- handler_kwargs : dict Config of DataHandler, which could include the following arguments: - arguments of DataHandler.conf_data, such as 'instrument...
Initialize the DatasetH Parameters ---------- handler_kwargs : dict Config of DataHandler, which could include the following arguments: - arguments of DataHandler.conf_data, such as 'instruments', 'start_time' and 'end_time'. kwargs : dict ...
config
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def setup_data(self, handler_kwargs: dict = None, **kwargs): """ Setup the Data Parameters ---------- handler_kwargs : dict init arguments of DataHandler, which could include the following arguments: - init_type : Init Type of Handler - enab...
Setup the Data Parameters ---------- handler_kwargs : dict init arguments of DataHandler, which could include the following arguments: - init_type : Init Type of Handler - enable_cache : whether to enable cache
setup_data
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _prepare_seg(self, slc, **kwargs): """ Give a query, retrieve the according data Parameters ---------- slc : please refer to the docs of `prepare` NOTE: it may not be an instance of slice. It may be a segment of `segments` from `def prepare` """ ...
Give a query, retrieve the according data Parameters ---------- slc : please refer to the docs of `prepare` NOTE: it may not be an instance of slice. It may be a segment of `segments` from `def prepare`
_prepare_seg
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def prepare( self, segments: Union[List[Text], Tuple[Text], Text, slice, pd.Index], col_set=DataHandler.CS_ALL, data_key=DataHandlerLP.DK_I, **kwargs, ) -> Union[List[pd.DataFrame], pd.DataFrame]: """ Prepare the data for learning and inference. Param...
Prepare the data for learning and inference. Parameters ---------- segments : Union[List[Text], Tuple[Text], Text, slice] Describe the scope of the data to be prepared Here are some examples: - 'train' - ['train', 'valid'] col_...
prepare
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _get_extrema(segments, idx: int, cmp: Callable, key_func=pd.Timestamp): """it will act like sort and return the max value or None""" candidate = None for k, seg in segments.items(): point = seg[idx] if point is None: # None indicates unbounded, return ...
it will act like sort and return the max value or None
_get_extrema
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def __init__( self, data: pd.DataFrame, start, end, step_len: int, fillna_type: str = "none", dtype=None, flt_data=None, ): """ Build a dataset which looks like torch.data.utils.Dataset. Parameters ---------- da...
Build a dataset which looks like torch.data.utils.Dataset. Parameters ---------- data : pd.DataFrame The raw tabular data whose index order is <"datetime", "instrument"> start : The indexable start time end : The indexable end time ...
__init__
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def build_index(data: pd.DataFrame) -> Tuple[pd.DataFrame, dict]: """ The relation of the data Parameters ---------- data : pd.DataFrame A DataFrame with index in order <instrument, datetime> RSQR5 RESI5 WVMA5 LABEL0 ...
The relation of the data Parameters ---------- data : pd.DataFrame A DataFrame with index in order <instrument, datetime> RSQR5 RESI5 WVMA5 LABEL0 instrument datetime SH600000 2017-01-03 0.016389 ...
build_index
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _get_indices(self, row: int, col: int) -> np.array: """ get series indices of self.data_arr from the row, col indices of self.idx_df Parameters ---------- row : int the row in self.idx_df col : int the col in self.idx_df Returns ...
get series indices of self.data_arr from the row, col indices of self.idx_df Parameters ---------- row : int the row in self.idx_df col : int the col in self.idx_df Returns ------- np.array: The indices of data of the...
_get_indices
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _get_row_col(self, idx) -> Tuple[int]: """ get the col index and row index of a given sample index in self.idx_df Parameters ---------- idx : the input of `__getitem__` Returns ------- Tuple[int]: the row and col index ...
get the col index and row index of a given sample index in self.idx_df Parameters ---------- idx : the input of `__getitem__` Returns ------- Tuple[int]: the row and col index
_get_row_col
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def __getitem__(self, idx: Union[int, Tuple[object, str], List[int]]): """ # We have two method to get the time-series of a sample tsds is a instance of TSDataSampler # 1) sample by int index directly tsds[len(tsds) - 1] # 2) sample by <datetime,instrument> index ...
# We have two method to get the time-series of a sample tsds is a instance of TSDataSampler # 1) sample by int index directly tsds[len(tsds) - 1] # 2) sample by <datetime,instrument> index tsds['2016-12-31', "SZ300315"] # The return value will be similar to th...
__getitem__
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _prepare_seg(self, slc: slice, **kwargs) -> TSDataSampler: """ split the _prepare_raw_seg is to leave a hook for data preprocessing before creating processing data NOTE: TSDatasetH only support slc segment on datetime !!! """ dtype = kwargs.pop("dtype", None) if not i...
split the _prepare_raw_seg is to leave a hook for data preprocessing before creating processing data NOTE: TSDatasetH only support slc segment on datetime !!!
_prepare_seg
python
microsoft/qlib
qlib/data/dataset/__init__.py
https://github.com/microsoft/qlib/blob/master/qlib/data/dataset/__init__.py
MIT
def _freq_file(self) -> str: """the freq to read from file""" if not hasattr(self, "_freq_file_cache"): freq = Freq(self.freq) if freq not in self.support_freq: # NOTE: uri # 1. If `uri` does not exist # - Get the `min_uri` ...
the freq to read from file
_freq_file
python
microsoft/qlib
qlib/data/storage/file_storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/file_storage.py
MIT
def __delitem__(self, i) -> None: """ Raises ------ ValueError If the data(storage) does not exist, raise ValueError """ raise NotImplementedError( "Subclass of CalendarStorage must implement `__delitem__(i: int)`/`__delitem__(s: slice)` method" ...
Raises ------ ValueError If the data(storage) does not exist, raise ValueError
__delitem__
python
microsoft/qlib
qlib/data/storage/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/storage.py
MIT
def __getitem__(self, i) -> CalVT: """ Raises ------ ValueError If the data(storage) does not exist, raise ValueError """ raise NotImplementedError( "Subclass of CalendarStorage must implement `__getitem__(i: int)`/`__getitem__(s: slice)` method...
Raises ------ ValueError If the data(storage) does not exist, raise ValueError
__getitem__
python
microsoft/qlib
qlib/data/storage/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/storage.py
MIT
def rebase(self, start_index: int = None, end_index: int = None): """Rebase the start_index and end_index of the FeatureStorage. start_index and end_index are closed intervals: [start_index, end_index] Examples --------- .. code-block:: feature: ...
Rebase the start_index and end_index of the FeatureStorage. start_index and end_index are closed intervals: [start_index, end_index] Examples --------- .. code-block:: feature: 3 4 4 5 ...
rebase
python
microsoft/qlib
qlib/data/storage/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/storage.py
MIT
def __getitem__(self, s: slice) -> pd.Series: """x.__getitem__(slice(start: int, stop: int, step: int)) <==> x[start:stop:step] Returns ------- pd.Series(values, index=pd.RangeIndex(start, len(values)) """
x.__getitem__(slice(start: int, stop: int, step: int)) <==> x[start:stop:step] Returns ------- pd.Series(values, index=pd.RangeIndex(start, len(values))
__getitem__
python
microsoft/qlib
qlib/data/storage/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/storage.py
MIT
def __getitem__(self, i) -> Union[Tuple[int, float], pd.Series]: """x.__getitem__(y) <==> x[y] Notes ------- if data(storage) does not exist: if isinstance(i, int): return (None, None) if isinstance(i, slice): # return empty pd.Se...
x.__getitem__(y) <==> x[y] Notes ------- if data(storage) does not exist: if isinstance(i, int): return (None, None) if isinstance(i, slice): # return empty pd.Series return pd.Series(dtype=np.float32)
__getitem__
python
microsoft/qlib
qlib/data/storage/storage.py
https://github.com/microsoft/qlib/blob/master/qlib/data/storage/storage.py
MIT
def begin_task_train(task_config: dict, experiment_name: str, recorder_name: str = None) -> Recorder: """ Begin task training to start a recorder and save the task config. Args: task_config (dict): the config of a task experiment_name (str): the name of experiment recorder_name (str...
Begin task training to start a recorder and save the task config. Args: task_config (dict): the config of a task experiment_name (str): the name of experiment recorder_name (str): the given name will be the recorder name. None for using rid. Returns: Recorder: the model re...
begin_task_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def end_task_train(rec: Recorder, experiment_name: str) -> Recorder: """ Finish task training with real model fitting and saving. Args: rec (Recorder): the recorder will be resumed experiment_name (str): the name of experiment Returns: Recorder: the model recorder """ w...
Finish task training with real model fitting and saving. Args: rec (Recorder): the recorder will be resumed experiment_name (str): the name of experiment Returns: Recorder: the model recorder
end_task_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def task_train(task_config: dict, experiment_name: str, recorder_name: str = None) -> Recorder: """ Task based training, will be divided into two steps. Parameters ---------- task_config : dict The config of a task. experiment_name: str The name of experiment recorder_name: ...
Task based training, will be divided into two steps. Parameters ---------- task_config : dict The config of a task. experiment_name: str The name of experiment recorder_name: str The name of recorder Returns ---------- Recorder: The instance of the recorder...
task_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def __init__( self, experiment_name: Optional[str] = None, train_func: Callable = task_train, call_in_subproc: bool = False, default_rec_name: Optional[str] = None, ): """ Init TrainerR. Args: experiment_name (str, optional): the default n...
Init TrainerR. Args: experiment_name (str, optional): the default name of experiment. train_func (Callable, optional): default training method. Defaults to `task_train`. call_in_subproc (bool): call the process in subprocess to force memory release
__init__
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def train(self, tasks: list, train_func: Callable = None, experiment_name: str = None, **kwargs) -> List[Recorder]: """ Given a list of `tasks` and return a list of trained Recorder. The order can be guaranteed. Args: tasks (list): a list of definitions based on `task` dict ...
Given a list of `tasks` and return a list of trained Recorder. The order can be guaranteed. Args: tasks (list): a list of definitions based on `task` dict train_func (Callable): the training method which needs at least `tasks` and `experiment_name`. None for the default trainin...
train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def end_train(self, models: list, **kwargs) -> List[Recorder]: """ Set STATUS_END tag to the recorders. Args: models (list): a list of trained recorders. Returns: List[Recorder]: the same list as the param. """ if isinstance(models, Recorder): ...
Set STATUS_END tag to the recorders. Args: models (list): a list of trained recorders. Returns: List[Recorder]: the same list as the param.
end_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def __init__( self, experiment_name: str = None, train_func=begin_task_train, end_train_func=end_task_train, **kwargs ): """ Init TrainerRM. Args: experiment_name (str): the default name of experiment. train_func (Callable, optional): default train method. De...
Init TrainerRM. Args: experiment_name (str): the default name of experiment. train_func (Callable, optional): default train method. Defaults to `begin_task_train`. end_train_func (Callable, optional): default end_train method. Defaults to `end_task_train`.
__init__
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def end_train(self, models, end_train_func=None, experiment_name: str = None, **kwargs) -> List[Recorder]: """ Given a list of Recorder and return a list of trained Recorder. This class will finish real data loading and model fitting. Args: models (list): a list of Recorder,...
Given a list of Recorder and return a list of trained Recorder. This class will finish real data loading and model fitting. Args: models (list): a list of Recorder, the tasks have been saved to them end_train_func (Callable, optional): the end_train method which needs a...
end_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def __init__( self, experiment_name: str = None, task_pool: str = None, train_func=task_train, skip_run_task: bool = False, default_rec_name: Optional[str] = None, ): """ Init TrainerR. Args: experiment_name (str): the default name...
Init TrainerR. Args: experiment_name (str): the default name of experiment. task_pool (str): task pool name in TaskManager. None for use same name as experiment_name. train_func (Callable, optional): default training method. Defaults to `task_train`. ski...
__init__
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def train( self, tasks: list, train_func: Callable = None, experiment_name: str = None, before_status: str = TaskManager.STATUS_WAITING, after_status: str = TaskManager.STATUS_DONE, default_rec_name: Optional[str] = None, **kwargs, ) -> List[Recorder]:...
Given a list of `tasks` and return a list of trained Recorder. The order can be guaranteed. This method defaults to a single process, but TaskManager offered a great way to parallel training. Users can customize their train_func to realize multiple processes or even multiple machines. ...
train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def end_train(self, recs: list, **kwargs) -> List[Recorder]: """ Set STATUS_END tag to the recorders. Args: recs (list): a list of trained recorders. Returns: List[Recorder]: the same list as the param. """ if isinstance(recs, Recorder): ...
Set STATUS_END tag to the recorders. Args: recs (list): a list of trained recorders. Returns: List[Recorder]: the same list as the param.
end_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def worker( self, train_func: Callable = None, experiment_name: str = None, ): """ The multiprocessing method for `train`. It can share a same task_pool with `train` and can run in other progress or other machines. Args: train_func (Callable): the trainin...
The multiprocessing method for `train`. It can share a same task_pool with `train` and can run in other progress or other machines. Args: train_func (Callable): the training method which needs at least `tasks` and `experiment_name`. None for the default training method. experim...
worker
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def __init__( self, experiment_name: str = None, task_pool: str = None, train_func=begin_task_train, end_train_func=end_task_train, skip_run_task: bool = False, **kwargs, ): """ Init DelayTrainerRM. Args: experiment_name (s...
Init DelayTrainerRM. Args: experiment_name (str): the default name of experiment. task_pool (str): task pool name in TaskManager. None for use same name as experiment_name. train_func (Callable, optional): default train method. Defaults to `begin_task_train`. ...
__init__
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def train(self, tasks: list, train_func=None, experiment_name: str = None, **kwargs) -> List[Recorder]: """ Same as `train` of TrainerRM, after_status will be STATUS_PART_DONE. Args: tasks (list): a list of definition based on `task` dict train_func (Callable): the train...
Same as `train` of TrainerRM, after_status will be STATUS_PART_DONE. Args: tasks (list): a list of definition based on `task` dict train_func (Callable): the train method which need at least `tasks` and `experiment_name`. Defaults to None for using self.train_func. ...
train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def end_train(self, recs, end_train_func=None, experiment_name: str = None, **kwargs) -> List[Recorder]: """ Given a list of Recorder and return a list of trained Recorder. This class will finish real data loading and model fitting. Args: recs (list): a list of Recorder, the...
Given a list of Recorder and return a list of trained Recorder. This class will finish real data loading and model fitting. Args: recs (list): a list of Recorder, the tasks have been saved to them. end_train_func (Callable, optional): the end_train method which need at ...
end_train
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def worker(self, end_train_func=None, experiment_name: str = None): """ The multiprocessing method for `end_train`. It can share a same task_pool with `end_train` and can run in other progress or other machines. Args: end_train_func (Callable, optional): the end_train method which n...
The multiprocessing method for `end_train`. It can share a same task_pool with `end_train` and can run in other progress or other machines. Args: end_train_func (Callable, optional): the end_train method which need at least `recorders` and `experiment_name`. Defaults to None for using self...
worker
python
microsoft/qlib
qlib/model/trainer.py
https://github.com/microsoft/qlib/blob/master/qlib/model/trainer.py
MIT
def __call__(self, ensemble_dict: dict) -> pd.DataFrame: """using sample: from qlib.model.ens.ensemble import AverageEnsemble pred_res['new_key_name'] = AverageEnsemble()(predict_dict) Parameters ---------- ensemble_dict : dict Dictionary you want to ensemble...
using sample: from qlib.model.ens.ensemble import AverageEnsemble pred_res['new_key_name'] = AverageEnsemble()(predict_dict) Parameters ---------- ensemble_dict : dict Dictionary you want to ensemble Returns ------- pd.DataFrame T...
__call__
python
microsoft/qlib
qlib/model/ens/ensemble.py
https://github.com/microsoft/qlib/blob/master/qlib/model/ens/ensemble.py
MIT