def trend(series, n):
    """Return the running average, minimum and maximum of a series for an n-
    element moving window."""
    meanvals = []
    minvals = []
    maxvals = []
    running = []
    for val in series:
        running.append(val)
        if len(running) > n:
            running.pop(0)
        meanvals.append(sum(running) / len(running))
        minvals.append(min(running))
        maxvals.append(max(running))
    return meanvals, minvals, maxvals