I'm not sure if it's exactly what you're looking for but play around with this attached script (I don't recall where I found it to give credit or citation and unfortunately I don't have the source code). It calculates the basket profit of specified ...