GitHub

File tree

  • lectures

    • _static/lecture_specific/optgrowth_fast

Original file line numberDiff line numberDiff line change

@@ -1,3 +1,5 @@

1+

from numba import float64

2+

from numba.experimental import jitclass

13
24

opt_growth_data = [

35

('α', float64), # Production parameter

@@ -12,8 +14,8 @@

1214

class OptimalGrowthModel:

1315
1416

def __init__(self,

15-

α=0.4,

16-

β=0.96,

17+

α=0.4,

18+

β=0.96,

1719

μ=0,

1820

s=0.1,

1921

grid_max=4,

@@ -29,12 +31,12 @@ def __init__(self,

2931

# Store shocks (with a seed, so results are reproducible)

3032

np.random.seed(seed)

3133

self.shocks = np.exp(μ + s * np.random.randn(shock_size))

32-
34+
3335
3436

def f(self, k):

3537

"The production function"

3638

return k**self.α

37-
39+
3840
3941

def u(self, c):

4042

"The utility function"

@@ -52,5 +54,3 @@ def u_prime(self, c):

5254

def u_prime_inv(self, c):

5355

"Inverse of u'"

5456

return 1/c

55-
56-
Original file line numberDiff line numberDiff line change

@@ -1,4 +1,5 @@

1-
1+

from numba import float64

2+

from numba.experimental import jitclass

23
34

opt_growth_data = [

45

('α', float64), # Production parameter

@@ -14,11 +15,11 @@

1415

class OptimalGrowthModel_CRRA:

1516
1617

def __init__(self,

17-

α=0.4,

18-

β=0.96,

18+

α=0.4,

19+

β=0.96,

1920

μ=0,

2021

s=0.1,

21-

γ=1.5,

22+

γ=1.5,

2223

grid_max=4,

2324

grid_size=120,

2425

shock_size=250,

@@ -32,7 +33,7 @@ def __init__(self,

3233

# Store shocks (with a seed, so results are reproducible)

3334

np.random.seed(seed)

3435

self.shocks = np.exp(μ + s * np.random.randn(shock_size))

35-
36+
3637
3738

def f(self, k):

3839

"The production function."

@@ -52,4 +53,3 @@ def u_prime(self, c):

5253
5354

def u_prime_inv(c):

5455

return c**(-1 / self.γ)

55-
Original file line numberDiff line numberDiff line change

@@ -59,7 +59,6 @@ Let's start with some imports:

5959

import matplotlib.pyplot as plt

6060

plt.rcParams["figure.figsize"] = (11, 5) #set default figure size

6161

import numpy as np

62-

import quantecon as qe

6362

from quantecon.markov import DiscreteDP

6463

from numba import jit

6564

```

@@ -441,4 +440,3 @@ ax.legend(loc='upper right')

441440
442441

plt.show()

443442

```

444-
Original file line numberDiff line numberDiff line change

@@ -65,11 +65,9 @@ Let's start with some imports:

6565

import matplotlib.pyplot as plt

6666

plt.rcParams["figure.figsize"] = (11, 5) #set default figure size

6767

import numpy as np

68-

import quantecon as qe

6968

from interpolation import interp

7069

from quantecon.optimize import brentq

71-

from numba import njit, float64

72-

from numba.experimental import jitclass

70+

from numba import njit

7371

```

7472
7573

## The Euler Equation

Original file line numberDiff line numberDiff line change

@@ -29,7 +29,6 @@ In addition to what's in Anaconda, this lecture will need the following librarie

2929

---

3030

tags: [hide-output]

3131

---

32-

!pip install quantecon

3332

!pip install interpolation

3433

```

3534

@@ -55,11 +54,8 @@ Let's start with some standard imports:

5554

import matplotlib.pyplot as plt

5655

plt.rcParams["figure.figsize"] = (11, 5) #set default figure size

5756

import numpy as np

58-

import quantecon as qe

5957

from interpolation import interp

60-

from numba import njit, float64

61-

from numba.experimental import jitclass

62-

from quantecon.optimize import brentq

58+

from numba import njit

6359

```

6460
6561

## Key Idea

@@ -266,4 +262,3 @@ has managed to shave off still more run time without compromising accuracy.

266262

This is due to the lack of a numerical root-finding step.

267263
268264

We can now solve the optimal growth model at given parameters extremely fast.

269-
Original file line numberDiff line numberDiff line change

@@ -54,7 +54,7 @@ import matplotlib.pyplot as plt

5454

plt.rcParams["figure.figsize"] = (11, 5) #set default figure size

5555

import numpy as np

5656

import sympy as sym

57-

from sympy import init_printing, latex

57+

from sympy import init_printing

5858

from matplotlib import cm

5959

from mpl_toolkits.mplot3d import Axes3D

6060

```

Read the original on github.com ↗