code: def calculate_metrics(self):
      warnings.filterwarnings("error")
  
      try:
          self.benchmark_period_returns = cum_returns(
              self.benchmark_returns
          ).iloc[-1]
      except Exception:
          # TODO: why is there an error
          self.benchmark_period_returns = 0
  
      self.algorithm_period_returns = cum_returns(
          self.algorithm_returns
      ).iloc[-1]
  
      if not self.algorithm_returns.index.equals(
          self.benchmark_returns.index
      ):
          message = "Mismatch between benchmark_returns ({bm_count}) and \
              algorithm_returns ({algo_count}) in range {start} : {end}"
          message = message.format(
              bm_count=len(self.benchmark_returns),
              algo_count=len(self.algorithm_returns),
              start=self._start_session,
              end=self._end_session,
          )
          raise Exception(message)
  
      self.num_trading_days = len(self.benchmark_returns)
  
      self.mean_algorithm_returns = (
          self.algorithm_returns.cumsum()
          / np.arange(1, self.num_trading_days + 1, dtype=np.float64)
      )
  
      self.benchmark_volatility = annual_volatility(
          self.benchmark_returns
      )
      self.algorithm_volatility = annual_volatility(
          self.algorithm_returns
      )
  
      self.treasury_period_return = choose_treasury(
          self.treasury_curves,
          self._start_session,
          self._end_session,
          self.trading_calendar,
      )
      self.sharpe = sharpe_ratio(
          self.algorithm_returns,
      )
      # The consumer currently expects a 0.0 value for sharpe in period,
      # this differs from cumulative which was np.nan.
      # When factoring out the sharpe_ratio, the different return types
      # were collapsed into `np.nan`.
      # TODO: Either fix consumer to accept `np.nan` or make the
      # `sharpe_ratio` return type configurable.
      # In the meantime, convert nan values to 0.0
      if pd.isnull(self.sharpe):
          self.sharpe = 0.0
      self.downside_risk = downside_risk(self.algorithm_returns.values)
  
      try:
          risk = self.downside_risk
          self.sortino = sortino_ratio(
              self.algorithm_returns.values,
              _downside_risk=risk,
          )
      except Exception:
          # TODO: what causes it to error out?
          self.sortino = 0
  
      self.information = information_ratio(
          self.algorithm_returns.values,
          self.benchmark_returns.values,
      )
      self.alpha, self.beta = alpha_beta_aligned(
          self.algorithm_returns.values,
          self.benchmark_returns.values,
      )
      self.excess_return = (
          self.algorithm_period_returns - self.treasury_period_return
      )
      self.max_drawdown = max_drawdown(self.algorithm_returns.values)
      self.max_leverage = self.calculate_max_leverage()
  
      warnings.resetwarnings()
  
file_path: catalyst/catalyst/finance/risk/period.py
imports: import functools
  import warnings
  import logbook
  from six import iteritems
  import numpy
  import pandas
  from .None import risk
  from .risk import check_entry
  from empyrical import alpha_beta_aligned, annual_volatility, downside_risk, information_ratio, sharpe_ratio, sortino_ratio
  from catalyst.patches.stats import max_drawdown, cum_returns
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 2 for calling the RiskMetricsPeriod obj's underlying member method code with example usage: obj.calculate_metrics() without return types