Finds the effective permanent and transitory shocks this period by combining the aggregate
        and idiosyncratic shocks of each type.

        Parameters
        ----------
        None

        Returns
        -------
        None
773370
def getShocks(self):
        '''
        
        '''
        IndShockConsumerType.getShocks(self) # Update idiosyncratic shocks
        self.TranShkNow = self.TranShkNow*self.TranShkAggNow*self.wRteNow
        self.PermShkNow = self.PermShkNow*self.PermShkAggNow
1245139
private PeriodType withFieldRemoved(int indicesIndex, String name) {
        int fieldIndex = iIndices[indicesIndex];
        if (fieldIndex == -1) {
            return this;
        }
        
        DurationFieldType[] types = new DurationFieldType[size() - 1];
        for (int i = 0; i < iTypes.length; i++) {
            if (i < fieldIndex) {
                types[i] = iTypes[i];
            } else if (i > fieldIndex) {
                types[i - 1] = iTypes[i];
            }
        }
        
        int[] indices = new int[8];
        for (int i = 0; i < indices.length; i++) {
            if (i < indicesIndex) {
                indices[i] = iIndices[i];
            } else if (i > indicesIndex) {
                indices[i] = (iIndices[i] == -1 ? -1 : iIndices[i] - 1);
            } else {
                indices[i] = -1;
            }
        }
        return new PeriodType(getName() + name, types, indices);
    }
1013435
def _end_apply_index(self, dtindex):
        
        off = dtindex.to_perioddelta('D')

        base, mult = libfrequencies.get_freq_code(self.freqstr)
        base_period = dtindex.to_period(base)
        if not isinstance(base_period._data, np.ndarray):
            # unwrap PeriodIndex --> PeriodArray
            base_period = base_period._data

        if self.n > 0:
            # when adding, dates on end roll to next
            normed = dtindex - off + Timedelta(1, 'D') - Timedelta(1, 'ns')
            roll = np.where(base_period.to_timestamp(how='end') == normed,
                            self.n, self.n - 1)
            # integer-array addition on PeriodIndex is deprecated,
            #  so we use _addsub_int_array directly
            shifted = base_period._addsub_int_array(roll, operator.add)
            base = shifted.to_timestamp(how='end')
        else:
            # integer addition on PeriodIndex is deprecated,
            #  so we use _time_shift directly
            roll = self.n
            base = base_period._time_shift(roll).to_timestamp(how='end')

        return base + off + Timedelta(1, 'ns') - Timedelta(1, 'D')
286560
def rate_of_change(data, period):
    
    catch_errors.check_for_period_error(data, period)

    rocs = [((data[idx] - data[idx - (period - 1)]) /
         data[idx - (period - 1)]) * 100 for idx in range(period - 1, len(data))]
    rocs = fill_for_noncomputable_vals(data, rocs)
    return rocs
93615
def rolling_performances(self, timestamp='one_month'):
        '''  '''
        # TODO Study the impact of month choice
        # TODO Check timestamp in an enumeration
        # TODO Implement other benchmarks for perf computation
        # (zipline issue, maybe expected)

        if self.metrics:
            perfs = {}
            length = range(len(self.metrics[timestamp]))
            index = self._get_index(self.metrics[timestamp])
            perf_keys = self.metrics[timestamp][0].keys()
            perf_keys.pop(perf_keys.index('period_label'))

            perfs['period'] = np.array(
                [pd.datetime.date(date) for date in index])
            for key in perf_keys:
                perfs[key] = self._to_perf_array(timestamp, key, length)
        else:
            # TODO Get it from DB if it exists
            raise NotImplementedError()

        return pd.DataFrame(perfs, index=index)
729710
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
        for (int i = 0, isize = period.size(); i < isize; i++) {
            DurationFieldType type = period.getFieldType(i);
            int value = period.getValue(i);
            checkAndUpdate(type, values, value);
        }
        return values;
    }
1012176
def get_balance(self, t: datetime):
        
        return sum_queryset(self.accountentry_set.all().filter(timestamp__lt=t))
268380
def to_discontinuous(self):
        """"""
        collection = HourlyDiscontinuousCollection(self.header.duplicate(),
                                                   self.values, self.datetimes)
        collection._validated_a_period = True
        return collection
744154
def moving_average_convergence_divergence(data, short_period, long_period):
    
    catch_errors.check_for_period_error(data, short_period)
    catch_errors.check_for_period_error(data, long_period)

    macd = ema(data, short_period) - ema(data, long_period)
    return macd
