MichaelJMath
7/19/2017 - 10:58 PM

Calculate/Compute Forward Returns

Calculate/Compute Forward Returns

def calc_forward_returns(prices, period, dropna=False):
    """Calculate forward forward returns from a series of prices
    ------
    Inputs
    ------
    prices: pd.Series, pd.DataFrame
      Prices to calculate returns on.
    period: int
      Forward period for return calculation
    dropna: bool
      Drop NA's in dataframe?
    """
    fwd_returns = prices.pct_change(period).shift(-period)
    if dropna:
        return fwd_returns[:-period]
    return fwd_returns