class_docstr: :Usage:
      Instantiate RiskMetricsCumulative once.
      Call update() method on each dt to update the metrics.
class_docstr_tok: [":","Usage",":","Instantiate","RiskMetricsCumulative","once",".","Call","update","(",")","method","on","each","dt","to","update","the","metrics","."]
code: def update(self, dt, algorithm_returns, benchmark_returns, leverage):
      warnings.filterwarnings("error")
  
      # Keep track of latest dt for use in to_dict and other methods
      # that report current state.
      self.latest_dt = dt
      dt_loc = self.cont_index.get_loc(dt)
      self.latest_dt_loc = dt_loc
  
      self.algorithm_returns_cont[dt_loc] = algorithm_returns
      self.algorithm_returns = self.algorithm_returns_cont[: dt_loc + 1]
  
      self.num_trading_days = len(self.algorithm_returns)
  
      if self.create_first_day_stats:
          if len(self.algorithm_returns) == 1:
              self.algorithm_returns = np.append(
                  0.0, self.algorithm_returns
              )
  
      try:
          self.algorithm_cumulative_returns[dt_loc] = cum_returns(
              self.algorithm_returns
          )[-1]
      except Exception as e:
          log.debug("unable to calculate cum returns: {}".format(e))
          self.algorithm_cumulative_returns[dt_loc] = np.nan
  
      algo_cumulative_returns_to_date = (
          self.algorithm_cumulative_returns[: dt_loc + 1]
      )
  
      self.mean_returns_cont[dt_loc] = (
          algo_cumulative_returns_to_date[dt_loc]
          / self.num_trading_days
      )
  
      self.mean_returns = self.mean_returns_cont[: dt_loc + 1]
  
      self.annualized_mean_returns_cont[dt_loc] = (
          self.mean_returns_cont[dt_loc] * 252
      )
  
      self.annualized_mean_returns = self.annualized_mean_returns_cont[
          : dt_loc + 1
      ]
  
      if self.create_first_day_stats:
          if len(self.mean_returns) == 1:
              self.mean_returns = np.append(0.0, self.mean_returns)
              self.annualized_mean_returns = np.append(
                  0.0, self.annualized_mean_returns
              )
  
      self.benchmark_returns_cont[dt_loc] = benchmark_returns
      self.benchmark_returns = self.benchmark_returns_cont[: dt_loc + 1]
  
      if self.create_first_day_stats:
          if len(self.benchmark_returns) == 1:
              self.benchmark_returns = np.append(
                  0.0, self.benchmark_returns
              )
  
      try:
          self.benchmark_cumulative_returns[dt_loc] = cum_returns(
              self.benchmark_returns
          )[-1]
      except Exception as e:
          log.debug(
              "unable to calculate benchmark cum returns: {}".format(e)
          )
          self.benchmark_cumulative_returns[dt_loc] = np.nan
  
      benchmark_cumulative_returns_to_date = (
          self.benchmark_cumulative_returns[: dt_loc + 1]
      )
  
      self.mean_benchmark_returns_cont[dt_loc] = (
          benchmark_cumulative_returns_to_date[dt_loc]
          / self.num_trading_days
      )
  
      self.mean_benchmark_returns = self.mean_benchmark_returns_cont[
          :dt_loc
      ]
  
      self.annualized_mean_benchmark_returns_cont[dt_loc] = (
          self.mean_benchmark_returns_cont[dt_loc] * 252
      )
  
      self.annualized_mean_benchmark_returns = (
          self.annualized_mean_benchmark_returns_cont[: dt_loc + 1]
      )
  
      self.algorithm_cumulative_leverages_cont[dt_loc] = leverage
      self.algorithm_cumulative_leverages = (
          self.algorithm_cumulative_leverages_cont[: dt_loc + 1]
      )
  
      if self.create_first_day_stats:
          if len(self.algorithm_cumulative_leverages) == 1:
              self.algorithm_cumulative_leverages = np.append(
                  0.0, self.algorithm_cumulative_leverages
              )
  
      if not len(self.algorithm_returns) and len(
          self.benchmark_returns
      ):
          message = "Mismatch between benchmark_returns ({bm_count}) and \
  algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
          message = message.format(
              bm_count=len(self.benchmark_returns),
              algo_count=len(self.algorithm_returns),
              start=self.start_session,
              end=self.end_session,
              dt=dt,
          )
          raise Exception(message)
  
      self.update_current_max()
      self.benchmark_volatility[dt_loc] = annual_volatility(
          self.benchmark_returns
      )
      self.algorithm_volatility[dt_loc] = annual_volatility(
          self.algorithm_returns
      )
  
      # caching the treasury rates for the minutely case is a
      # big speedup, because it avoids searching the treasury
      # curves on every minute.
      # In both minutely and daily, the daily curve is always used.
      treasury_end = dt.replace(hour=0, minute=0)
      if np.isnan(self.daily_treasury[treasury_end]):
          treasury_period_return = choose_treasury(
              self.treasury_curves,
              self.start_session,
              treasury_end,
              self.trading_calendar,
          )
          self.daily_treasury[treasury_end] = treasury_period_return
      self.treasury_period_return = self.daily_treasury[treasury_end]
      self.excess_returns[dt_loc] = (
          self.algorithm_cumulative_returns[dt_loc]
          - self.treasury_period_return
      )
  
      self.alpha[dt_loc], self.beta[dt_loc] = alpha_beta_aligned(
          self.algorithm_returns,
          self.benchmark_returns,
      )
      self.sharpe[dt_loc] = sharpe_ratio(
          self.algorithm_returns,
      )
  
      try:
          self.downside_risk[dt_loc] = downside_risk(
              self.algorithm_returns
          )
      except Exception as e:
          log.debug(
              "unable to calculate downside risk returns: {}".format(e)
          )
          self.downside_risk[dt_loc] = np.nan
  
      try:
          risk = self.downside_risk[dt_loc]
          self.sortino[dt_loc] = sortino_ratio(
              self.algorithm_returns, _downside_risk=risk
          )
      except Exception as e:
          log.debug(
              "unable to calculate benchmark cum returns: {}".format(e)
          )
          self.sortino[dt_loc] = np.nan
  
      self.information[dt_loc] = information_ratio(
          self.algorithm_returns,
          self.benchmark_returns,
      )
      try:
          self.max_drawdown = max_drawdown(self.algorithm_returns)
      except Exception as e:
          log.debug("unable to calculate max drawdown: {}".format(e))
          self.max_drawdown = np.nan
  
      self.max_drawdowns[dt_loc] = self.max_drawdown
      self.max_leverage = self.calculate_max_leverage()
      self.max_leverages[dt_loc] = self.max_leverage
  
      warnings.resetwarnings()
  
file_path: catalyst/catalyst/finance/risk/cumulative.py
imports: import functools
  import logbook
  import numpy
  import pandas
  from pandas.tseries.tools import normalize_date
  from six import iteritems
  from .risk import check_entry, choose_treasury
  from catalyst.patches.stats import alpha_beta_aligned, annual_volatility, downside_risk, information_ratio, max_drawdown, sharpe_ratio, sortino_ratio, cum_returns
  import warnings
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 2 for calling the RiskMetricsCumulative obj's underlying member method code with example usage: obj.update(dt, algorithm_returns, benchmark_returns, leverage) without return types