GitHub

@@ -212,11 +212,11 @@ One natural way to answer questions about Markov chains is to simulate them.

212212213213

(To approximate the probability of event $E$, we can simulate many times and count the fraction of times that $E$ occurs).

214214215-

Nice functionality for simulating Markov chains exists in [QuantEcon.py](https://quantecon.org/quantecon-py).

215+

Nice functionality for simulating Markov chains exists in [QuantEcon.py](https://quantecon.org/quantecon-py/).

216216217217

* Efficient, bundled with lots of other useful routines for handling Markov chains.

218218219-

However, it's also a good exercise to roll our own routines --- let's do that first and then come back to the methods in [QuantEcon.py](https://quantecon.org/quantecon-py).

219+

However, it's also a good exercise to roll our own routines --- let's do that first and then come back to the methods in [QuantEcon.py](https://quantecon.org/quantecon-py/).

220220221221

In these exercises, we'll take the state space to be $S = 0,\ldots, n-1$.

222222

@@ -231,7 +231,7 @@ The Markov chain is then constructed as discussed above. To repeat:

231231232232

To implement this simulation procedure, we need a method for generating draws from a discrete distribution.

233233234-

For this task, we'll use `random.draw` from [QuantEcon](https://quantecon.org/quantecon-py), which works as follows:

234+

For this task, we'll use `random.draw` from [QuantEcon](https://quantecon.org/quantecon-py/), which works as follows:

235235236236

```{code-cell} python3

237237

ψ = (0.3, 0.7) # probabilities over {0, 1}

@@ -294,7 +294,7 @@ always close to 0.25, at least for the `P` matrix above.

294294295295

### Using QuantEcon's Routines

296296297-

As discussed above, [QuantEcon.py](https://quantecon.org/quantecon-py) has routines for handling Markov chains, including simulation.

297+

As discussed above, [QuantEcon.py](https://quantecon.org/quantecon-py/) has routines for handling Markov chains, including simulation.

298298299299

Here's an illustration using the same P as the preceding example

300300

@@ -306,7 +306,7 @@ X = mc.simulate(ts_length=1_000_000)

306306

np.mean(X == 0)

307307

```

308308309-

The [QuantEcon.py](https://quantecon.org/quantecon-py) routine is [JIT compiled](https://python-programming.quantecon.org/numba.html#numba-link) and much faster.

309+

The [QuantEcon.py](https://quantecon.org/quantecon-py/) routine is [JIT compiled](https://python-programming.quantecon.org/numba.html#numba-link) and much faster.

310310311311

```{code-cell} ipython

312312

%time mc_sample_path(P, sample_size=1_000_000) # Our homemade code version

@@ -556,7 +556,7 @@ $$

556556

It's clear from the graph that this stochastic matrix is irreducible: we can eventually

557557

reach any state from any other state.

558558559-

We can also test this using [QuantEcon.py](https://quantecon.org/quantecon-py)'s MarkovChain class

559+

We can also test this using [QuantEcon.py](https://quantecon.org/quantecon-py/)'s MarkovChain class

560560561561

```{code-cell} python3

562562

P = [[0.9, 0.1, 0.0],

@@ -775,7 +775,7 @@ One option is to regard solving system {eq}`eq:eqpsifixed` as an eigenvector pr

775775

$\psi$ such that $\psi = \psi P$ is a left eigenvector associated

776776

with the unit eigenvalue $\lambda = 1$.

777777778-

A stable and sophisticated algorithm specialized for stochastic matrices is implemented in [QuantEcon.py](https://quantecon.org/quantecon-py).

778+

A stable and sophisticated algorithm specialized for stochastic matrices is implemented in [QuantEcon.py](https://quantecon.org/quantecon-py/).

779779780780

This is the one we recommend:

781781

@@ -1322,7 +1322,7 @@ $$

1322132213231323

Tauchen's method {cite}`Tauchen1986` is the most common method for approximating this continuous state process with a finite state Markov chain.

132413241325-

A routine for this already exists in [QuantEcon.py](https://quantecon.org/quantecon-py) but let's write our own version as an exercise.

1325+

A routine for this already exists in [QuantEcon.py](https://quantecon.org/quantecon-py/) but let's write our own version as an exercise.

1326132613271327

As a first step, we choose

13281328

@@ -1363,13 +1363,13 @@ The exercise is to write a function `approx_markov(rho, sigma_u, m=3, n=7)` that

13631363

$\{x_0, \ldots, x_{n-1}\} \subset \mathbb R$ and $n \times n$ matrix

13641364

$P$ as described above.

136513651366-

* Even better, write a function that returns an instance of [QuantEcon.py's](https://quantecon.org/quantecon-py) MarkovChain class.

1366+

* Even better, write a function that returns an instance of [QuantEcon.py's](https://quantecon.org/quantecon-py/) MarkovChain class.

13671367

```

1368136813691369

```{solution} fm_ex3

13701370

:class: dropdown

137113711372-

A solution from the [QuantEcon.py](https://quantecon.org/quantecon-py) library

1372+

A solution from the [QuantEcon.py](https://quantecon.org/quantecon-py/) library

13731373

can be found [here](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/markov/approximation.py).

1374137413751375

```

Read the original on github.com ↗