1 of 30

Bayesian Portfolio Allocation

Thomas Wiecki, PhD

@twiecki

2 of 30

Disclaimer

This presentation is for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation for any security; nor does it constitute an offer to provide investment advisory or other services by Quantopian, Inc. ("Quantopian"). Nothing contained herein constitutes investment advice or offers any opinion with respect to the suitability of any security, and any views expressed herein should not be taken as advice to buy, sell, or hold any security or as an endorsement of any security or company. In preparing the information contained herein, Quantopian, Inc. has not taken into account the investment needs, objectives, and financial circumstances of any particular investor. Any views expressed and data illustrated herein were prepared based upon information, believed to be reliable, available to Quantopian, Inc. at the time of publication. Quantopian makes no guarantees as to their accuracy or completeness. All information is subject to change and may quickly become unreliable for various reasons, including changes in market conditions or economic circumstances.

3 of 30

  • Bayesian consultancy by the inventors of PyMC3
  • Solving advanced analytical problems
  • Team consists of PhDs, mathematicians, neuroscientists, and a former SpaceX rocket scientist
  • Clients in pharma (Roche), fintech, mortgage, agriculture, adtech, biotech...
  • www.pymc-labs.io

3

4 of 30

Markowitz mean-variance optimization

  • Optimal portfolio - in theory - taking mean return, volatility and correlations into account
  • Highly sub-optimal in practice, why?
    • Estimates are very noisy, but we do not quantify that noise
    • Leads to lack of diversification
  • Many hacks… err solutions, exist:
    • Equal-weight (MVO but assuming means and vol are equal and no correlations exist)
    • Inverse-variance weighting (MVO but assuming means are equal and no correlations exist)
    • Hierarchical Risk Parity
    • ...

5 of 30

Bayesian statistics allows to build models flexibly

vs

6 of 30

Bayesian statistics allows specification of prior information

+

7 of 30

Not single most likely solution, but all probable solutions

Instead of point-estimates (scalar values) of e.g. the mean or variance, we use probability distributions that quantify uncertainty.

Point estimates

Probability distributions

8 of 30

Given 16 strategies, how to weight them?

9 of 30

Where we are

Data

10 of 30

Bayesian Modeling: Coin flipping

Parameters

Prior p(θ)

Likelihood p(x | θ)

Model construction:

How parameters relate to data

Inference: Bayes Formula

most likely parameters given data

Data x

(Heads / Tails)

Parameters

Posterior p(θ | x)

p(heads)

Observe:

HTTHTTT

belief

11 of 30

Probabilistic Programming

Parameters

Prior p(θ)

Likelihood p(x | θ)

Model construction:

How parameters relate to data

Inference: Bayes Formula

most likely parameters given data

Data x

(Heads / Tails)

Parameters

Posterior p(θ | x)

p(heads)

Observe:

HTTHTTT

belief

code

automatic

(MCMC)

12 of 30

Modeling financial returns

T-Distribution

Inference: Bayes Formula

probability of parameters given data

Latent causes

(Parameters)

Distribution

of Data

Observed Data

  • mean returns
  • volatility
  • tails

13 of 30

Where we are

Data

Model

14 of 30

  • Probabilistic Programming framework for Python, FOSS
  • Specify arbitrary models in code by plugging probability distributions into each other
  • Intuitive model specification syntax
    • For example: x ~ N(0,1) translates to x = Normal('x', 0, 1)
  • Inference Button: Automatic and powerful inference for any model

15 of 30

The model in

Parameters / Priors

Inference

Model specification

16 of 30

Where we are

Data

Model

Posterior

17 of 30

Posterior probability that strategy is profitable (SR > 0)

18 of 30

Where we are

Data

Model

Posterior

Predictions

19 of 30

Bayesian Decision Making

  • So far we only have probability distributions for our strategies.
  • How to construct a portfolio from them?
  • Use model to generate all kinds of possible future scenarios (prediction)
  • Define loss function that rates how good a solution is given a scenario
  • Use optimizer to find best solution across all possible future scenarios

20 of 30

Bayesian Decision Making

Data

Model

Posterior

Predictions

Optimizer

Loss function

Decision

21 of 30

Predictions

  • Generate possible future scenarios by drawing parameter set from posterior & sampling from likelihood
  • Two sources of variability: Likelihood & uncertainty

22 of 30

Bayesian Decision Making

Data

Model

Posterior

Predictions

Optimizer

Loss function

Decision

23 of 30

Loss function for Mean-Variance

  • Utility theory tells us to minimize our expected losses (maximizing wins leads to overly risky behavior)
  • Black-Littermann: −exp(−λr(ω)), where r(ω) are the expected returns if we used portfolio weights ω, λ is how averse to losses we are

24 of 30

Example

def loss_function(ω): # weight vector, e.g. [1/16, 1/16, …]

loss = 0

for r in sampled_returns:

# compute portfolio returns

port_rets = sum(r * ω)

loss += -exp(-port_rets)

return loss

25 of 30

Bayesian Decision Making

Data

Model

Posterior

Predictions

Optimizer

Loss function

Decision

26 of 30

Optimization → Output

  • Finds optimal portfolio weights ω which minimize expected loss
  • In our case: loss function is convex so we can use convex solvers (cvxpy) which are much faster, otherwise, use scipy.optimizer.fmin().

27 of 30

The full model

  • Changes in volatility and mean over time using GPs
  • Hierarchical estimation to pool information from batch of algorithms
  • Correlations

28 of 30

Benefits

  • Robust due to using posterior distributions rather than point-estimates
  • Different length track-records are automatically handled
    • Short but great track-record: high uncertainty -> many potentially bad outcomes -> low weight
  • Model can be improved to include all kinds of structure, like risk-factors, prior information we might have (e.g. knowing a certain manager well).

29 of 30

Further reading

30 of 30

Disclaimer

This presentation is for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation for any security; nor does it constitute an offer to provide investment advisory or other services by Quantopian, Inc. ("Quantopian"). Nothing contained herein constitutes investment advice or offers any opinion with respect to the suitability of any security, and any views expressed herein should not be taken as advice to buy, sell, or hold any security or as an endorsement of any security or company. In preparing the information contained herein, Quantopian, Inc. has not taken into account the investment needs, objectives, and financial circumstances of any particular investor. Any views expressed and data illustrated herein were prepared based upon information, believed to be reliable, available to Quantopian, Inc. at the time of publication. Quantopian makes no guarantees as to their accuracy or completeness. All information is subject to change and may quickly become unreliable for various reasons, including changes in market conditions or economic circumstances.