def moving_average(time_series, window_size=20, fwd_fill_to_end=0):
    """
    Computes a Simple Moving Average (SMA) function on a time series
    :param time_series: a pandas time series input containing numerical values
    :param window_size: a window size used to compute the SMA
    :param fwd_fill_to_end: index from which computation must stop and propagate last value
    :return: Simple Moving Average time series
    """
    if fwd_fill_to_end <= 0:
        sma = time_series.rolling(window=window_size).mean()
    else:
        sma = time_series.rolling(window=window_size).mean()
        sma[-fwd_fill_to_end:] = sma.iloc[-fwd_fill_to_end]

    '''
    Moving average feature is empty for the first *n* days, where *n* is the window size,
    so I'll use some backfill to fill NaN values
    '''
    sma.fillna(method='backfill', inplace=True)
    return sma