Mar 7, 2017 - low-rank tensor decomposition ... Smolyak sparse grids vs tensor decomposition criteria elegance: ..... Tensor-train decomposition (TT Toolbox).
Computational Tools and Techniques for Numerical Macro-Financial Modeling Victor V. Zhorin MFM/BFI
March 7, 2017
(MFM/BFI)
March 7, 2017
1 / 29
Numerical Building Blocks Spectral approximation technology (chebfun): numerical computation in Chebyshev functions piece-wise smooth functions breakpoints detection rootfinding functions with singularities fast adaptive quadratures continuous QR, SVD, least-squares linear operators solution of linear and non-linear ODE Fr´ echet derivatives via automatic differentiation PDEs in one space variable plus time
Stochastic processes: (quazi) Monte-Carlo simulations, Polynomial Expansion (gPC), finite-differences (FD) non-linear IRF Boroviˇ cka-Hansen-Sc[heinkman shock-exposure and shock-price elasticities Malliavin derivatives
Many states: Dimensionality Curse Cure low-rank tensor decomposition sparse Smolyak grids
(MFM/BFI)
March 7, 2017
2 / 29
Numerical Building Blocks (cont.) MFM
R
(n)
∂ , ∂x (n)
roots, Pad´ e
spectral tech nonlinear ODE
(q)MC
nonlinear model
shocks
gPC
FD BVP
many states
sparse grids
(MFM/BFI)
low rank TT
March 7, 2017
3 / 29
Horse race: methods and models models He-Krishnamurthy, ”Intermediary Asset Pricing” Klimenko-Pfeil-Rochet-DeNicolo, ”Aggregate Bank Capital and Credit Dynamics” Brunnermeier-Sannikov, ”A Macroeconomic Model with a Financial Sector” Basak-Cuoco, ”An Equilibrium Model with Restricted Stock Market Participation” Di Tella, ”Uncertainty Shocks and Balance Sheet Recessions”
methods spectral technology vs discrete grids Monte-Carlo simulations (MC) vs Polynomial Expansion (gPC) vs finite-differences SPDE (FD) Smolyak sparse grids vs tensor decomposition
criteria elegance: clean primitives, libraries, ease of mathematical concepts expression in code speed: feasibility, ready prototypes, LEGO blocks; precision: numerical tests of speed vs stability trade-offs common metrics: shock exposure elasticity, asset pricing implications (MFM/BFI)
March 7, 2017
4 / 29
Adaptive Chebyshev functional approximation (chebfun.org)
Given Chebyshev interpolation nodes zk , k = 1, . . . , m on [−1, 1] zk = −cos
2k − 1 2m
π
and Chebychev coefficients ai , i = 0, . . . , n computed on Chebychev nodes we can approximate
F(x) ≈
n X i=0
ai Ti (x) ; ai =
2 π
Z 1 F(x)Ti (x) dx p −1 1 − x2
”Approximation Theory and Approximation Practice”, by Lloyd N. Trefethen (chebfun.org) ”Chebyshev and Fourier Spectral Methods”, by John P. Boyd Chebyshev interpolation nodes and degree of polynomials have to be adaptive during continuous Newton updates. (i) When in doubt, use Chebyshev polynomials unless the solution is spatially periodic, in which case an ordinary Fourier series is better. (ii) Unless youre sure another set of basis functions is better, use Chebyshev polynomials. (iii) Unless youre really, really sure that another set of basis functions is better, use Chebyshev polynomials
(MFM/BFI)
March 7, 2017
5 / 29
Adaptive Chebyshev functional approximation: examples (chebfun)
2
5 4 1.5
3 2
1
F ′(x)
0 −1 −2
0
−3 −0.5
−4 −5
−1
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
0
0.5
1
1.5
2
x
2.5
3
3.5
4
4.5
5
x
Chebyshev coefficients
0
10
−2
10
−4
Magnitude of coefficient
F(x)
1 0.5
10
−6
10
−8
10
−10
10
−12
10
−14
10
−16
10
0
10
20
30
40
50
60
70
Degree of Chebyshev polynomial
(MFM/BFI)
March 7, 2017
6 / 29
shock-exposure and shock-price elasticity first kind Multiplicative functional Mt : 1) consumption Ct for consumption shock-exposure 2) stochastic discount factor St for consumption shock-price elasticity d log Mt = β(Xt )dt + α(Xt )dBt
(x, t) = σ(x)
∂ ∂x
log E[Mt |X0 = x] + α(x)
Define φ(x, t) = E
Mt M0
|X0 = x
Then solve PDE ∂φ(x, t) ∂t
=
∂ 1 2 ∂2 φ(x, t) + (µ(x) + σ(x)α(x)) σ (x) φ(x, t) + 2 ∂x 2 ∂x
β(x) +
1 2
2 |α(x) | φ(x, t)
s.t. initial boundary condition φ(x, 0) = 1
(MFM/BFI)
March 7, 2017
7 / 29
shock-exposure and shock-price elasticity second kind Multiplicative functional Mt : 1) consumption Ct for consumption shock-exposure 2) stochastic discount factor St for consumption shock-price elasticity d log Mt = β(Xt )dt + α(Xt )dBt The elasticity of second kind is 2 (Xt ) =
E(Dt Mt )|F0 EMt |F0
Use specification for Mt to get 2 (Xt ) =
E( Mt η(Xt )α(Xt ))|F0 EMt |F0
Then solve PDE twice ∂φ(x, t) ∂t
=
1 2 ∂2 ∂ σ (x) φ(x, t) + φ(x, t) + (µ(x) + σ(x)α(x)) 2 ∂x 2 ∂x
β(x) +
1 2
2 |α(x) | φ(x, t)
s.t. initial boundary condition φ(x, 0) = 1 to get a solution φ1 (x, t) and initial boundary condition φ(x, 0) = α(x) to get a solution φ2 (x, t) Then, second type elasticity is φ2 (x, t) 2 (x, t) = φ1 (x, t)
(MFM/BFI)
March 7, 2017
8 / 29
”Intermediary Asset Pricing”:
Zhiguo He and Arvind Krishnamurthy, AER, 2013
h i P Find Dt = F (y ), ∀y ∈ 0, 1+l , by solving ρ t
F
=
00
(y ) θs (y )G (y )
2
(θ b (y )σ)2
!
1 + l + ρy (γ − 1)
G (y )
θs (y )F (y ) 1 + l − ρy + ργG (y ) θ b (y ) " # ρG (y ) θ b (y ) y − G (y ) θ b (y ) 1 + l − ρy − ρG (y ) θ b (y ) + ρ + g (γ − 1) − 1+ F (y ) 2 1 + l − ρy θs (y )F (y ) 1 + l − ρy + ργG (y ) θ b (y ) ! (1 + l − ρy ) (G (y ) − 1) θs (y ) + l + θ b (y )(g (γ − 1) + ρ) − ρy − + γρG (y ) . θs (y )F (y ) 1 + l − ρy + ργG (y ) θ b (y ) 2
1
γ (1 − γ) σ 2
where G (y ) =
1 1 − θs (y )F 0 (y )
,
and if y ∈ (0, y c ) θs (y ) = θb (y ) =
if y ∈
(1−λ)y F (y )−λy F (y )−y λy F (y )−λy
y c , 1+l ρ m 1+m
.
m F (y ) y − 1+m
m The endogenous threshold y c is determined by y c = 1−λ+m F (y c ). Boundary conditions on y = 0 and y = 1+l . r
1 + F 0 (0) l
F (0) =
ρ + g (γ − 1) +
(MFM/BFI)
γ(1−γ)σ 2 2
−
lγρ 1+l
; F
1+l ρ
=
1+l ρ
;F
0
1+l ρ
= 1.
March 7, 2017
9 / 29
He-Krishnamurthy, BVP solution
dXt = µy (Xt )dt + σy (Xt )dBt , Xt =
wt Pt
; σy (Xt ) = −
θb 1 − θs F 0 (y )
σ; Xt =
F (y ) − y F (y )
d log Ct = β(Xt )dt + α(Xt )dBt ; d log St = −γ log Ct β(x) = µ(x)ξ(x) +
1 2
σ(x)
2
∂ξ ∂x
+ gd −
σd2 2
; α(x) = σ(x)ξ(x) + σd ; ξ(x) = −ρ
0.2
p 0 (x)(1 − x) − p(x) 1 + l − ρ(1 − x)p(x)
0.2
0.15 0.15
µ(X)
σ(X)
0.1 0.1
0.05 0.05 0
−0.05 0
0.2
0.4
0.6
X
(MFM/BFI)
0.8
1
0 0
0.2
0.4
0.6
0.8
1
X
March 7, 2017
10 / 29
example, He-Krishnamurthy
stationary density distribution, percentiles 12 density 1% 5% 25% 35.3% 50% 75% 90% 99%
stationary density
10 8 6 4 2 0
0
0.1
0.2
0.3
0.4
0.5
0.6
X
*
(MFM/BFI)
March 7, 2017
11 / 29
He-Krushnamurthy: shock exposure, specialist C
(a) type 1 elasticity
(MFM/BFI)
(b) type 2 elasticity
March 7, 2017
12 / 29
He-Krushnamurthy: price exposure, specialist C
(a) type 1 elasticity
(MFM/BFI)
(b) type 2 elasticity
March 7, 2017
13 / 29
Brunnermeier-Sannikov example
dXt Xt
= µ(Xt )dt + σ(Xt )dBt − dζt , Xt =
Nt q t Kt
;
X (t) : expert share of wealth Consumption is aggregate output net of aggregate investment a
Ct = [aψ(Xt ) + a(1 − ψ(Xt ))]Kt d log Ct = β(Xt )dt + α(Xt )dBt ; where
2
α(X ) = σ; β(X ) = Φ(X ) − δ − σ /2 For log-utility St /S0 = e
(MFM/BFI)
−ρt
C0 /Ct
March 7, 2017
14 / 29
Brunnermeier-Sannikov: shock exposure, aggregate C for logarithmic utility consumption of both households and experts are myopic, proportional to their wealth Nt dζt = ρdt; d log Ct = d log Kt 1 2 dt + σdBt d log Kt = Φ(it ) − δψt − δ(1 − ψt ) − σ 2 for δ = δ α(X ) = σ; β(X ) = Φ(X ) − δ −
(a) type 1 elasticity (MFM/BFI)
1 2 σ 2
(b) type 2 elasticity March 7, 2017
15 / 29
Brunnermeier-Sannikov: price exposure, aggregate C for logarithmic utility consumption of both households and experts are myopic, proportional to their wealth Nt dζt = ρdt; d log Ct = d log Kt 1 2 dt + σdBt d log Kt = Φ(it ) − δψt − δ(1 − ψt ) − σ 2 for δ = δ α(X ) = σ; β(X ) = Φ(X ) − δ −
(a) type 1 elasticity (MFM/BFI)
1 2 σ 2
(b) type 2 elasticity March 7, 2017
16 / 29
Model Settings, Klimenko, Pfeil, Rochet, DeNicolo (KPRD) State - equity E Multiplicative functional M = R(E ) dEt = µ(Et )dt + σ(Et )dBt , p + r ≤ Rt ≤ Rmax , where µ(E ) = Er + L(R(E ))(R(E ) − r − p); σ(E ) = L(R(E ))σ0 . Z E max R(s) − p − r σ02 L(R(s))
0
ds = ln(1 + γ); u(E ) = exp
Z E max R(s) − p − r E
with L(R) =
R−R
σ02 L(R(s))
! ds
!β
R−p
where u(E) is market-to-book value d log R =
R(E )0 R(E )
dE = ψ(E )dE → d log Rt = β(Et )dt + α(Et )dBt
∂ψ(E ) ∂φt (E ) where β(E ) = µ(E )ψ(E ) + 21 σ(E )2 ∂E , α(E ) = σ(E )ψ(E ); s.t. Neumann b.c.: ∂x 1 2(ρ − r )σ02 + [R(E ) − p − r ]2 + 2rE [R(E ) − p − r ]L(R(E ))−1
0
R (E ) = −
σ02
(MFM/BFI)
L(R(E )) − L0 (R(E ))[R(E ) − p − r ]
=0 Emin,max
, R(Emax ) = p + r
March 7, 2017
17 / 29
State Space (E) drift µ(E ) and volatility σ(E ), functional M: α(E ), β(E ) Klimenko, Pfeil, Rochet, DeNicolo (KPRD), revised
(a) µ(E )
(b) σ(E ) -0.088
0.025
-0.09
0.02
-0.092
σ(E)
µ(E)
0.03
0.015 0.01
-0.096
0.005 0
-0.094
-0.098
0
0.05
0.1
0.15
0.2
-0.1
0.25
0
0.05
0.1
E
0.15
0.2
0.25
0.2
0.25
E
(a) β(E )
(b) α(E )
-0.05
0.5
-0.06 0.45
-0.07
α(E)
β(E)
-0.08 -0.09
0.4
-0.1 0.35
-0.11 -0.12 -0.13
0.3 0
0.05
0.1
0.15
E
(MFM/BFI)
0.2
0.25
0
0.05
0.1
0.15
E
March 7, 2017
18 / 29
stationary density in E and R, Klimenko, Pfeil, Rochet, DeNicolo (KPRD)
in E space stationary density
5
4
3
2
1
0 0
0.05
0.1
0.15
0.2
0.25
0.3
E
in R space (identical to a graph in KPRD paper) 45 40 35
g(R)
30 25 20 15 10 5 0
0.02
0.025
0.03
0.035
0.04
0.045
0.05
0.055
R
(MFM/BFI)
March 7, 2017
19 / 29
R=R(E), Klimenko, Pfeil, Rochet, DeNicolo (KPRD)
R=R(E)
0.055 0.05
R(E)
0.045 0.04 0.035 0.03 0.025 0.02
0
0.05
0.1
0.15
0.2
0.25
E
(MFM/BFI)
March 7, 2017
20 / 29
Shock-exposure elasticity for R = R(E ) (KPRD)
state space: bank equity, type 1 elasticity, shock exposure
state space: bank equity, type 2 elasticity, shock exposure
0.5
0.5
0.01 0.13 0.25
0.45
0.01 0.13 0.25
0.48
0.4 0.46 0.35
interest rate
interest rate
0.44 0.3 0.25 0.2
0.42 0.4 0.38
0.15
0.36
0.1
0.34
0.05
0.32
0 0
10
20
30
40
time, years
(a) type 1 elasticity
(MFM/BFI)
50
0
10
20
30
40
50
time, years
(b) type 2 elasticity
March 7, 2017
21 / 29
SDF and price elasticity, Klimenko, Pfeil, Rochet, DeNicolo (KPRD) State - equity E Multiplicative functional for SDF M = u(E ) u(E ) = exp
Z E max R(s) − p − r σ02 L(R(s))
E
with L(R) =
R−R
! ds
!β
R−p
market-to-book
where u(E) is market-to-book value
1.5 1.4 1.3 1.2 1.1 1 0
0.05
0.1
0.15
0.2
0.25
0.3
0.2
0.25
0.3
E 0.06
R(E)
0.05 0.04 0.03 0.02 0
0.05
0.1
0.15
E
(MFM/BFI)
March 7, 2017
22 / 29
Price elasticity for R = R(E ) (KPRD)
state space: bank equity, type 1 elasticity, price exposure
state space: bank equity, type 2 elasticity, price exposure
0
0
-0.05
-0.1
interest rate
-0.1
interest rate
0.01 0.13 0.25
-0.05
-0.15
-0.2 0.01 0.13 0.25
-0.25
-0.15
-0.2
-0.25
-0.3
-0.3
0
10
20
30
40
time, years
(a) type 1 elasticity
(MFM/BFI)
50
0
10
20
30
40
50
time, years
(b) type 2 elasticity
March 7, 2017
23 / 29
Malliavin Derivative and Generalized Polynomial Chaos Expansion (gPC)
Fast technique for high-precision numerical analysis of stochastic non-linear systems Malliavin calculus to integrate and differentiate processes that are expressed in generalized Polynomial Chaos (gPC)
Generating function exp
sx −
s2
! =
2
n=0
Let Bt be Brownian motion, Mt = exp
∞ n X s
n! 2
sBt − s 2 t
Hn (x); Hn (x) are orthogonal Hermite polynomials
Then (Ito) dMt = s
∞ n X s n=0
n!
xn (t)dBt , xn (t) = t Z t
dxn (t) = nxn−1 dBt ; xn (t) = n!
u(t, Bt ) ≈
p X
0
dB(tn−1 )
n/2
Z t −1 n 0
√ Hn (Bt / t) Z t2 dB(tn−2 ) . . .
dB(t1 ) 0
ui (t)Hi (Bt ), Cameron and Martin for Gaussian random variables, Xiu-Karniadakis for generalized
i=0
u0 (x, t) = E[u(x, t, ξ)H0 ] = E[u(x, t, ξ)]
(MFM/BFI)
March 7, 2017
24 / 29
from SDE to ODEs
√ Let Hˆn ξ := Hn (ξ)/ n! Then the Malliavin derivative operator (annihilation operator) with √ respect to random variable ξ is: Dξ (Hn (ξ)) := nHn−1 (ξ) Malliavin divergence operator (creation √ operator, Skorokhod integral) with respect to ξ is: δξ (Hn (ξ)) := n + 1Hn+1 (ξ) extended to nonlinear functionals of random variables expressed with PC decomposition Ornstein-Uhlenbeck operator L := δ ◦ D (and its semigroup) - the Hermite polynomials are eigenvectors
(MFM/BFI)
March 7, 2017
25 / 29
from SDE to ODEs (cont)
Loan rate Rt = R(Et ): dRt = µ(Rt )dt + σ(Rt )dBt , p ≤ Rt ≤ Rmax , Z t Rt = r0 +
Z t µ(Rτ )dτ +
0
Rt ≈
p X
ri (t)Hi (ξ); B(t, ξ) ≈
i=0
n X
σ(Rτ )dBτ 0
bi (t)Hi (ξ), ξ ∼ N(0, 1), {Hi } − Hermite polynomials : KLE
i=1
R R Integration by parts: E F 0t Rτ dBτ = E 0t Dξ FRτ dτ
r˙i (t) ≈ hµ(Rt )ii +
n p X
jbj (t)hσ(Rt )ij−1 , i = 0, . . . , p
j=1
Non-linear IRF: Ft = D0 Rt from Borovicka-Hansen-Scheinkman
(MFM/BFI)
March 7, 2017
26 / 29
Stochastic Galerkin and Polynomial Chaos Expansion for Stochastic PDE
Spectral expansion in stochastic variable(s): ξ ∈ Ω:
u(x, t, ξ) =
∞ X
ui (x, t)ψi (ξ)
i=0
where ψi (ξ) are orthogonal polynomials (Hermite, Legendre, Chebyshev) standard approximations (spectral or finite elements) in space and polynomial (also spectral or pseudo-spectral) approximation in the probability domain Babuska, Ivo, Fabio Nobile, and Raul Tempone. ”A stochastic collocation method for elliptic partial differential equations with random input data.” SIAM Journal on Numerical Analysis 45.3 (2007): 1005-1034. u(x, t, ξ) ≈
p X
ui (x, t)ψi (ξ)
i=0
substitute into PDE and do a Galerkin projection by multiplying with ψk (ξ) ∂u ∂t
= a(ξ)
(MFM/BFI)
∂2u ∂x 2
;
p X ∂ui (x, t) i=0
∂t
hψi ψk i +
pσ p X ∂ 2 ui X i=0
∂x 2 j=0
aj hψj ψi ψk i, k = 0, . . . , p
March 7, 2017
27 / 29
Monte-Carlo/gPC comparison (sglib) gPC expansion for ln N(µ, σ 2 ) with µ = 0.03, σ = 0.85, comparison with exact value and MC (1,000 and 100,000 samples)
(MFM/BFI)
March 7, 2017
28 / 29
Extension to many dimensions: Adaptive sparse (Smolyak) grids (Bocola, 2015), tensor approximation
1
1
0.5
0.5
0
0
−0.5
−0.5
1
1
0
0
−1 1
−1 1 1
0 −1 −1
−0.5
0
0.5
1
−1 −1
1
1
0.5
0.5
−0.5
0
0.5
0
0 −0.5
1
0
0
−1 1
−1 1 1
0 −1 −1
−0.5
0
0.5
1
−1 −1
−0.5
0
0.5
1
0 −1 −1
1
−0.5
1
0
0 −1 −1
1
0 −1 −1
1
0
0 −1 −1
Tensor-train decomposition (TT Toolbox) A(i1 , . . . , id ) = G1 (i1 )G2 (i2 ) . . . Gd (id ), where Gk (ik ) is rk−1 × rk , r0 = rd = 1. basic linear algebra operations in O(dnr α ) rank reduction in O(dnr 3 ) operations tensor can be recovered exactly by sampling (MFM/BFI)
March 7, 2017
29 / 29