code: def activeshare(fund, idx, in_format="num"):
      
  
      if not (fund.index.is_unique) and (idx.index.is_unique):
          raise ValueError("Inputs must have unique indices.")
      if isinstance(fund, pd.DataFrame):
          cols = fund.columns
      fund = fund * NUMTODEC[in_format]
      idx = idx * NUMTODEC[in_format]
  
      union = fund.index.union(idx.index)
      fund = fund.reindex(union, fill_value=0.0).values
      idx = idx.reindex(union, fill_value=0.0).values
  
      if fund.ndim == 1:
          # Resulting active share will be a scalar
          diff = fund - idx
      else:
          diff = fund - idx[:, None]
      act_sh = np.sum(np.abs(diff) * 0.5, axis=0)
      if isinstance(act_sh, np.ndarray):
          act_sh = pd.Series(act_sh, index=cols)
      return act_sh
docs: Compute the active ahare of a fund versus an index.
  
      Formula is 0.5 * sum(abs(w_fund - w_idx)).
  
      Parameters
      ----------
      fund: {pd.Series, pd.DataFrame}
          The fund's holdings, with tickers as the Index and weights as
          values.  If a DataFrame, each column is a ticker/portfolio.
      idx: pd.Series
          The benchmark portfolio, with tickers as the Index and weights
          as values.
      in_format: {'num', 'dec'}
          Decimal notation of the inputs.  "num" means 0.5% is denoted 0.5;
          "dec" means 0.5% is denoted 0.005.
  
      Returns
      -------
      act_sh : pd.Series or pd.DataFrame
          The dimension will be one-lower than that of `fund`.
          If `fund` is a Series, the result is a scalar value.
          If `fund` is a DataFrame, the result is a Series, with
          the columns of `fund` as the resulting Index.
  
      .. _Cremers & Petajisto, 'How Active Is Your Fund Manager?', 2009