code: def gpd_risk_estimates_aligned(returns, var_p=0.01):
      """Estimate VaR and ES using the Generalized Pareto Distribution (GPD)
  
          Parameters
          ----------
          returns : pd.Series or np.ndarray
              Daily returns of the strategy, noncumulative.
              - See full explanation in :func:`~empyrical.stats.cum_returns`.
          var_p : float
              The percentile to use for estimating the VaR and ES
  
          Returns
          -------
          [threshold, scale_param, shape_param, var_estimate, es_estimate]
              : list[float]
              threshold - the threshold use to cut off exception tail losses
              scale_param - a parameter (often denoted by sigma, capturing the
                  scale, related to variance)
              shape_param - a parameter (often denoted by xi, capturing the shape or
                  type of the distribution)
              var_estimate - an estimate for the VaR for the given percentile
              es_estimate - an estimate for the ES for the given percentile
  
          Note
          ----
          seealso::
          `An Application of Extreme Value Theory for
      Measuring Risk <https://link.springer.com/article/10.1007/s10614-006-9025-7>`
              A paper describing how to use the Generalized Pareto
              Distribution to estimate VaR and ES.
      """
      result = np.zeros(5)
      if not len(returns) < 3:
          DEFAULT_THRESHOLD = 0.2
          MINIMUM_THRESHOLD = 0.000000001
  
          try:
              returns_array = pd.Series(returns).to_numpy()
          except AttributeError:
              # while zipline requires support for pandas < 0.25
              returns_array = pd.Series(returns).as_matrix()
  
          flipped_returns = -1 * returns_array
          losses = flipped_returns[flipped_returns > 0]
          threshold = DEFAULT_THRESHOLD
          finished = False
          scale_param = 0
          shape_param = 0
          while not finished and threshold > MINIMUM_THRESHOLD:
              losses_beyond_threshold = losses[losses >= threshold]
              param_result = gpd_loglikelihood_minimizer_aligned(
                  losses_beyond_threshold
              )
              if (
                  param_result[0] is not False
                  and param_result[1] is not False
              ):
                  scale_param = param_result[0]
                  shape_param = param_result[1]
                  var_estimate = gpd_var_calculator(
                      threshold,
                      scale_param,
                      shape_param,
                      var_p,
                      len(losses),
                      len(losses_beyond_threshold),
                  )
                  # non-negative shape parameter is required for fat tails
                  # non-negative VaR estimate is required for loss of some kind
                  if shape_param > 0 and var_estimate > 0:
                      finished = True
              if not finished:
                  threshold = threshold / 2
          if finished:
              es_estimate = gpd_es_calculator(
                  var_estimate, threshold, scale_param, shape_param
              )
              result = np.array(
                  [
                      threshold,
                      scale_param,
                      shape_param,
                      var_estimate,
                      es_estimate,
                  ]
              )
      if isinstance(returns, pd.Series):
          result = pd.Series(result)
      return result
  
imports: from __future__ import division
  import math
  import pandas
  import numpy
  from math import pow
  from scipy import stats, optimize
  from six import iteritems
  from sys import float_info
  from .utils import nanmean, nanstd, nanmin, up, down, roll, rolling_window
  from .periods import ANNUALIZATION_FACTORS, APPROX_BDAYS_PER_YEAR
  from .periods import DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY
label_desc: Use image node_id 35 for calling a global function with example usage: gpd_risk_estimates_aligned(returns, var_p) and returns: result