def _arma_predict_in_sample(start, end, endog, resid, k_ar, method):
    if 'mle' in method:
        fittedvalues = endog - resid  # get them all then trim
    else:
        fittedvalues = endog[k_ar:] - resid

    fv_start = start
    if 'mle' not in method:
        fv_start -= k_ar  # start is in terms of endog index
    fv_end = min(len(fittedvalues), end + 1)
    return fittedvalues[fv_start:fv_end]
Pre- and in-sample fitting for ARMA.
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/arima_model.py/_arma_predict_in_sample