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 index.is_lexsorted(), "index should be sorted"
  
      # number of dates for each code
      sample_count_by_codes = (
          pd.Series(0, index=index).groupby(level=0).size().values
      )
  
      # start_index for each code
      start_index_of_codes = np.roll(
          np.cumsum(sample_count_by_codes), 1
      )
      start_index_of_codes[0] = 0
  
      # all the [start, stop) indices of features
      # features btw [start, stop) are used to predict the `stop - 1` label
      slices = []
      for cur_loc, cur_cnt in zip(
          start_index_of_codes, sample_count_by_codes
      ):
          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)
  
      return slices
  
imports: import copy
  import torch
  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