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

Method shift

qlib/workflow/task/utils.py:243–280  ·  view source on GitHub ↗

Shift the datetime of segment If there are None (which indicates unbounded index) in the segment, this method will return None. Parameters ---------- seg : datetime segment step : int rolling step rtype : str

(self, seg: tuple, step: int, rtype=SHIFT_SD)

Source from the content-addressed store, hash-verified

241 return index + step
242
243 def shift(self, seg: tuple, step: int, rtype=SHIFT_SD) -> tuple:
244 """
245 Shift the datetime of segment
246
247 If there are None (which indicates unbounded index) in the segment, this method will return None.
248
249 Parameters
250 ----------
251 seg :
252 datetime segment
253 step : int
254 rolling step
255 rtype : str
256 rolling type ("sliding" or "expanding")
257
258 Returns
259 --------
260 tuple: new segment
261
262 Raises
263 ------
264 KeyError:
265 shift will raise error if the index(both start and end) is out of self.cal
266 """
267 if isinstance(seg, tuple):
268 start_idx, end_idx = self.align_idx(seg[0], tp_type="start"), self.align_idx(seg[1], tp_type="end")
269 if rtype == self.SHIFT_SD:
270 start_idx = self._add_step(start_idx, step)
271 end_idx = self._add_step(end_idx, step)
272 elif rtype == self.SHIFT_EX:
273 end_idx = self._add_step(end_idx, step)
274 else:
275 raise NotImplementedError(f"This type of input is not supported")
276 if start_idx is not None and start_idx > len(self.cals):
277 raise KeyError("The segment is out of valid calendar")
278 return self.get(start_idx), self.get(end_idx)
279 else:
280 raise NotImplementedError(f"This type of input is not supported")
281
282
283def replace_task_handler_with_cache(task: dict, cache_dir: Union[str, Path] = ".") -> dict:

Callers 15

calc_changeMethod · 0.80
calc_changeMethod · 0.80
test_AbsMethod · 0.80
test_SignMethod · 0.80
get_shifted_labelFunction · 0.80
pred_autocorrFunction · 0.80
__init__Method · 0.80
_pred_autocorrFunction · 0.80
_pred_turnoverFunction · 0.80
_report_figureFunction · 0.80
_add_bench_to_positionFunction · 0.80
build_index_from_dataMethod · 0.80

Calls 3

align_idxMethod · 0.95
_add_stepMethod · 0.95
getMethod · 0.95

Tested by 2

test_AbsMethod · 0.64
test_SignMethod · 0.64