174742
def simple_moving_average(data, period):
    
    catch_errors.check_for_period_error(data, period)
    # Mean of Empty Slice RuntimeWarning doesn't affect output so it is
    # supressed
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=RuntimeWarning)
        sma = [np.mean(data[idx-(period-1):idx+1]) for idx in range(0, len(data))]
    sma = fill_for_noncomputable_vals(data, sma)
    return sma
289240
def integratedAutocorrelationTimeMultiple(A_kn, fast=False):
    

    g = statisticalInefficiencyMultiple(A_kn, fast, False)
    tau = (g - 1.0) / 2.0
    return tau
801625
def double_exponential_moving_average(data, period):
    
    catch_errors.check_for_period_error(data, period)

    dema = (2 * ema(data, period)) - ema(ema(data, period), period)
    return dema
805697
def countables
      key :type, :int
      key :ts, :timestamp
      key :uid, :text

      column :count, :bigint

      generate_aggregators { |ts, method|
        totype = method_names_type_counter(method)
        fromtype = get_fromtype_for_totype(totype)
        aggregate_and_create(fromtype, totype, ts)
      }
    end
1093157
def aroon_down(data, period):
    
    catch_errors.check_for_period_error(data, period)
    period = int(period)

    a_down = [((period -
            list(reversed(data[idx+1-period:idx+1])).index(np.min(data[idx+1-period:idx+1]))) /
            float(period)) * 100 for idx in range(period-1, len(data))]
    a_down = fill_for_noncomputable_vals(data, a_down)
    return a_down
1369602
def getShocks(self):
        '''
        
        '''
        # Get new Markov states for each agent
        if self.global_markov:
            base_draws = np.ones(self.AgentCount)*drawUniform(1,seed=self.RNG.randint(0,2**31-1))
        else:
            base_draws = self.RNG.permutation(np.arange(self.AgentCount,dtype=float)/self.AgentCount + 1.0/(2*self.AgentCount))
        newborn = self.t_age == 0 # Don't change Markov state for those who were just born (unless global_markov)
        MrkvPrev = self.MrkvNow
        MrkvNow = np.zeros(self.AgentCount,dtype=int)
        for t in range(self.T_cycle):
            Cutoffs = np.cumsum(self.MrkvArray[t],axis=1)
            for j in range(self.MrkvArray[t].shape[0]):
                these = np.logical_and(self.t_cycle == t,MrkvPrev == j)
                MrkvNow[these] = np.searchsorted(Cutoffs[j,:],base_draws[these]).astype(int)
        if not self.global_markov:
                MrkvNow[newborn] = MrkvPrev[newborn]
        self.MrkvNow = MrkvNow.astype(int)

        # Now get income shocks for each consumer, by cycle-time and discrete state
        PermShkNow = np.zeros(self.AgentCount) # Initialize shock arrays
        TranShkNow = np.zeros(self.AgentCount)
        for t in range(self.T_cycle):
            for j in range(self.MrkvArray[t].shape[0]):
                these = np.logical_and(t == self.t_cycle, j == MrkvNow)
                N = np.sum(these)
                if N > 0:
                    IncomeDstnNow    = self.IncomeDstn[t-1][j] # set current income distribution
                    PermGroFacNow    = self.PermGroFac[t-1][j] # and permanent growth factor
                    Indices          = np.arange(IncomeDstnNow[0].size) # just a list of integers
                    # Get random draws of income shocks from the discrete distribution
                    EventDraws       = drawDiscrete(N,X=Indices,P=IncomeDstnNow[0],exact_match=False,seed=self.RNG.randint(0,2**31-1))
                    PermShkNow[these] = IncomeDstnNow[1][EventDraws]*PermGroFacNow # permanent "shock" includes expected growth
                    TranShkNow[these] = IncomeDstnNow[2][EventDraws]
        newborn = self.t_age == 0
        PermShkNow[newborn] = 1.0
        TranShkNow[newborn] = 1.0
        self.PermShkNow = PermShkNow
        self.TranShkNow = TranShkNow
899835
def calculate_output(self, variable_name, period):
        

        variable = self.tax_benefit_system.get_variable(variable_name, check_existence = True)

        if variable.calculate_output is None:
            return self.calculate(variable_name, period)

        return variable.calculate_output(self, variable_name, period)
803867
def momentum(data, period):
    
    catch_errors.check_for_period_error(data, period)

    momentum = [data[idx] - data[idx+1-period] for idx in range(period-1, len(data))]
    momentum = fill_for_noncomputable_vals(data, momentum)
    return momentum