I think you need to define this namedtuple outside of this function so that it can be used elsewhere. For example, on line 207, you're using `x[3]` when you could be using `x.date`.