Mean-Field Game Slides

AMS 516 · Statistical Methods in Finance · Project 21

Multi-Agent
Mean-Field Game
for Portfolio Choice

The HJB and Fokker–Planck equations, solved with physics-informed neural networks

The idea

What is a mean-field game?

  1. Thousands of drivers, each picks a road: short or long
  2. The short road is fast only if few take it
  3. One car alone doesn’t change the traffic
  4. Together, their choices make the traffic
  5. Equilibrium: the traffic drivers expect is the traffic they create

The problem

Grow your wealth, but don’t end below the average

\[ dX_t = \big[\,\underbrace{r X_t}_{\text{interest}} + \underbrace{\pi_t\,(\mu - r)}_{\text{premium}}\,\big]\,dt + \underbrace{\sigma\,\pi_t\,dW_t}_{\text{luck}} \]

each line is one investor’s wealth · r = 2%, μ = 8%, σ = 20%

  1. A large population of investors, each keeps π dollars in a stock and the rest in the bank
  2. Luck spreads their wealth apart
  3. At the end, each is compared with the average mT
  4. Ending below it costs a penalty that grows with the gap squared
  5. One investor can’t move the average, and independent luck makes it a fixed number
  6. Everyone’s choices set the average, and the average shapes everyone’s choice

The problem · the goal

Grow your wealth, but fear falling behind

What each investor wants at T

\[ U(x, \cC{\bar m_T}) = \underbrace{-e^{-\gamma x}}_{\text{usual utility}}\; \underbrace{-\;\frac{\lambda}{2}\big((\cC{\bar m_T} - x)^+\big)^2}_{\text{penalty below the average}} \]
\(x\)
final wealth
\(\cC{\bar m_T}\)
average final wealth of everyone
\(\gamma = 1\)
risk aversion
\((z)^+\)
z if positive, else 0
  1. Usual utility: more is better, each extra dollar a bit less
  2. Below the average, each dollar short hurts more and more
  3. λ: how much they fear falling behind; we use λ = 2 λ = 2.0
  4. First posed as −e−γ(x − θmT): peers changed no one’s choice, so we added the penalty

The problem · the equilibrium

Two equations, tied together by one number

HJB

each investor’s best strategy

◀ solved backward, T → 0

\[ \begin{gathered} \partial_t V + \sup_{\pi}\Big\{\big[r x + \pi\,(\mu - r)\big]\,\partial_x V + \tfrac12\,\sigma^2\pi^2\,\partial_{xx} V\Big\} = 0 \\[2pt] V(T,x) = U(x, \cC{\bar m_T}) \end{gathered} \]
\[ \pi^*(t,x) = -\frac{\mu - r}{\sigma^2}\,\frac{\partial_x V}{\partial_{xx} V} \]

the best strategy moves the crowd

Fokker–Planck

how wealth spreads in the crowd

solved forward, 0 → T ▶

\[ \begin{gathered} \partial_t m + \partial_x\big[(r x + (\mu - r)\,\pi^*)\,m\big] - \tfrac12\,\partial_{xx}\big[\sigma^2(\pi^*)^2\,m\big] = 0 \\[2pt] m(0,x) = m_0(x) = \mathcal{N}(1,\ 0.2^2) \end{gathered} \]
\[ \cC{\bar m_T} = \int x\, m(T,x)\,dx \]

the crowd’s average

Equilibrium: the average the HJB assumes is the average the Fokker–Planck equation delivers.

The equilibrium

A guess that confirms itself

\(\bar m\)

\(\pi^*\)

\(\Phi(\bar m)\)

no: a new guess for \(\bar m\)

yes: equilibrium, \(\Phi(\bar m^*) = \bar m^*\)

Guess

\(\bar m\)

first guess: 1.110, the average with no penalty

Each investor

HJB

the best plan \(\pi^*\) against \(\bar m\)

The crowd

Fokker–Planck

everyone plays \(\pi^*\): the average they create, \(\Phi(\bar m)\)

Compare

\(\Phi(\bar m) \overset{?}{=} \bar m\)

does the guess come back?

The method

Two ways to solve the equations

Finite differences

the classic way: our benchmark

Values on a grid (800 × 400 in the code); derivatives from neighbouring points; solved column by column, backward from T

Physics-informed neural network

a network trained to satisfy the equation

\[ \text{loss} = \operatorname{mean} R(t,x)^2 + \operatorname{mean} \big(V(T,x) - U\big)^2 \]

