Exemple #1
0
    def test_euler_maruyama(self):
        rnd.random_state(np.random.RandomState(seed=42), force=True)

        W = proc.WienerProcess.create_2d(mean1=-.5, mean2=3., sd1=3., sd2=4., cor=.5)
        em = sim.EulerMaruyama(process=W)
        
        t, v = next(em)
        npt.assert_almost_equal(t, 0.)
        npt.assert_almost_equal(v, npu.col(0.0, 0.0))

        t, v = next(em)
        npt.assert_almost_equal(t, 1.)
        npt.assert_almost_equal(v, npu.col(0.9901425, 3.5144667))
Exemple #2
0
    def test_run(self):
        rnd.random_state(np.random.RandomState(seed=42), force=True)

        W = proc.WienerProcess.create_2d(mean1=.25, mean2=.5, sd1=3., sd2=4., cor=.5)
        em = sim.EulerMaruyama(process=W)
        
        df = sim.run(em, nstep=10)
        pdt.assert_frame_equal(df, pd.DataFrame(data=[
                [0.000000, 0.000000],
                [1.740142, 1.014467],
                [3.933208, 8.085774],
                [3.480748, 7.306393],
                [8.468386, 13.623291],
                [7.309963, 15.063825],
                [6.169710, 13.023654],
                [7.145597, 7.379782],
                [2.220843, 2.482125],
                [-0.567650, 2.045047]],
                index=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]))