Skip to content

Commit e474a1c

Browse files
committed
remove ipywidgets because it takes too long to build and does not work with static html
1 parent f394021 commit e474a1c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lectures/black_litterman.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import numpy as np
8686
import scipy.stats as stat
8787
import matplotlib.pyplot as plt
8888
from numba import jit
89-
from ipywidgets import interact, FloatSlider
9089
```
9190

9291
## Mean-Variance Portfolio Choice
@@ -404,10 +403,9 @@ def black_litterman(λ, μ1, μ2, Σ1, Σ2):
404403
405404
# The Black-Litterman recommendation for the portfolio weights
406405
w_tilde = np.linalg.solve(δ * Σ_est, μ_tilde)
406+
```
407407

408-
τ_slider = FloatSlider(min=0.05, max=10, step=0.5, value=τ)
409-
410-
@interact(τ=τ_slider)
408+
```{code-cell} ipython3
411409
def BL_plot(τ):
412410
μ_tilde = black_litterman(1, μ_m, μ_est, Σ_est, τ * Σ_est)
413411
w_tilde = np.linalg.solve(δ * Σ_est, μ_tilde)
@@ -441,6 +439,8 @@ def BL_plot(τ):
441439
ax[1].xaxis.set_ticks(np.arange(1, N+1, 1))
442440
ax[1].legend(numpoints=1)
443441
plt.show()
442+
443+
BL_plot(τ)
444444
```
445445

446446
## Bayesian Interpretation
@@ -643,9 +643,10 @@ r2 = np.linspace(-0.02, .15, N_r2)
643643
curve = np.asarray([black_litterman(λ, μ_m, μ_est, Σ_est,
644644
τ * Σ_est).flatten() for λ in λ_grid])
645645
646-
λ_slider = FloatSlider(min=.1, max=7, step=.5, value=1)
646+
λ = 1
647+
```
647648

648-
@interact(λ=λ_slider)
649+
```{code-cell} ipython3
649650
def decolletage(λ):
650651
dist_r_BL = stat.multivariate_normal(μ_m.squeeze(), Σ_est)
651652
dist_r_hat = stat.multivariate_normal(μ_est.squeeze(), τ * Σ_est)
@@ -674,6 +675,8 @@ def decolletage(λ):
674675
ax.text(μ_est[0] + 0.003, μ_est[1], r'$\hat{\mu}$')
675676
ax.text(μ_m[0] + 0.003, μ_m[1] + 0.005, r'$\mu_{BL}$')
676677
plt.show()
678+
679+
decolletage(λ)
677680
```
678681

679682
Note that the line that connects the two points
@@ -694,10 +697,10 @@ and $\mu_{BL}$ are bending
694697
λ_grid = np.linspace(.001, 20000, 1000)
695698
curve = np.asarray([black_litterman(λ, μ_m, μ_est, Σ_est,
696699
τ * np.eye(N)).flatten() for λ in λ_grid])
700+
λ = 200
701+
```
697702

698-
λ_slider = FloatSlider(min=5, max=1500, step=100, value=200)
699-
700-
@interact(λ=λ_slider)
703+
```{code-cell} ipython3
701704
def decolletage(λ):
702705
dist_r_BL = stat.multivariate_normal(μ_m.squeeze(), Σ_est)
703706
dist_r_hat = stat.multivariate_normal(μ_est.squeeze(), τ * np.eye(N))
@@ -727,6 +730,8 @@ def decolletage(λ):
727730
ax.text(μ_est[0] + 0.003, μ_est[1], r'$\hat{\mu}$')
728731
ax.text(μ_m[0] + 0.003, μ_m[1] + 0.005, r'$\mu_{BL}$')
729732
plt.show()
733+
734+
decolletage(λ)
730735
```
731736

732737
## Black-Litterman Recommendation as Regularization

0 commit comments

Comments
 (0)