def meanreturn(rates):
    """
    Calculates the average rate of return given a list of returns.

    [ r1, r2, r3, r4, r5 ... rn ]

    r = [(1+r1)*(1+r2)*(1+r2) .... * (1+rn)]^(1/n) - 1

    :param rates: List of interest rate
    :return: Geometric mean return

    Example:
        Suppose you have invested your savings in the stock market for five years.
        If your returns each year were 90%, 10%, 20%, 30% and -90%, what would your
        average return be during this period? Ans. -20%


    >>> import m2py.finance.finance as fin
    >>> # Return in percent
    >>> 100*fin.meanreturn([0.9, 0.10, 0.20, 0.30, -0.90])
    -20.080238920753235

    Reference: http://www.investopedia.com/ask/answers/06/geometricmean.asp
    """
    prod = 1

    for r in rates:
        prod = prod * (1 + r)

    return prod ** (1.0 / len(rates)) - 1