# How to… use bootstrapping in portfolio management

## Bootstrapping method

### Definition

Faced with growing uncertainty in financial markets, investors are worried about the future of their investments. Travelling in time to check the future reality is not yet a possibility. For that reason, we use techniques and create measures to gain confidence in our investments’ future behaviour.

Bootstrapping is a financial technique that allows us to get a return confidence interval for a certain time horizon given the distribution of a sample of historical portfolio returns. We have to keep in mind this method doesn’t predict future results but it gives us an idea of the expected returns based on the historical behaviour of our portfolio.

Supposing that the portfolio launch date was on 1st January 2010 and we had this asset universe:

```import pandas as pd
import numpy as np
import datetime
import random
import matplotlib.pyplot as plt
import matplotlib as mpl
from cycler import cycler

from scipy.stats.kde import gaussian_kde
from scipy.stats import norm

start, end = datetime.datetime(2009, 12, 30), datetime.datetime(2016, 12, 31)

tickers = ["TLT", "HYG", "^GSPC", "^STOXX50E", "^N225", "^FTSE"]

universe = pd.DataFrame([web.DataReader(t, 'yahoo', start, end).loc[:, 'Adj Close'] for t in tickers], index=tickers).T.fillna(method='ffill')
universe = universe/universe.iloc[0,:]-1
``` We talked with our favourite monkey advisor Jeff to give each asset a weight in order to beat our benchmark, an equally weighted portfolio:

```equally_weights = pd.DataFrame(1./len(universe.columns), index=universe.index, columns=universe.columns)
monkey_weights = pd.DataFrame(np.random.uniform(low=0, high=1, size=universe.shape),index=universe.index, columns=universe.columns)
monkey_weights = monkey_weights/pd.DataFrame(monkey_weights.sum(1).repeat(6).values.reshape(universe.shape), index=universe.index, columns=universe.columns)

returns = (1+universe).pct_change(periods=1).fillna(0)

benchmark_returns = (returns*equally_weights).sum(1)
benchmark = (1+benchmark_returns).cumprod()-1

portfolio_returns = (returns*monkey_weights).sum(1)
portfolio = (1+portfolio_returns).cumprod()-1
``` ### How do I do it?

We have the following return distribution for our universe, benchmark and portfolio: For the Bootstrapping we randomly select 261 returns from each distribution multiple times (in this case I did 1000 repetitions). Accumulating these returns we achieve new random samples as possible curves in one year.

```benchmark_bootstrapping = (1+pd.DataFrame([random.sample(list(benchmark_returns.values), 261) for i in range(1000)]).T.shift(1).fillna(0)).cumprod()-1
portfolio_bootstrapping = (1+pd.DataFrame([random.sample(list(portfolio_returns.values), 261) for i in range(1000)]).T.shift(1).fillna(0)).cumprod()-1
``` Removing the outliers, our portfolio could get a yearly return between -5% and 30%, clearly beating our benchmark (from -7.5% to 24.5%):

```benchmark_bootstrapping_prc = benchmark_bootstrapping.quantile([0.05, 0.50, 0.95], axis=1).T

portfolio_bootstrapping_prc = portfolio_bootstrapping.quantile([0.05, 0.50, 0.95], axis=1).T
``` Good job Jeff!!
{"ft_lang_label":"__label__en","ft_lang_prob":0.64295065,"math_prob":0.927962,"size":3112,"snap":"2019-51-2020-05","text_gpt3_token_len":763,"char_repetition_ratio":0.14607465,"word_repetition_ratio":0.0057306592,"special_character_ratio":0.24839331,"punctuation_ratio":0.20446736,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9860024,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,5,null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-18T18:40:17Z\",\"WARC-Record-ID\":\"<urn:uuid:e57490ec-fbbb-4543-9236-ac819ac4b5af>\",\"Content-Length\":\"57294\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6cb56557-ee82-4d57-9030-2fca1144b840>\",\"WARC-Concurrent-To\":\"<urn:uuid:04e20d6d-4ea6-47e2-a751-f2bb75786767>\",\"WARC-IP-Address\":\"178.33.160.126\",\"WARC-Target-URI\":\"https://quantdare.com/bootstrapping-portfolio-management/\",\"WARC-Payload-Digest\":\"sha1:3O4VPDJG7WSMOYZDYJWDR7FW4ACTOGMP\",\"WARC-Block-Digest\":\"sha1:2KAXPIT4PLIRXJHZ2B2LKZPR4NO2IF7H\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250593295.11_warc_CC-MAIN-20200118164132-20200118192132-00337.warc.gz\"}"}