ARIMA

Includes changes from code review.  
Not really a 'problem' but I would consider:

in_row := this_row BETWEEN td.first_row AND td.last_row;

more correct