Ejemplo n.º 1
0
def test_3():  # many steps (check that recursion does not bust stack)
    out = fs.recdyn(step=step,
                    data0=data0(),
                    steps=2000,
                    trials=10,
                    stdnorm=True)
    assert type(out) == xr.DataArray
Ejemplo n.º 2
0
def test_2():  # alternative seed
    out = fs.recdyn(step=step,
                    data0=data0(),
                    steps=10,
                    trials=500,
                    seed=123,
                    stdnorm=True)
    assert type(out) == xr.DataArray
    assert abs(float(out[:, 0, 10].mean()) - 1.0234) < 0.01
Ejemplo n.º 3
0
def test_1():  # use multi
    out = fs.recdyn(step=step,
                    data0=data0(),
                    steps=10,
                    trials=500,
                    multi=True,
                    stdnorm=True)
    assert type(out) == xr.DataArray
    assert abs(float(out[:, 0, 10].mean()) - 1.0234) < 0.01
Ejemplo n.º 4
0
def test_0():  # basic
    out = fs.recdyn(step=step,
                    data0=data0(),
                    steps=10,
                    trials=500,
                    stdnorm=True)
    assert type(out) == xr.DataArray
    print(out)
    print(out[:, 0, 10].mean())
    assert abs(float(out[:, 0, 10].mean()) - 1.0234) < 0.01
Ejemplo n.º 5
0
def step(data, draw):
    # take one step through time

    # value of p in previous period
    pLag1 = fs.recall(data, "p", lag=1)

    # uniform draw --> standard normal draw
    u = next(draw)
    eps = stats.norm.ppf(u)

    # update all intermediate variables
    pNew = gbm(s0=pLag1, dt=1.0 / 12.0, mu=0.01, sig=0.10, eps=eps)
    cNew = max(0.0, pNew - 1.0)

    # return updated price history
    dataNew = fs.chron(data, {"p": pNew, "c": cNew})
    return dataNew


# set up existing/historical data
steps = [0, 1, 2]
variables = ["p", "c"]
a = np.array([[1.0, np.nan], [1.01, np.nan], [0.99, np.nan]])
data0 = \
    xr.DataArray(data=a, coords=(('steps', steps), ('variables', variables)))

# simulate
out = fs.recdyn(step=step, data0=data0, steps=10, trials=20, multi=True)
print(out)