GitHub

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

213213214214

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

215215216-

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

216+

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

217217218218

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

219219220-

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](http://quantecon.org/quantecon-py).

220+

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).

221221222222

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

223223

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

232232233233

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

234234235-

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

235+

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

236236237237

```{code-cell} python3

238238

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

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

295295296296

### Using QuantEcon's Routines

297297298-

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

298+

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

299299300300

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

301301

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

307307

np.mean(X == 0)

308308

```

309309310-

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

310+

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

311311312312

```{code-cell} ipython

313313

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

@@ -557,7 +557,7 @@ $$

557557

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

558558

reach any state from any other state.

559559560-

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

560+

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

561561562562

```{code-cell} python3

563563

P = [[0.9, 0.1, 0.0],

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

776776

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

777777

with the unit eigenvalue $\lambda = 1$.

778778779-

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

779+

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

780780781781

This is the one we recommend:

782782

@@ -867,7 +867,7 @@ The result tells us that the fraction of time the chain spends at state $x$ conv

867867

(new_interp_sd)=

868868

This gives us another way to interpret the stationary distribution --- provided that the convergence result in {eq}`llnfmc0` is valid.

869869870-

The convergence asserted in {eq}`llnfmc0` is a special case of a law of large numbers result for Markov chains --- see [EDTC](http://johnstachurski.net/edtc.html), section 4.3.4 for some additional information.

870+

The convergence asserted in {eq}`llnfmc0` is a special case of a law of large numbers result for Markov chains --- see [EDTC](https://johnstachurski.net/edtc.html), section 4.3.4 for some additional information.

871871872872

(mc_eg1-2)=

873873

### Example

@@ -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](http://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](http://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](http://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 ↗