code: def downside_risk(returns,
                    required_return=0,
                    period=DAILY,
                    annualization=None,
                    out=None):
      allocated_output = out is None
      if allocated_output:
          out = np.empty(returns.shape[1:])
      returns_1d = returns.ndim == 1
      if len(returns) < 1:
          out[()] = np.nan
          if returns_1d:
              out = out.item()
          return out
      ann_factor = annualization_factor(period, annualization)
      downside_diff = np.clip(
          _adjust_returns(
              np.asanyarray(returns),
              np.asanyarray(required_return),
          ),
          np.NINF,
          0,
      )
      np.square(downside_diff, out=downside_diff)
      nanmean(downside_diff, axis=0, out=out)
      np.sqrt(out, out=out)
      np.multiply(out, np.sqrt(ann_factor), out=out)
      if returns_1d:
          out = out.item()
      elif isinstance(returns, pd.DataFrame):
          out = pd.Series(out, index=returns.columns)
      return out