code: def cum_returns(returns, starting_value=0, out=None):
      
      if len(returns) < 1:
          return returns.copy()
  
      nanmask = np.isnan(returns)
      if np.any(nanmask):
          returns = returns.copy()
          returns[nanmask] = 0
  
      allocated_output = out is None
      if allocated_output:
          out = np.empty_like(returns)
  
      np.add(returns, 1, out=out)
      out.cumprod(axis=0, out=out)
  
      if starting_value == 0:
          np.subtract(out, 1, out=out)
      else:
          np.multiply(out, starting_value, out=out)
  
      if allocated_output:
          if returns.ndim == 1 and isinstance(returns, pd.Series):
              out = pd.Series(out, index=returns.index)
          elif isinstance(returns, pd.DataFrame):
              out = pd.DataFrame(
                  out, index=returns.index, columns=returns.columns,
              )
  
      return out
docs: Compute cumulative returns from simple returns.
  
      Parameters
      ----------
      returns : pd.Series, np.ndarray, or pd.DataFrame
          Returns of the strategy as a percentage, noncumulative.
           - Time series with decimal returns.
           - Example::
  
              2015-07-16   -0.012143
              2015-07-17    0.045350
              2015-07-20    0.030957
              2015-07-21    0.004902
  
           - Also accepts two dimensional data. In this case, each column is
             cumulated.
  
      starting_value : float, optional
         The starting returns.
      out : array-like, optional
          Array to use as output buffer.
          If not passed, a new array will be created.
  
      Returns
      -------
      cumulative_returns : array-like
          Series of cumulative returns.