Average cost of units over time

57 Views Asked by At

I buy and sell units at varying price and I always have a varying stock of units bought in different batches at different prices.
I always keep the current_price and the current_volume and I base my decissions of the current_price.

Every time I buy I recalculate current_price as:
current_price = (current_price * current_vol + batch_price*batch_vol) / (current_vol+batch_vol)

Every time I sell I simply subtract batch_vol from current_vol

Is this a sensible strategy? at any given time the current_price is not exactly equal to the last buy orders that match the volume but it seems like a good approximation.

Should I use something else? I am interested in simplicity, if this is not blatantly wrong I can live with it for external reasons.

1

There are 1 best solutions below

0
On

What you are doing makes sense. It does track the average unit cost of the items in your inventory, diluting the old ones with the new ones. It assumes that each time you sell and item, it is part new one and part old one.