'Returns in-sample and out-of-sample prediction.
Parameters
params : array
The fitted model parameters.
start : int, str, or datetime
Zero-indexed observation number at which to start forecasting, ie.,
the first forecast is start. Can also be a date string to
parse or a datetime type.
end : int, str, or datetime
Zero-indexed observation number at which to end forecasting, ie.,
the first forecast is start. Can also be a date string to
parse or a datetime type.
dynamic : bool
The `dynamic` keyword affects in-sample prediction. If dynamic
is False, then the in-sample lagged values are used for
prediction. If `dynamic` is True, then in-sample forecasts are
used in place of lagged dependent variables. The first forecasted
value is `start`.
Returns
predicted values : array
Notes
The linear Gaussian Kalman filter is used to return pre-sample fitted
values. The exact initial Kalman Filter is used. See Durbin and Koopman
in the references for more information.'

def predict(self, params, start=None, end=None, dynamic=False):

    (start, end, out_of_sample, _) = self._get_prediction_index(start, end, dynamic)
    if ((start - end) > 1):
        raise ValueError('end    is    before    start')
    k_ar = self.k_ar
    k_trend = self.k_trend
    method = self.method
    endog = self.endog.squeeze()
    if dynamic:
        out_of_sample += ((end - start) + 1)
        return _ar_predict_out_of_sample(endog, params, k_ar, k_trend, out_of_sample, start)
    predictedvalues = np.zeros(((end + 1) - start))
    if (method == 'mle'):
        if k_trend:
            mu = (params[0] / (1 - np.sum(params[k_trend:])))
        if (start < k_ar):
            self._presample_fit(params, start, k_ar, min((k_ar - 1), end), (endog[:k_ar] - mu), predictedvalues)
            predictedvalues[:(k_ar - start)] += mu
    if (end < k_ar):
        return predictedvalues
    fittedvalues = dot(self.X, params)
    pv_start = max((k_ar - start), 0)
    fv_start = max((start - k_ar), 0)
    fv_end = min(len(fittedvalues), ((end - k_ar) + 1))
    predictedvalues[pv_start:] = fittedvalues[fv_start:fv_end]
    if out_of_sample:
        forecastvalues = _ar_predict_out_of_sample(endog, params, k_ar, k_trend, out_of_sample)
        predictedvalues = np.r_[(predictedvalues, forecastvalues)]
    return predictedvalues
