Ejemplo n.º 1
0
def test_expand_2D_already_filled():
    _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250],
                [38000, 74000, 36900, 49400, 73800, 36900],
                [40000, 74900, 37450, 50200, 74900, 37450]]
    res = Policy.expand_2D(_II_brk2, inflate=True, inflation_rates=[0.02] * 5,
                           num_years=3)
    npt.assert_array_equal(res, np.array(_II_brk2))
Ejemplo n.º 2
0
def test_expand_2D_short_array():
    x = np.array([[1, 2, 3]], dtype=np.float64)
    val = np.array([1, 2, 3], dtype=np.float64)
    exp2 = np.array([val * math.pow(1.02, i) for i in range(1, 5)])
    exp1 = np.array([1, 2, 3], dtype=np.float64)
    exp = np.zeros((5, 3))
    exp[:1] = exp1
    exp[1:] = exp2
    res = Policy.expand_2D(x, inflate=True, inflation_rates=[0.02] * 5, num_years=5)
    npt.assert_allclose(exp, res)
Ejemplo n.º 3
0
def test_expand_2D_short_array():
    x = np.array([[1, 2, 3]], dtype='f8')
    val = np.array([1, 2, 3], dtype='f8')
    exp2 = np.array([val * math.pow(1.02, i) for i in range(1, 5)])
    exp1 = np.array([1, 2, 3], dtype='f8')
    exp = np.zeros((5, 3))
    exp[:1] = exp1
    exp[1:] = exp2
    res = Policy.expand_2D(x, inflate=True, inflation_rates=[0.02] * 5,
                           num_years=5)
    assert np.allclose(exp, res)
Ejemplo n.º 4
0
def test_expand_2D_variable_rates():
    x = np.array([[1, 2, 3]], dtype=np.float64)
    cur = np.array([1, 2, 3], dtype=np.float64)
    irates = [0.02, 0.02, 0.02, 0.03, 0.035]
    exp2 = []
    for i in range(0, 4):
        idx = i + len(x) - 1
        cur = np.array(cur * (1.0 + irates[idx]))
        print("cur is ", cur)
        exp2.append(cur)
    exp1 = np.array([1, 2, 3], dtype=np.float64)
    exp = np.zeros((5, 3), dtype=np.float64)
    exp[:1] = exp1
    exp[1:] = exp2
    res = Policy.expand_2D(x, inflate=True, inflation_rates=irates, num_years=5)
    npt.assert_allclose(exp, res)
Ejemplo n.º 5
0
def test_expand_2D_variable_rates():
    x = np.array([[1, 2, 3]], dtype=np.float64)
    cur = np.array([1, 2, 3], dtype=np.float64)
    irates = [0.02, 0.02, 0.02, 0.03, 0.035]
    exp2 = []
    for i in range(0, 4):
        idx = i + len(x) - 1
        cur = np.array(cur * (1.0 + irates[idx]))
        print("cur is ", cur)
        exp2.append(cur)
    exp1 = np.array([1, 2, 3], dtype=np.float64)
    exp = np.zeros((5, 3), dtype=np.float64)
    exp[:1] = exp1
    exp[1:] = exp2
    res = Policy.expand_2D(x,
                           inflate=True,
                           inflation_rates=irates,
                           num_years=5)
    npt.assert_allclose(exp, res)
Ejemplo n.º 6
0
def test_expand_2D_variable_rates():
    x = np.array([[1, 2, 3]], dtype='f8')
    cur = np.array([1, 2, 3], dtype='f8')
    irates = [0.02, 0.02, 0.02, 0.03, 0.035]

    exp2 = []
    for i in range(0, 4):
        idx = i + len(x) - 1
        cur = np.array(cur * (1.0 + irates[idx]))
        print("cur is ", cur)
        exp2.append(cur)

    # exp2 = np.array([val * math.pow(1.02, i) for i in range(1, 5)])
    exp1 = np.array([1, 2, 3], dtype='f8')
    exp = np.zeros((5, 3))
    exp[:1] = exp1
    exp[1:] = exp2
    res = Policy.expand_2D(x, inflate=True, inflation_rates=irates,
                           num_years=5)
    npt.assert_array_equal(res, np.array(exp).astype('f8', casting='unsafe'))
    assert np.allclose(exp, res)
Ejemplo n.º 7
0
def test_expand_2D_partial_expand():
    _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250],
                [38000, 74000, 36900, 49400, 73800, 36900],
                [40000, 74900, 37450, 50200, 74900, 37450]]
    # We have three years worth of data, need 4 years worth,
    # but we only need the inflation rate for year 3 to go
    # from year 3 -> year 4
    inf_rates = [0.02, 0.02, 0.03]
    exp1 = 40000 * 1.03
    exp2 = 74900 * 1.03
    exp3 = 37450 * 1.03
    exp4 = 50200 * 1.03
    exp5 = 74900 * 1.03
    exp6 = 37450 * 1.03
    exp = [[36000, 72250, 36500, 48600, 72500, 36250],
           [38000, 74000, 36900, 49400, 73800, 36900],
           [40000, 74900, 37450, 50200, 74900, 37450],
           [exp1, exp2, exp3, exp4, exp5, exp6]]
    res = Policy.expand_2D(_II_brk2, inflate=True, inflation_rates=inf_rates,
                           num_years=4)
    npt.assert_array_equal(res, exp)
Ejemplo n.º 8
0
def test_expand_2D_partial_expand():
    _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250],
                [38000, 74000, 36900, 49400, 73800, 36900],
                [40000, 74900, 37450, 50200, 74900, 37450]]
    # We have three years worth of data, need 4 years worth,
    # but we only need the inflation rate for year 3 to go
    # from year 3 -> year 4
    inf_rates = [0.02, 0.02, 0.03]
    exp1 = 40000 * 1.03
    exp2 = 74900 * 1.03
    exp3 = 37450 * 1.03
    exp4 = 50200 * 1.03
    exp5 = 74900 * 1.03
    exp6 = 37450 * 1.03
    exp = [[36000, 72250, 36500, 48600, 72500, 36250],
           [38000, 74000, 36900, 49400, 73800, 36900],
           [40000, 74900, 37450, 50200, 74900, 37450],
           [exp1, exp2, exp3, exp4, exp5, exp6]]
    exp = np.array(exp).astype('i4', casting='unsafe')
    res = Policy.expand_2D(_II_brk2, inflate=True, inflation_rates=inf_rates,
                           num_years=4)
    npt.assert_array_equal(res, exp)