def METHOD_NAME(
    optimal_position: pd.Series,
    pos_buffers: pd.DataFrame,
    trade_to_edge: bool = False,
    roundpositions: bool = False,
) -> pd.Series:
    """
    Apply a buffer to a position
    If position is outside the buffer, we either trade to the edge of the
    buffer, or to the optimal
    If we're rounding positions, then we floor and ceiling the buffers.
    :param position: optimal position
    :type position: pd.Series
    :param pos_buffers:
    :type pos_buffers: Tx2 pd.dataframe, top_pos and bot_pos
    :param trade_to_edge: Trade to the edge (TRue) or the optimal (False)
    :type trade_to_edge: bool
    :param round_positions: Produce rounded positions
    :type round_positions: bool
    :returns: pd.Series
    """
    pos_buffers = pos_buffers.ffill()
    use_optimal_position = optimal_position.ffill()
    top_pos = pos_buffers.top_pos
    bot_pos = pos_buffers.bot_pos
    if roundpositions:
        use_optimal_position = use_optimal_position.round()
        top_pos = top_pos.round()
        bot_pos = bot_pos.round()
    current_position = use_optimal_position.values[0]
    if np.isnan(current_position):
        current_position = 0.0
    buffered_position_list = [current_position]
    for idx in range(len(optimal_position.index))[1:]:
        current_position = apply_buffer_single_period(
            current_position,
            float(use_optimal_position.values[idx]),
            float(top_pos.values[idx]),
            float(bot_pos.values[idx]),
            trade_to_edge=trade_to_edge,
        )
        buffered_position_list.append(current_position)
    buffered_position = pd.Series(buffered_position_list, index=optimal_position.index)
    return buffered_position