In [1]:
%matplotlib inline
In [2]:
import os, sys
sys.path.append(os.path.abspath('../../main/python'))
In [3]:
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
import thalesians.tsa.processes as proc
import thalesians.tsa.randomness as rnd
import thalesians.tsa.simulation as sim
In [4]:
rnd.random_state(np.random.RandomState(seed=42), force=True);
In [5]:
W = proc.WienerProcess.create_2d(mean1=.25, mean2=.5, sd1=3., sd2=4., cor=-1.)
em = sim.EulerMaruyama(process=W)
In [6]:
df = sim.run(em, 100)
In [7]:
isinstance(W, proc.MarkovProcess)
Out[7]:
In [8]:
plt.plot(df);
In [9]:
rnd.random_state(np.random.RandomState(seed=42), force=True);
x = [0., 0.]
ts = [0.]; xs = [x]
for t, v in zip(sim.xtimes(1., 100., 1.), rnd.multivariate_normals(ndim=2)):
x = W.propagate(max(0, t-1), x, t, v)
ts.append(t); xs.append(x.flatten())
plt.plot(ts, xs);
In [10]:
df[0:10]
Out[10]:
In [11]:
next(em)
Out[11]:
In [12]:
ts, vs = [], []
for t, v in em:
ts.append(t); vs.append(v)
if t == 110: break
ts, vs
Out[12]:
In [13]:
plt.plot(ts, np.hstack(vs).T);
In [14]:
ts, vs = [], []
for t, v in em:
ts.append(t); vs.append(v.flatten())
if t == 120: break
ts, vs
Out[14]:
In [15]:
plt.plot(ts, vs);
In [16]:
ts = sim.xtimes(dt.datetime(2017, 5, 1), dt.datetime(2017, 6, 1), dt.timedelta(hours=12))
em = sim.EulerMaruyama(process=W, times=ts, time_unit=dt.timedelta(days=1.), flatten=True)
next(em)
Out[16]:
In [17]:
next(em)
Out[17]:
In [18]:
ts, vs = [], []
for t, v in em:
ts.append(t); vs.append(v)
plt.plot(ts, vs);
In [19]:
X = proc.OrnsteinUhlenbeckProcess(transition=1., vol=1.)
In [20]:
em = sim.EulerMaruyama(process=X, times=sim.xtimes(start=0., stop=5., step=1E-4))
df = sim.run(em)
plt.plot(df);
In [21]:
em = sim.EulerMaruyama(process=X, times=sim.xtimes(start=0., stop=5., step=1E-3))
df = sim.run(em)
plt.plot(df);
In [22]:
em = sim.EulerMaruyama(process=X, times=sim.xtimes(start=0., stop=5., step=1E-2))
df = sim.run(em)
plt.plot(df);