code: def create_event_returns_tear_sheet(
      factor_data,
      returns,
      avgretplot=(5, 15),
      long_short=True,
      group_neutral=False,
      std_bar=True,
      by_group=False,
  ):
      """
      Creates a tear sheet to view the average cumulative returns for a
      factor within a window (pre and post event).
  
      Parameters
      ----------
      factor_data : pd.DataFrame - MultiIndex
          A MultiIndex Series indexed by date (level 0) and asset (level 1),
          containing the values for a single alpha factor, the factor
          quantile/bin that factor value belongs to and (optionally) the group
          the asset belongs to.
          - See full explanation in utils.get_clean_factor_and_forward_returns
      returns : pd.DataFrame
          A DataFrame indexed by date with assets in the columns containing daily
          returns.
          - See full explanation in utils.get_clean_factor_and_forward_returns
      avgretplot: tuple (int, int) - (before, after)
          If not None, plot quantile average cumulative returns
      long_short : bool
          Should this computation happen on a long short portfolio? if so then
          factor returns will be demeaned across the factor universe
      group_neutral : bool
          Should this computation happen on a group neutral portfolio? if so,
          returns demeaning will occur on the group level.
      std_bar : boolean, optional
          Show plots with standard deviation bars, one for each quantile
      by_group : bool
          If True, display graphs separately for each group.
      """
  
      before, after = avgretplot
  
      avg_cumulative_returns = (
          perf.average_cumulative_return_by_quantile(
              factor_data,
              returns,
              periods_before=before,
              periods_after=after,
              demeaned=long_short,
              group_adjust=group_neutral,
          )
      )
  
      num_quantiles = int(factor_data["factor_quantile"].max())
  
      vertical_sections = 1
      if std_bar:
          vertical_sections += ((num_quantiles - 1) // 2) + 1
      cols = 2 if num_quantiles != 1 else 1
      gf = GridFigure(rows=vertical_sections, cols=cols)
      plotting.plot_quantile_average_cumulative_return(
          avg_cumulative_returns,
          by_quantile=False,
          std_bar=False,
          ax=gf.next_row(),
      )
      if std_bar:
          ax_avg_cumulative_returns_by_q = [
              gf.next_cell() for _ in range(num_quantiles)
          ]
          plotting.plot_quantile_average_cumulative_return(
              avg_cumulative_returns,
              by_quantile=True,
              std_bar=True,
              ax=ax_avg_cumulative_returns_by_q,
          )
  
      plt.show()
      gf.close()
  
      if by_group:
          groups = factor_data["group"].unique()
          num_groups = len(groups)
          vertical_sections = ((num_groups - 1) // 2) + 1
          gf = GridFigure(rows=vertical_sections, cols=2)
  
          avg_cumret_by_group = (
              perf.average_cumulative_return_by_quantile(
                  factor_data,
                  returns,
                  periods_before=before,
                  periods_after=after,
                  demeaned=long_short,
                  group_adjust=group_neutral,
                  by_group=True,
              )
          )
  
          for group, avg_cumret in avg_cumret_by_group.groupby(
              level="group"
          ):
              avg_cumret.index = avg_cumret.index.droplevel("group")
              plotting.plot_quantile_average_cumulative_return(
                  avg_cumret,
                  by_quantile=False,
                  std_bar=False,
                  title=group,
                  ax=gf.next_cell(),
              )
  
          plt.show()
          gf.close()
  
file_path: alphalens/alphalens/tears.py
imports: import matplotlib.gridspec
  import matplotlib.pyplot
  import pandas
  import warnings
  from .None import plotting
  from .None import performance
  from .None import utils
label_desc: Use image node_id 6 for calling a global function with example usage: create_event_returns_tear_sheet(factor_data, returns, avgretplot, long_short, group_neutral, std_bar, by_group) without return types