Basic Bootstrapping in GAUSS

Introduction

The bootstrap is a commonly used resampling technique which involves taking random samples with replacement to quantify uncertainty about a particular estimator or statistic.

Goals

In this post, we will apply the bootstrap procedure to asset returns. Our data will be annual returns from the S&P 500 and the 10 year US Treasury Bond from 1988-2017. We will apply the bootstrap to the cumulative return of a portfolio with 50% stocks and 50% bonds.

How to take a random sample

After loading our data, the first thing we need to do is to take random samples of our data. We will use the GAUSS function, sampleData, which takes the following inputs:

As we would expect, we see that both samples are the same size as the original vector. The sample without replacement contains the same values as the original vector, just in a different order. The sample with replacement contains a repeated value. This is what we need for the bootstrap.

Example data

The asset return data is 1 plus the year's return expressed as a decimal. For example, the S&P 500 return for 1988 was 16.54% and the 10 year Treasury Bond returned 6.24% in 1990. With the data in this form, it is easy to compute the cumulative return as the cumulative product of each annual value.

For example, for the period 1988 through 1991:

S&P500 Total Return = 1.1654 * 1.3148 * 0.9694 * 1.3023 = 1.9344

meaning that $1 invested in the S&P 500 at the start of 1988 would be worth $1.93 at the end of 1991. That assumes dividends are reinvested and there are no taxes, but still a pretty good return for four years.

Compute the return

Earlier we mentioned that we can compute the return of our data by computing the cumulative product, which we illustrated when we found that $1 invested in the S&P 500 at the start of 1988 would be worth $1.93 by the end of 1991.

We will use the GAUSS function prodc, which computes the cumulative product of every column in a matrix.

// Compute the returns of each asset
returns = prodc(X_s);
// Average the two returns to find the return
// of a portfolio split equally between each asset
total_return = meanc(returns);

After running the last two code snippets, we find:

returns = 11.78 total_return = 8.44
5.09

The full bootstrap

To complete our bootstrap all we have to do now is:

Create a vector to hold the results of our bootstrapped portfolio returns.

Create a loop to perform our bootstrap samples.

// Set seed for repeatable random numbers
rndseed 12577;
// Load all 30 observations for both assets
X = loadd("asset_returns.csv", "S&P500 + 10yrTBond");
// The number of boostrap iterations to perform
n_iters = 10000;
// Create a vector to hold the bootstrap results
results = zeros(n_iters, 1);
for i(1, n_iters, 1);
// Take a sample with replacement
X_s = sampleData(X, rows(X), 1);
// Compute the returns of each asset
returns = prodc(X_s);
// Average the two returns to find the return
// of a portfolio split equally between each asset.
// Store the total return in the 'results' vector.
results[i] = meanc(returns);
endfor;

Results

The histogram of our results vector is shown above. As we mentioned earlier, this data does not account for inflation, assumes all dividends are reinvested and that there are no taxes.

However, even with these stipulations, the returns seem unrealistically high. This is because the bootstrap procedure assumes that each observation is completely independent of all other observations.

This assumption of independence is not generally reasonable for time series data, including asset returns. Future blogs will explore bootstrap modifications to deal with this issue.

Conclusions

In this post, we have learned how to sample data with replacement and perform a basic bootstrap in GAUSS. Make sure to look out for future posts on more advanced bootstrap options.

Have a Specific Question?

Need Support?

Try GAUSS for 30 days for FREE

GAUSS is the product of decades of innovation and enhancement by Aptech Systems, a supportive team of experts dedicated to the success of the worldwide GAUSS user community. Aptech helps people achieve their goals by offering products and applications that define the leading edge of statistical analysis capabilities.