def first_close_to_final(x, y, min_rel_proximity=0.05):
    """
    returns the chronologically first value of x where
    y was close to min_rel_proximity (y[-1] - y[0]) of
    the final value of y, i.e., y[-1].
    """
    min_abs_proximity = (y[-1] - y[0]) * min_rel_proximity
    final_y = y[-1]
    for i in range(len(x)):
        if abs(y[i] - final_y) < min_abs_proximity:
            return x[i]