def simEM(self, xzero=None, nobs=100, T=1, dt=None, nrepl=1, Tratio=4):
        #TODO: reverse parameterization to start with final nobs and DT
        nobs = nobs * Tratio  # simple way to change parameter
        # maybe wrong parameterization,
        # drift too large, variance too small ? which dt/Dt
        # _drift, _sig independent of dt is wrong
        if xzero is None:
            xzero = self.xzero
        if dt is None:
            dt = T*1.0/nobs
        W, t = self.simulateW(nobs=nobs, T=T, dt=dt, nrepl=nrepl)
        dW = self.dW
        t = np.linspace(dt, 1, nobs)
        Dt = Tratio*dt;
        L = nobs/Tratio;        # L EM steps of size Dt = R*dt
        Xem = np.zeros((nrepl,L));    # preallocate for efficiency
        Xtemp = xzero
        Xem[:,0] = xzero
        for j in np.arange(1,L):
           #Winc = np.sum(dW[:,Tratio*(j-1)+1:Tratio*j],1)
           Winc = np.sum(dW[:,np.arange(Tratio*(j-1)+1,Tratio*j)],1)
           #Xtemp = Xtemp + Dt*lamda*Xtemp + mu*Xtemp*Winc;
           Xtemp = Xtemp + self._drift(x=Xtemp) + self._sig(x=Xtemp) * Winc
           #Dt*lamda*Xtemp + mu*Xtemp*Winc;
           Xem[:,j] = Xtemp
        return Xem
from Higham 2001
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/sandbox/tsa/diffusion.py/AffineDiffusion.simEM