def fit(self, start_params=None, trend='c', method="css-mle",
            transparams=True, solver='lbfgs', maxiter=50, full_output=1,
            disp=5, callback=None, **kwargs):
        k_ar = self.k_ar
        k_ma = self.k_ma

        # enforce invertibility
        self.transparams = transparams

        endog, exog = self.endog, self.exog
        k_exog = self.k_exog
        self.nobs = len(endog)  # this is overwritten if method is 'css'

        # (re)set trend and handle exogenous variables
        # always pass original exog
        k_trend, exog = _make_arma_exog(endog, self.exog, trend)

        # Check has something to estimate
        if k_ar == 0 and k_ma == 0 and k_trend == 0 and k_exog == 0:
            raise ValueError("Estimation requires the inclusion of least one "
                         "AR term, MA term, a constant or an exogenous "
                         "variable.")

        # check again now that we know the trend
        _check_estimable(len(endog), k_ar + k_ma + k_exog + k_trend)

        self.k_trend = k_trend
        self.exog = exog    # overwrites original exog from __init__

        # (re)set names for this model
        self.exog_names = _make_arma_names(self.data, k_trend, (k_ar, k_ma),
                                           self.exog_names)
        k = k_trend + k_exog

        # choose objective function
        if k_ma == 0 and k_ar == 0:
            method = "css"  # Always CSS when no AR or MA terms

        self.method = method = method.lower()

        # adjust nobs for css
        if method == 'css':
            self.nobs = len(self.endog) - k_ar

        if start_params is not None:
            start_params = np.asarray(start_params)

        else:  # estimate starting parameters
            start_params = self._fit_start_params((k_ar, k_ma, k), method)

        if transparams:  # transform initial parameters to ensure invertibility
            start_params = self._invtransparams(start_params)

        if solver == 'lbfgs':
            kwargs.setdefault('pgtol', 1e-8)
            kwargs.setdefault('factr', 1e2)
            kwargs.setdefault('m', 12)
            kwargs.setdefault('approx_grad', True)
        mlefit = super(ARMA, self).fit(start_params, method=solver,
                                       maxiter=maxiter,
                                       full_output=full_output, disp=disp,
                                       callback=callback, **kwargs)
        params = mlefit.params

        if transparams:  # transform parameters back
            params = self._transparams(params)

        self.transparams = False  # so methods don't expect transf.

        normalized_cov_params = None  # TODO: fix this
        armafit = ARMAResults(self, params, normalized_cov_params)
        armafit.mle_retvals = mlefit.mle_retvals
        armafit.mle_settings = mlefit.mle_settings
        return ARMAResultsWrapper(armafit)


#NOTE: the length of endog changes when we give a difference to fit
#so model methods are not the same on unfit models as fit ones
#starting to think that order of model should be put in instantiation...
Fits ARMA(p,q) model using exact maximum likelihood via Kalman filter.
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/arima_model.py/ARMA.fit