def stdev(seriesList, time): count = 0 for series in seriesList: stddevs = TimeSeries("stddev(%s,%.1f)" % (series.name, float(time)), series.start, series.end, series.step, []) stddevs.pathExpression = "stddev(%s,%.1f)" % (series.name, float(time)) avg = safeDiv(safeSum(series[:time]), time) sumOfSquares = sum(map(lambda (x): x * x, series[:time])) (sd, sumOfSquares) = doStdDev(sumOfSquares, 0, 0, time, avg) stddevs.append(sd) for (index, el) in enumerate(series[time:]): if el is None: continue toDrop = series[index] if toDrop is None: toDrop = 0 s = safeSum([safeMul(time, avg), el, -toDrop]) avg = safeDiv(s, time) (sd, sumOfSquares) = doStdDev(sumOfSquares, toDrop, series[index + time], time, avg) stddevs.append(sd) for i in range(0, time - 1): stddevs.insert(0, None) seriesList[count] = stddevs count = count + 1 return seriesList
def stdev(seriesList,time): count = 0 for series in seriesList: stddevs = TimeSeries("stddev(%s,%.1f)" % (series.name,float(time)),series.start,series.end,series.step,[]) stddevs.pathExpression = "stddev(%s,%.1f)" % (series.name,float(time)) avg = safeDiv(safeSum(series[:time]), time) sumOfSquares = sum(map(lambda(x): x * x, series[:time])) (sd, sumOfSquares) = doStdDev(sumOfSquares, 0, 0, time, avg) stddevs.append(sd) for (index, el) in enumerate(series[time:]): if el is None: continue toDrop = series[index] if toDrop is None: toDrop = 0 s = safeSum([safeMul(time, avg), el, -toDrop]) avg = safeDiv(s, time) (sd, sumOfSquares) = doStdDev(sumOfSquares, toDrop, series[index+time], time, avg) stddevs.append(sd) for i in range(0, time-1): stddevs.insert(0, None) seriesList[count] = stddevs count = count + 1 return seriesList
def movingAverage(seriesList,time): count = 0 for series in seriesList: movAvg = TimeSeries("movingAverage(%s,%.1f)" % (series.name,float(time)),series.start,series.end,series.step,[]) movAvg.pathExpression = "movingAverage(%s,%.1f)" % (series.name,float(time)) avg = safeDiv(safeSum(series[:time]), time) movAvg.append(avg) for (index, el) in enumerate(series[time:]): if el is None: continue toDrop = series[index] if toDrop is None: toDrop = 0 s = safeSum([safeMul(time, avg), el, -toDrop]) avg = safeDiv(s, time) movAvg.append(avg) for i in range(0, time-1): movAvg.insert(0, None) seriesList[count] = movAvg count = count + 1 return seriesList
def movingAverage(seriesList, time): count = 0 for series in seriesList: movAvg = TimeSeries( "movingAverage(%s,%.1f)" % (series.name, float(time)), series.start, series.end, series.step, []) movAvg.pathExpression = "movingAverage(%s,%.1f)" % (series.name, float(time)) avg = safeDiv(safeSum(series[:time]), time) movAvg.append(avg) for (index, el) in enumerate(series[time:]): if el is None: continue toDrop = series[index] if toDrop is None: toDrop = 0 s = safeSum([safeMul(time, avg), el, -toDrop]) avg = safeDiv(s, time) movAvg.append(avg) for i in range(0, time - 1): movAvg.insert(0, None) seriesList[count] = movAvg count = count + 1 return seriesList