code: def factor_rank_autocorrelation(factor_data, period=1):
      """
      Computes autocorrelation of mean factor ranks in specified time spans.
      We must compare period to period factor ranks rather than factor values
      to account for systematic shifts in the factor values of all names or names
      within a group. This metric is useful for measuring the turnover of a
      factor. If the value of a factor for each name changes randomly from period
      to period, we'd expect an autocorrelation of 0.
  
      Parameters
      ----------
      factor_data : pd.DataFrame - MultiIndex
          A MultiIndex DataFrame indexed by date (level 0) and asset (level 1),
          containing the values for a single alpha factor, forward returns for
          each period, 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
      period: int, optional
          Number of days over which to calculate the turnover.
  
      Returns
      -------
      autocorr : pd.Series
          Rolling 1 period (defined by time_rule) autocorrelation of
          factor values.
      """
      grouper = [factor_data.index.get_level_values("date")]
  
      ranks = factor_data.groupby(grouper)["factor"].rank()
  
      asset_factor_rank = ranks.reset_index().pivot(
          index="date", columns="asset", values="factor"
      )
  
      asset_shifted = asset_factor_rank.shift(period)
  
      autocorr = asset_factor_rank.corrwith(asset_shifted, axis=1)
      autocorr.name = period
      return autocorr
  
imports: import pandas
  import numpy
  import warnings
  import empyrical
  from pandas.tseries.offsets import BDay
  from scipy import stats
  from statsmodels.regression.linear_model import OLS
  from statsmodels.tools.tools import add_constant
  from .None import utils
label_desc: Use image node_id 11 for calling a global function with example usage: factor_rank_autocorrelation(factor_data, period) and returns: autocorr