docstr: Internal method that pre-calculates the benchmark return series for
  use in the simulation.
  
  Parameters
  ----------
  asset:  Asset to use
  
  trading_calendar: TradingCalendar
  
  trading_days: pd.DateTimeIndex
  
  data_portal: DataPortal
  
  Notes
  -----
  If the benchmark asset started trading after the simulation start,
  or finished trading before the simulation end, exceptions are raised.
  
  If the benchmark asset started trading the same day as the simulation
  start, the first available minute price on that day is used instead
  of the previous close.
  
  We use history to get an adjusted price history for each day's close,
  as of the look-back date (the last day of the simulation).  Prices are
  fully adjusted for dividends, splits, and mergers.
  
  Returns
  -------
  A pd.Series, indexed by trading day, whose values represent the %
  change from close to close.
docstr_tok: ["Internal","method","that","pre-calculates","the","benchmark","return","series","for","use","in","the","simulation",".","Parameters","--","--","--","--","--","asset",":","Asset","to","use","trading_calendar",":","TradingCalendar","trading_days",":","pd.DateTimeIndex","data_portal",":","DataPortal","Notes","--","--","-","If","the","benchmark","asset","started","trading","after","the","simulation","start",",","or","finished","trading","before","the","simulation","end",",","exceptions","are","raised",".","If","the","benchmark","asset","started","trading","the","same","day","as","the","simulation","start",",","the","first","available","minute","price","on","that","day","is","used","instead","of","the","previous","close",".","We","use","history","to","get","an","adjusted","price","history","for","each","day","'s","close",",","as","of","the","look-back","date","(","the","last","day","of","the","simulation",")",".","Prices","are","fully","adjusted","for","dividends",",","splits",",","and","mergers",".","Returns","--","--","--","-","A","pd.Series",",","indexed","by","trading","day",",","whose","values","represent","the","%","change","from","close","to","close","."]
code: def _initialize_precalculated_series(
      self, asset, trading_calendar, trading_days, data_portal
  ):
      """
      Internal method that pre-calculates the benchmark return series for
      use in the simulation.
  
      Parameters
      ----------
      asset:  Asset to use
  
      trading_calendar: TradingCalendar
  
      trading_days: pd.DateTimeIndex
  
      data_portal: DataPortal
  
      Notes
      -----
      If the benchmark asset started trading after the simulation start,
      or finished trading before the simulation end, exceptions are raised.
  
      If the benchmark asset started trading the same day as the simulation
      start, the first available minute price on that day is used instead
      of the previous close.
  
      We use history to get an adjusted price history for each day's close,
      as of the look-back date (the last day of the simulation).  Prices are
      fully adjusted for dividends, splits, and mergers.
  
      Returns
      -------
      A pd.Series, indexed by trading day, whose values represent the %
      change from close to close.
      """
      if self.emission_rate == "minute":
          minutes = trading_calendar.minutes_for_sessions_in_range(
              self.sessions[0], self.sessions[-1]
          )
          benchmark_series = data_portal.get_history_window(
              [asset],
              minutes[-1],
              bar_count=len(minutes) + 1,
              frequency="1m",
              field="price",
              data_frequency=self.emission_rate,
              ffill=True,
          )[asset]
  
          return benchmark_series.pct_change()[1:]
      else:
          start_date = asset.start_date
          if start_date < trading_days[0]:
              # get the window of close prices for benchmark_asset from the
              # last trading day of the simulation, going up to one day
              # before the simulation start day (so that we can get the %
              # change on day 1)
              benchmark_series = data_portal.get_history_window(
                  [asset],
                  trading_days[-1],
                  bar_count=len(trading_days) + 1,
                  frequency="1d",
                  field="price",
                  data_frequency=self.emission_rate,
                  ffill=True,
              )[asset]
              return benchmark_series.pct_change()[1:]
          elif start_date == trading_days[0]:
              # Attempt to handle case where stock data starts on first
              # day, in this case use the open to close return.
              benchmark_series = data_portal.get_history_window(
                  [asset],
                  trading_days[-1],
                  bar_count=len(trading_days),
                  frequency="1d",
                  field="price",
                  data_frequency=self.emission_rate,
                  ffill=True,
              )[asset]
  
              # get a minute history window of the first day
              first_open = data_portal.get_spot_value(
                  asset, "open", trading_days[0], "daily"
              )
              first_close = data_portal.get_spot_value(
                  asset, "close", trading_days[0], "daily"
              )
  
              first_day_return = (first_close - first_open) / first_open
  
              returns = benchmark_series.pct_change()[:]
              returns[0] = first_day_return
              return returns
  
file_path: catalyst/catalyst/sources/benchmark_source.py
imports: import pandas
  from catalyst.errors import InvalidBenchmarkAsset, BenchmarkAssetNotAvailableTooEarly, BenchmarkAssetNotAvailableTooLate
label_desc: Use image node_id 5 for calling the BenchmarkSource obj's underlying member method code with example usage: obj._initialize_precalculated_series(asset, trading_calendar, trading_days, data_portal) and returns: benchmark_series, benchmark_series, returns