R: how far the network is from satisfying the equation, at thousands of random points. No solution is given; derivatives by automatic differentiation

Finite differences: the whole equilibrium in 2 s, error about 10⁻⁶

Networks: about 1 hour, equilibrium within 0.014% of finite differences

With N investors a grid needs 800N points; a network does not

The value network · training

Training: every rule becomes part of the loss

\[ L_V(\theta_V) = \bbox[#DDD9F6,7px]{L_{\text{equation}}} + \bbox[#CDEDE2,7px]{L_{\text{terminal}}} + \bbox[#FBEAC7,7px]{L_{\text{slopes}}} + \bbox[#FAE2EB,7px]{L_{\text{edges}}} \]
  • equation the HJB holds inside
  • terminal the right value at T
  • slopes its slope and curvature at T
  • edges the right values at x = −1 and 3

checked at 6,400 new random points at every training step

after L-BFGS

The crowd · Fokker–Planck

The density network: where the wealth goes

  1. Starts from the known bell 𝒩(1, 0.2²), built in so it is exact at t = 0
  2. Everyone plays π*; the network is trained so Fokker–Planck holds and the total stays 1 loss = residual² + (mass − 1)²
  3. Wealth piles up just below the average average at T: network 1.0650 · FD 1.0651

Results · fear of falling behind · λ = 2

Less risk near the average, lower returns for all

The network and finite differences overlap; the equilibrium average agrees to 0.014%.

  1. At the start of the year: Merton far from the average; near it, about a third
  2. Through the year: still about a third at the average, until the last weeks, when it becomes a cliff
  3. Everyone holds less stock, so everyone earns less 11.0%6.5% no penaltywith the penalty the population’s average return over the year 1.5 → 0.75 dollarsthe population’s average stock holding is halved, so the stock’s 9% becomes 4.5%

Extension

The league of
N investors

A few investors who see each other: one HJB, solved in rounds

The league of N · in symbols

From one number to N − 1 rivals

Mean field · before

The crowd enters through one fixed number

mT: one fixed number me wealth →

League of N · now

Every rival enters with their current wealth

y: their mean, it moves y1 y2 y3 y4 me, x wealth → (here N = 5)

Goal at T

mean field: \( -e^{-\gamma x} - \tfrac{\lambda}{2}\big((\bar m_T - x)^+\big)^2 \)
\[ U(x, \cC{\bar x}) = -e^{-\gamma x} - \frac{\lambda}{2}\big((\cC{\bar x} - x)^+\big)^2 \]

The group’s mean \(\bar x\) includes me: \(\bar x - x = \big(1 - \tfrac1N\big)(\bar y - x)\), with \(\bar y\) the rivals’ mean, so it is rewritten as

\[ U = -e^{-\gamma x} - \frac{\cC{\lambda_N}}{2}\big((\cC{\bar y} - x)^+\big)^2, \qquad \cC{\lambda_N} = \lambda\big(1 - \tfrac1N\big)^2 \]

Best plan: one HJB with N wealths

\[ \begin{aligned} &\underbrace{\partial_t V + \sup_{\pi}\Big\{\big(rx + \pi(\mu - r)\big)\,\partial_x V + \tfrac12\sigma^2\pi^2\,\partial_{xx} V\Big\}}_{\text{as in the mean field}} \\ &+ \underbrace{\sum_{j=1}^{N-1}\Big[\big(r\cC{y_j} + \cC{\pi_j}(\mu - r)\big)\,\partial_{y_j}V + \tfrac12\sigma^2\cC{\pi_j}^2\,\partial_{y_jy_j}V\Big]}_{\text{new: each rival's drift and luck}} = 0 \end{aligned} \]

\(V(t, x, \cC{y})\) with \(\cC{y} = (y_1, \dots, y_{N-1})\) and \(V(T, x, y) = U(x, \bar x)\)

\(\cC{\pi_j} = \pi\big(t, y_j, y^{(j)}\big)\): every rival plays the same rule, from their own seat

The league of N · the method

Play in rounds until the rule stops changing

no: the rivals play the new rule

yes: equilibrium

Start

\(\pi_0 = \text{Merton}\)

the rule without the penalty

Freeze

the rivals

a frozen copy of the rule plays them

V network

HJB

my best response to them

m network

Fokker–Planck

where wealth ends up

New rule

\(\pi_{k+1}\)

read from the network

Compare

Δ falling?

is the rule still moving?

Not needed: the rivals are already inside the HJB

Start · round 1

The rivals start by playing Merton

\[ \pi_0(t) = \frac{\mu - r}{\gamma\sigma^2}\,e^{-r(T-t)} \]

Exact and smooth: the rule without the penalty, no training needed

Each round · freeze

A frozen copy of the rule plays every rival

\[ \pi_j = \pi_k\big(t,\ y_j,\ y^{(j)}\big), \qquad y^{(j)} = \text{everyone else, me included} \]

It does not change during the round, so my problem is an ordinary HJB

Each round · the V network

Train my best response to those rivals

\[ \partial_t V + \sup_{\pi}\{\cdots\} + \sum_{j=1}^{N-1}\Big[\big(r y_j + \pi_j(\mu - r)\big)\,\partial_{y_j}V + \tfrac12\sigma^2\pi_j^2\,\partial_{y_jy_j}V\Big] = 0 \]

One round is one training, starting from the network of the round before

Each round · the new rule

Read the new rule from the network

\[ \pi_{k+1}(t, x, y) = -\frac{\mu - r}{\sigma^2}\,\frac{\partial_x V}{\partial_{xx} V} \]

The same formula as in the mean field; there is no density to compute

Each round · compare

Has the change stopped falling?

\[ \Delta_k = \operatorname{mean}\,\big|\pi_{k+1} - \pi_k\big| \]

Stop when Δ no longer halves: what is left is training noise

The rounds of the league with N = 5

The league of N · training

Every step draws 6,000 new situations

The league of N · training

The same loss, with rivals and without edges

\[ L(\theta_V) = \bbox[#DDD9F6,7px]{L_{\text{equation}}} + \bbox[#CDEDE2,7px]{L_{\text{terminal}}} + \bbox[#FBEAC7,7px]{L_{\text{slopes}}} \]

Ledgesno edges: there is no box

equation5,000 situations

the HJB with every rival holds; the rivals’ \(\pi_j\) come from the frozen copy

\[ \begin{aligned} L_{\text{equation}} &= \operatorname*{mean}_{\text{situations}} R^2 \\ R &= R_{\text{1D}} + \frac{1}{\kappa^2/2}\sum_{j=1}^{N-1}\Big[\big(r y_j + \pi_j(\mu - r)\big)\,\partial_{y_j}\vth + \tfrac{\sigma^2}{2}\,\pi_j^2\big(\partial_{y_jy_j}\vth + (\partial_{y_j}\vth)^2\big)\Big] \end{aligned} \]
terminal1,000 at t = T

the right value at the end, now with \(\lambda_N\) and \(\bar y\)

\[ L_{\text{terminal}} = \operatorname*{mean}_{t = T}\big(\vth(T, x, y) - v_T(x, \bar y)\big)^2, \qquad v_T = \log\Big(e^{-\gamma x} + \tfrac{\lambda_N}{2}\big((\bar y - x)^+\big)^2\Big) \]
slopesthe same 1,000 points

my own slope and curvature at the end, which set my rule

\[ L_{\text{slopes}} = \operatorname*{mean}_{t = T,\ |x - \bar y| \gt 0.05}\Big[\big(\partial_x\vth - v_T'\big)^2 + \big(\partial_{xx}\vth - v_T''\big)^2\Big] \]
the network: my rule exact (only at T) my rivals’ rule (last round’s) rivals and their mean
N =
after round 4

The league of N · the rule

The network’s result

the network N → ∞ (mean field) Merton my rivals and their mean other N, each in its own game
N =

The league of N · real games

If we simulate the games

one game average of 2,000 games a population without the penalty
N =

A real case · why a square

Chile’s pension funds play a league of N = 7

\[ \pi^* = -\frac{\mu - r}{\sigma^2}\,\frac{\partial_x V}{\partial_{xx} V} \]

at a corner, \(\partial_{xx} V = -\infty\)

  1. In Chile, 7 private firms (AFPs) invest workers’ pension savings
  2. A fund that trails the average by too much: its firm pays the gapPension law, art. 37 · until 2027
  3. And a square has no corner: the standard choice
  4. Money is not all they lose: clients and reputation go too, so the cost bends up
  5. So they all invest alike: herdingOlivares & Sepúlveda 2007
    Bravo & Ruiz 2015

AMS 516 · Stony Brook University

Thank you

Questions?

1 / 16

← → or clicker to move · F for full screen