You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/markov_asset.md
+34-19Lines changed: 34 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,16 @@ kernelspec:
35
35
"Asset pricing is all about covariances" -- Lars Peter Hansen
36
36
```
37
37
38
+
```{admonition} GPU
39
+
:class: warning
40
+
41
+
This lecture is accelerated via [hardware](status:machine-details) that has access to a GPU and JAX for GPU programming.
42
+
43
+
Free GPUs are available on Google Colab. To use this option, please click on the play icon top right, select Colab, and set the runtime environment to include a GPU.
44
+
45
+
Alternatively, if you have your own GPU, you can follow the [instructions](https://github.com/google/jax) for installing JAX with GPU support. If you would like to install JAX running on the `cpu` only you can use `pip install jax[cpu]`
46
+
```
47
+
38
48
In addition to what's in Anaconda, this lecture will need the following libraries:
39
49
40
50
```{code-cell} ipython
@@ -976,10 +986,12 @@ $$
976
986
977
987
Consider the following primitives
978
988
979
-
```{code-cell} python3
989
+
```{code-cell} ipython3
980
990
n = 5 # Size of State Space
981
-
P = np.full((n, n), 0.0125)
982
-
P[range(n), range(n)] += 1 - P.sum(1)
991
+
P = jnp.full((n, n), 0.0125)
992
+
P = P.at[jnp.arange(n), jnp.arange(n)].set(
993
+
P[jnp.arange(n), jnp.arange(n)] + 1 - P.sum(1)
994
+
)
983
995
# State values of the Markov chain
984
996
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05])
985
997
γ = 2.0
@@ -1004,11 +1016,13 @@ Do the same for
1004
1016
1005
1017
First, let's enter the parameters:
1006
1018
1007
-
```{code-cell} python3
1019
+
```{code-cell} ipython3
1008
1020
n = 5
1009
-
P = np.full((n, n), 0.0125)
1010
-
P[range(n), range(n)] += 1 - P.sum(1)
1011
-
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05]) # State values
1021
+
P = jnp.full((n, n), 0.0125)
1022
+
P = P.at[jnp.arange(n), jnp.arange(n)].set(
1023
+
P[jnp.arange(n), jnp.arange(n)] + 1 - P.sum(1)
1024
+
)
1025
+
s = jnp.array([0.95, 0.975, 1.0, 1.025, 1.05]) # State values
1012
1026
mc = qe.MarkovChain(P, state_values=s)
1013
1027
1014
1028
γ = 2.0
@@ -1020,27 +1034,27 @@ p_s = 150.0
1020
1034
Next, we'll create an instance of `AssetPriceModel` to feed into the
0 commit comments