N-step discounted return.
327849
def fixed_step_return(reward, value, length, discount, window):
  """"""
  timestep = tf.range(reward.shape[1].value)
  mask = tf.cast(timestep[None, :] < length[:, None], tf.float32)
  return_ = tf.zeros_like(reward)
  for _ in range(window):
    return_ += reward
    reward = discount * tf.concat(
        [reward[:, 1:], tf.zeros_like(reward[:, -1:])], 1)
  return_ += discount ** window * tf.concat(
      [value[:, window:], tf.zeros_like(value[:, -window:])], 1)
  return tf.check_numerics(tf.stop_gradient(mask * return_), 'return')
140264
def discount_bootstrap(rewards_buffer, dones_buffer, final_values, discount_factor, number_of_steps):
    
    true_value_buffer = torch.zeros_like(rewards_buffer)

    # discount/bootstrap off value fn
    current_value = final_values

    for i in reversed(range(number_of_steps)):
        current_value = rewards_buffer[i] + discount_factor * current_value * (1.0 - dones_buffer[i])
        true_value_buffer[i] = current_value

    return true_value_buffer
683466
protected function _applyDiscounts()
    {
        //apply discounts for brutto price
        $dDiscountedSum = $this->_getDiscountedProductsSum();

        $oUtils = \OxidEsales\Eshop\Core\Registry::getUtils();
        $dVatSum = 0;
        foreach ($this->_aDiscountedVats as $dVat) {
            $dVatSum += $oUtils->fRound($dVat, $this->_oCurrency);
        }

        $oNotDiscounted = $this->getNotDiscountProductsPrice();

        if ($this->isCalculationModeNetto()) {
            // netto view mode
            $this->setNettoSum($this->getProductsPrice()->getSum());
            $this->setBruttoSum($oNotDiscounted->getSum(false) + $dDiscountedSum + $dVatSum);
        } else {
            // brutto view mode
            $this->setNettoSum($oNotDiscounted->getSum() + $dDiscountedSum - $dVatSum);
            $this->setBruttoSum($this->getProductsPrice()->getSum(false));
        }
    }
820932
function(value, offset) {
    offset = offset || 1;
    var roundedValue = value;

    if (this.standard_deviation > 0.1) {
      var multiplier = Math.pow(10, -offset);
      roundedValue = Math.round(value * multiplier) / multiplier;

      if (roundedValue > this.min) {
        return this.round(value - this.step);
      }
    }
    return roundedValue;
  }
1049698
def _at_return(self, calculator, rule, scope, block):
        
        # TODO should assert this only happens within a @function
        ret = calculator.calculate(block.argument)
        raise SassReturn(ret)
532801
def optimize(self, to_buy, to_sell):
        '''
        
        '''
        allocations = {}

        # Process every stock the same way
        for s in to_buy:
            quantity = self.properties.get('buy_amount', 100)
            if s in self.properties.get('scale', {}):
                quantity *= self.properties['scale'][s]
            # Allocate defined amount to buy
            allocations[s] = int(quantity)

        # NOTE You must provide sell_amount if you want to short
        for s in to_sell:
            quantity = self.properties.get(
                'sell_amount', self.portfolio.positions[s].amount)
            if s in self.properties.get('scale', {}):
                quantity *= self.properties['scale'][s]
            # Allocate defined amount to buy
            allocations[s] = -int(quantity)

        # Defaults values
        e_ret = 0
        e_risk = 1
        return allocations, e_ret, e_risk
85609
function (discount, cb) {

		Discount.destroy(discount.id)
	    .exec(function (err, destroyedDiscounts){
	      if (err) return cb(err);
	      if (!destroyedDiscounts) return cb(null, null);
	      Discount.afterStripeCustomerDiscountDeleted(destroyedDiscounts[0], function(err, discount){
	      	cb(err, discount);
	      });
	    });
	}
1372855
def compute_discounts(self, precision=None):
        '''
        
        '''
        return sum([line.compute_discounts(precision) for line in self.__lines])
421530
def rollback(self, date):
        """"""
        if self.onOffset(date):
            return date
        else:
            return date - YearBegin(month=self.month)
1350636
def recurse(self, factory_meta, extras):
        """"""
        return self.__class__(factory_meta, extras, strategy=self.strategy)
994784
function step(x, a, p, q) {
      var temp, w;

      temp = p <= 0.5 ? gratio(a)(x) - p : q - gratioc(a)(x);
      temp /= r(a, x);
      w = (a - 1 - x) / 2;
      if (Math.max(Math.abs(temp), Math.abs(w * temp)) <= 0.1) {
         return x * (1 - (temp + w * temp * temp));
      }
      return x * (1 - temp);
   }
457364
def somenan(self, x, fun, p=0.1):
        """"""
        if np.random.rand(1) < p:
            return np.NaN
        else:
            return fun(x)
723133
def drawdowns(returns, geometric=True):
    
    wealth = 1. + returns_cumulative(returns, geometric=geometric, expanding=True)
    values = wealth.values
    if values.ndim == 2:
        ncols = values.shape[-1]
        values = np.vstack(([1.] * ncols, values))
        maxwealth = pd.expanding_max(values)[1:]
        dds = wealth / maxwealth - 1.
        dds[dds > 0] = 0  # Can happen if first returns are positive
        return dds
    elif values.ndim == 1:
        values = np.hstack(([1.], values))
        maxwealth = pd.expanding_max(values)[1:]
        dds = wealth / maxwealth - 1.
        dds[dds > 0] = 0  # Can happen if first returns are positive
        return dds
    else:
        raise ValueError('unable to process array with %s dimensions' % values.ndim)
105042
def get_transitions_forward_steps(self, indexes, forward_steps, discount_factor):
        
        return self.deque.get_transitions_forward_steps(indexes, forward_steps, discount_factor)
592270
def rolling_returns_cumulative(returns, window, min_periods=1, geometric=True):
    
    if geometric:
        rc = lambda x: (1. + x[np.isfinite(x)]).prod() - 1.
    else:
        rc = lambda x: (x[np.isfinite(x)]).sum()

    return pd.rolling_apply(returns, window, rc, min_periods=min_periods)
1676
def lambda_return(reward, value, length, discount, lambda_):
  """"""
  timestep = tf.range(reward.shape[1].value)
  mask = tf.cast(timestep[None, :] < length[:, None], tf.float32)
  sequence = mask * reward + discount * value * (1 - lambda_)
  discount = mask * discount * lambda_
  sequence = tf.stack([sequence, discount], 2)
  return_ = tf.reverse(tf.transpose(tf.scan(
      lambda agg, cur: cur[0] + cur[1] * agg,
      tf.transpose(tf.reverse(sequence, [1]), [1, 2, 0]),
      tf.zeros_like(value[:, -1]), 1, False), [1, 0]), [1])
  return tf.check_numerics(tf.stop_gradient(return_), 'return')
177680
def compute_discounts(self, precision=None):
        '''
        
        '''
        gross = self.compute_gross(precision)
        return min(gross,
                   sum([d.compute(gross, precision) for d in self.__discounts]))