code: def generate_cutoffs(df, horizon, initial, period):
      """Generate cutoff dates
  
      Parameters
      ----------
      df: pd.DataFrame with historical data.
      horizon: pd.Timedelta forecast horizon.
      initial: pd.Timedelta window of the initial forecast period.
      period: pd.Timedelta simulated forecasts are done with this period.
  
      Returns
      -------
      list of pd.Timestamp
      """
      # Last cutoff is 'latest date in data - horizon' date
      cutoff = df["ds"].max() - horizon
      if cutoff < df["ds"].min():
          raise ValueError("Less data than horizon.")
      result = [cutoff]
      while result[-1] >= min(df["ds"]) + initial:
          cutoff -= period
          # If data does not exist in data range (cutoff, cutoff + horizon]
          if not (
              (
                  (df["ds"] > cutoff) & (df["ds"] <= cutoff + horizon)
              ).any()
          ):
              # Next cutoff point is 'last date before cutoff in data - horizon'
              if cutoff > df["ds"].min():
                  closest_date = df[df["ds"] <= cutoff].max()["ds"]
                  cutoff = closest_date - horizon
              # else no data left, leave cutoff as is, it will be dropped.
          result.append(cutoff)
      result = result[:-1]
      if len(result) == 0:
          raise ValueError(
              "Less data than horizon after initial window. "
              "Make horizon or initial shorter."
          )
      logger.info(
          "Making {} forecasts with cutoffs between {} and {}".format(
              len(result), result[-1], result[0]
          )
      )
      return list(reversed(result))
  
imports: from __future__ import absolute_import, division, print_function
  import logging
  from tqdm.auto import tqdm
  from copy import deepcopy
  import concurrent.futures
  import numpy
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: generate_cutoffs(df, horizon, initial, period) and returns: list