code: def risk_metric_period(cls,
                             start_session,
                             end_session,
                             algorithm_returns,
                             benchmark_returns,
                             algorithm_leverages):
          algorithm_returns = algorithm_returns[
              (algorithm_returns.index >= start_session) &
              (algorithm_returns.index <= end_session)
          ]
          benchmark_returns = benchmark_returns[
              (benchmark_returns.index >= start_session) &
              (benchmark_returns.index <= algorithm_returns.index[-1])
          ]
          benchmark_period_returns = ep.cum_returns(benchmark_returns).iloc[-1]
          algorithm_period_returns = ep.cum_returns(algorithm_returns).iloc[-1]
          alpha, beta = ep.alpha_beta_aligned(
              algorithm_returns.values,
              benchmark_returns.values,
          )
          sharpe = ep.sharpe_ratio(algorithm_returns)
          if pd.isnull(sharpe):
              sharpe = 0.0
          sortino = ep.sortino_ratio(
              algorithm_returns.values,
              _downside_risk=ep.downside_risk(algorithm_returns.values),
          )
          rval = {
              'algorithm_period_return': algorithm_period_returns,
              'benchmark_period_return': benchmark_period_returns,
              'treasury_period_return': 0,
              'excess_return': algorithm_period_returns,
              'alpha': alpha,
              'beta': beta,
              'sharpe': sharpe,
              'sortino': sortino,
              'period_label': end_session.strftime("%Y-%m"),
              'trading_days': len(benchmark_returns),
              'algo_volatility': ep.annual_volatility(algorithm_returns),
              'benchmark_volatility': ep.annual_volatility(benchmark_returns),
              'max_drawdown': ep.max_drawdown(algorithm_returns.values),
              'max_leverage': algorithm_leverages.max(),
          }
          return {
              k: (
                  None
                  if k != 'period_label' and not np.isfinite(v) else
                  v
              )
              for k, v in iteritems(rval)
          }