def bootstrap(block_size, data, nbootstrap, sig_level=0.05, custom_func=None):
    """
    Description
    ----
    Stationary bootstrap for different block sizes

    Inputs
    ----
    :block_size: Number of points per block
    :nbootstrap: Number of bootstrap samples
    :data: Data to find confidence intervals for

    Outputs
    ----
    List containing mean, standard error
    """

    bs = StationaryBootstrap(block_size, data)

    try:
        bs_results = eval('bs.apply(' + custom_func + ', nbootstrap)')
    except TypeError:
        bs_results = bs.apply(np.mean, nbootstrap)

    mn = np.mean(bs_results, axis=0)
    se = np.std(bs_results, ddof=1, axis=0)

    return list(np.hstack((mn, se)))
Exemplo n.º 2
0
    def _bootstrap(self, block_size):
        """
        Description
        ----
        Stationary bootstrap for different block sizes

        Inputs
        ----
        :block_size: Number of points per block

        Outputs
        ----
        List containing mean, standard error
        """

        bs = StationaryBootstrap(block_size, self._data)

        try:
            bs_results = eval('bs.apply(' + self._custom_func +
                              ', nbootstrap)')
        except TypeError:
            bs_results = bs.apply(np.mean, self._nbootstrap)

        mn = np.mean(bs_results, axis=0)
        se = np.std(bs_results, ddof=1, axis=0)

        return list(np.hstack((mn, se)))
Exemplo n.º 3
0
def bootstrap(x, f):
    if len(x) == 0:
        return np.nan
    from arch.bootstrap import StationaryBootstrap
    bs = StationaryBootstrap(50, x)
    return bs.apply(f,100).mean()
Exemplo n.º 4
0
def bootstrap(x, f):
    if len(x) == 0:
        return np.nan
    from arch.bootstrap import StationaryBootstrap
    bs = StationaryBootstrap(50, x)
    return bs.apply(f, 100).mean()
Exemplo n.º 5
0

def sharpe_ratio(x):
    mu, sigma = x.mean(), np.sqrt(x.var())
    values = np.array([x.sum(), sigma, mu / sigma]).squeeze()
    index = ['CR', 'sigma', 'SR']
    return pd.Series(values, index=index)


R = import_data('results/Yearly_portfolio/yearly_portfolio_returns_CDAX_mp')

R1 = R.iloc[:, 2]
params = sharpe_ratio(R1)

bs = StationaryBootstrap(12, R1)
results = bs.apply(sharpe_ratio, 100000)
delta_CR = results[:, 0] - params[0]
delta_sigma = results[:, 1] - params[1]
delta_SR = results[:, 2] - params[2]


def CI(delta, q=0.95):
    delta.sort()
    abs_sorted = np.abs(delta)
    bound = abs_sorted[int(q * 100000)]
    return bound


CR_bound = CI(delta_CR)
sigma_bound = CI(delta_sigma)
SR_bound = CI(delta_SR)