code: def _create_ts_slices(index, seq_len):
      """
      create time series slices from pandas index
  
      Args:
          index (pd.MultiIndex): pandas multiindex with <instrument, datetime> order
          seq_len (int): sequence length
      """
      assert isinstance(index, pd.MultiIndex), "unsupported index type"
      assert seq_len > 0, "sequence length should be larger than 0"
      assert index.is_monotonic_increasing, "index should be sorted"
  
      # number of dates for each instrument
      sample_count_by_insts = (
          index.to_series().groupby(level=0).size().values
      )
  
      # start index for each instrument
      start_index_of_insts = np.roll(
          np.cumsum(sample_count_by_insts), 1
      )
      start_index_of_insts[0] = 0
  
      # all the [start, stop) indices of features
      # features between [start, stop) will be used to predict label at `stop - 1`
      slices = []
      for cur_loc, cur_cnt in zip(
          start_index_of_insts, sample_count_by_insts
      ):
          for stop in range(1, cur_cnt + 1):
              end = cur_loc + stop
              start = max(end - seq_len, 0)
              slices.append(slice(start, end))
      slices = np.array(slices, dtype="object")
  
      assert len(slices) == len(index)  # the i-th slice = index[i]
  
      return slices
  
imports: import copy
  import torch
  import warnings
  import numpy
  import pandas
  from qlib.data.dataset import DatasetH
label_desc: Use image node_id 2 for calling a global function with example usage: _create_ts_slices(index, seq_len) and returns: slices