To understand your performance problems you need to know that if you are updating an indexed table, every time you insert or delete a row the index must be modified to be kept up-to-date.
Since you are starting with an empty table, you are actually modifying the index more times than there are rows in the entire table! I am not surprised performance is so slow. It is standard practice for DBAs (Oracle, Sybase etc.) if they are doing a complete table load, they drop indexes first, do the load and then put the indexes back on.
I suggest you look at sorting the data in order of the key variable(s), followed by the earliest to latest transactions for each key. With some FIRST. and LAST. processing with a SET statement and a BY statement I suspect you can get what you want much faster.