SolowModel._solow_model()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
import functools
2
3
from ... import problems
4
5
6
class SolowModel(problems.IVP):
7
    """
8
    Class representing a generic Solow growth model.
9
10
    Attributes
11
    ----------
12
    equilibrium_capital : function
13
        Equilibrium value for capital (per unit effective labor).
14
    intensive_output : function
15
        Output (per unit effective labor supply).
16
    params : dict(str: float)
17
        Dictionary of model parameters.
18
19
    """
20
21
    def __init__(self, f, k_star, params):
22
        """
23
        Initialize an instance of the SolowModel class.
24
25
        Parameters
26
        ----------
27
        f : function
28
            Output (per unit effective labor supply).
29
        k_star : function
30
            Equilibrium value for capital (per unit effective labor).
31
        params : dict(str: float)
32
            Dictionary of model parameters.
33
34
        """
35
        rhs = self._rhs_factory(f)
36
        self._equilbrium_capital = k_star
37
        self._intensive_output = f
38
        super(SolowModel, self).__init__(self._initial_condition, 1, 1, params, rhs)
39
40
    @property
41
    def equilibrium_capital(self):
42
        return self._equilbrium_capital
43
44
    @property
45
    def intensive_output(self):
46
        return self._intensive_output
47
48
    @staticmethod
49
    def _initial_condition(t, k, k0, **params):
50
        return [k - k0]
51
52
    @classmethod
53
    def _solow_model(cls, t, k, f, delta, g, n, s, **params):
54
        return [s * f(k, **params) - (g + n + delta) * k]
55
56
    @classmethod
57
    def _rhs_factory(cls, f):
58
        return functools.partial(cls._solow_model, f=f)
59