MCPcopy
hub / github.com/microsoft/qlib / QlibDataLoader

Class QlibDataLoader

qlib/data/dataset/loader.py:153–227  ·  view source on GitHub ↗

Same as QlibDataLoader. The fields can be define by config

Source from the content-addressed store, hash-verified

151
152
153class QlibDataLoader(DLWParser):
154 """Same as QlibDataLoader. The fields can be define by config"""
155
156 def __init__(
157 self,
158 config: Tuple[list, tuple, dict],
159 filter_pipe: List = None,
160 swap_level: bool = True,
161 freq: Union[str, dict] = "day",
162 inst_processors: Union[dict, list] = None,
163 ):
164 """
165 Parameters
166 ----------
167 config : Tuple[list, tuple, dict]
168 Please refer to the doc of DLWParser
169 filter_pipe :
170 Filter pipe for the instruments
171 swap_level :
172 Whether to swap level of MultiIndex
173 freq: dict or str
174 If type(config) == dict and type(freq) == str, load config data using freq.
175 If type(config) == dict and type(freq) == dict, load config[<group_name>] data using freq[<group_name>]
176 inst_processors: dict | list
177 If inst_processors is not None and type(config) == dict; load config[<group_name>] data using inst_processors[<group_name>]
178 If inst_processors is a list, then it will be applied to all groups.
179 """
180 self.filter_pipe = filter_pipe
181 self.swap_level = swap_level
182 self.freq = freq
183
184 # sample
185 self.inst_processors = inst_processors if inst_processors is not None else {}
186 assert isinstance(
187 self.inst_processors, (dict, list)
188 ), f"inst_processors(={self.inst_processors}) must be dict or list"
189
190 super().__init__(config)
191
192 if self.is_group:
193 # check sample config
194 if isinstance(freq, dict):
195 for _gp in config.keys():
196 if _gp not in freq:
197 raise ValueError(f"freq(={freq}) missing group(={_gp})")
198 assert (
199 self.inst_processors
200 ), f"freq(={self.freq}), inst_processors(={self.inst_processors}) cannot be None/empty"
201
202 def load_group_df(
203 self,
204 instruments,
205 exprs: list,
206 names: list,
207 start_time: Union[str, pd.Timestamp] = None,
208 end_time: Union[str, pd.Timestamp] = None,
209 gp_name: str = None,
210 ) -> pd.DataFrame:

Callers 1

test_case2Method · 0.90

Calls

no outgoing calls

Tested by 1

test_case2Method · 0.72