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.