'Estimate lag coefficients of an ARIMA process.
Parameters
order : sequence
p,d,q where p is the number of AR lags, d is the number of
differences to induce stationarity, and q is the number of
MA lags to estimate.
method : str {"ls", "ssm"}
Method of estimation.  LS is conditional least squares.
SSM is state-space model and the Kalman filter is used to
maximize the exact likelihood.
rhoy0, rhoe0 : array_like (optional)
starting values for estimation
Returns
(rh, cov_x, infodict, mesg, ier) : output of scipy.optimize.leastsq
rh :
estimate of lag parameters, concatenated [rhoy, rhoe]
cov_x :
unscaled (!) covariance matrix of coefficient estimates'

def fit(self, order=(0, 0), start_params=None, method='ls', **optkwds):

    if (not hasattr(order, '__iter__')):
        raise ValueError(('order    must    be    an    iterable    sequence.        Got    type    %s    instead' % type(order)))
    (p, q) = order
    self.nar = p
    self.nma = q
    x = self.endog.squeeze()
    if (start_params is None):
        arcoefs0 = (0.5 * np.ones(p))
        macoefs0 = (0.5 * np.ones(q))
        start_params = np.r_[(arcoefs0, macoefs0)]
    method = method.lower()
    if (method == 'ls'):
        optim_kwds = dict(ftol=1e-10, full_output=True)
        optim_kwds.update(optkwds)
        (rh, cov_x, infodict, mesg, ier) = optimize.leastsq(self.geterrors, start_params, **optim_kwds)
    elif (method == 'ssm'):
        pass
    else:
        errfnsum = (lambda rho: np.sum((self.geterrors(rho) ** 2)))
        optim_kwds = dict(maxiter=2, full_output=True)
        optim_kwds.update(optkwds)
        (rh, fopt, gopt, cov_x, _, _, ier) = optimize.fmin_bfgs(errfnsum, start_params, **optim_kwds)
        (infodict, mesg) = (None, None)
    self.params = rh
    self.ar_est = np.concatenate(([1], (- rh[:p])))
    self.ma_est = np.concatenate(([1], rh[p:(p + q)]))
    self.error_estimate = self.geterrors(rh)
    return (rh, cov_x, infodict, mesg, ier)
