def METHOD_NAME(
    period_index: int,
    list_of_starting_dates_per_period: list,
    start_date: datetime.datetime,
    date_method: str = "expanding",
    rollyears=20,
):
    period_start = list_of_starting_dates_per_period[period_index]
    period_end = list_of_starting_dates_per_period[period_index + 1]
    if date_method == "expanding":
        fit_start = start_date
    elif date_method == "rolling":
        yearidx_to_use = max(0, period_index - rollyears)
        fit_start = list_of_starting_dates_per_period[yearidx_to_use]
    else:
        raise Exception("date_method %s not known" % date_method)
    fit_end = period_start
    fit_date = fitDates(fit_start, fit_end, period_start, period_end)
    return fit_date