'Returns in-sample predictions or forecasts'

def predict(self, params, start=None, end=None, lags=1, trend='c'):

    start = self._get_predict_start(start, lags)
    (end, out_of_sample) = self._get_predict_end(end)
    if (end < start):
        raise ValueError('end    is    before    start')
    if (end == (start + out_of_sample)):
        return np.array([])
    k_trend = util.get_trendorder(trend)
    k = self.neqs
    k_ar = lags
    predictedvalues = np.zeros(((((end + 1) - start) + out_of_sample), k))
    if (k_trend != 0):
        intercept = params[:k_trend]
        predictedvalues += intercept
    y = self.y
    X = util.get_var_endog(y, lags, trend=trend, has_constant='raise')
    fittedvalues = np.dot(X, params)
    fv_start = (start - k_ar)
    pv_end = min(len(predictedvalues), (len(fittedvalues) - fv_start))
    fv_end = min(len(fittedvalues), ((end - k_ar) + 1))
    predictedvalues[:pv_end] = fittedvalues[fv_start:fv_end]
    if (not out_of_sample):
        return predictedvalues
    y = y[(- k_ar):]
    coefs = params[k_trend:].reshape((k_ar, k, k)).swapaxes(1, 2)
    predictedvalues[pv_end:] = forecast(y, coefs, intercept, out_of_sample)
    return predictedvalues
