generating averages and ewma handling undefined values