Hi K, good to see you applying yourself. Good work. Question: What's the weighted average? I gather you aren't using LIFO. And, your 'actual cost' - is it LIFO, FIFO, or average?
Regarding your formula, I'll need to look at it. I'll need to derive it mathematically. I'll give it a looksee. But, my first reaction is that what is done to the buy should be done to the sell. You know, "what's good for the goose is good for the gander." :-)
Keep up the good work.
Matt