def tail_avg(timeseries):
 try:
  t = (((timeseries[(-1)][1] + timeseries[(-2)][1]) + timeseries[(-3)][1]) / 3)
  return t
 except IndexError:
  return timeseries[(-1)][1]

def tail_avg ( timeseries ) : try : t = ( ( ( timeseries [ ( - 1 ) ] [ 1 ] + timeseries [ ( - 2 ) ] [ 1 ] ) + timeseries [ ( - 3 ) ] [ 1 ] ) / 3 ) return t except IndexError : return timeseries [ ( - 1 ) ] [ 1 ]
this is a utility function used to calculate the average of the last three datapoints in the series as a measure .