def df_restrict_dates(df_in, start_date, end_date, multi_index=False, date_name='date'):

    """
    restrict input dataframe to certain date range
    boundaries are inclusive
    index must be in date format

    :param df_in: pandas data frame, index must be in datetime format; can deal with multi-index now as well
    :param start_date: datetime.datetime (date or certain string formats might also work)
    :param end_date: datetime.datetime (date or certain string formats might also work)
    :return: reduced dateframe
    """

    df_out = df_in.copy()
    if multi_index:
        mask = (df_out.index.get_level_values(date_name) >= start_date) & \
               (df_out.index.get_level_values(date_name) <= end_date)
    else:
        mask = (df_out.index >= start_date) & (df_out.index <= end_date)
    return df_out[mask]