# Calculating average rolling cost stock for bulk products

How to calculate the current average cost of a product mixed in stock ?

The individual deliveries are not identifiable: it's gasoline delivered in bulk, each day has a different price and everything is mixed in the storage tanks.

I've worked out by trial and error and using real data from our network (500+ locations) the equation that gives the average price for one daily delivery with a 80 % stock renewal by day. i.e we start the day at 00:00 with 80 % of the stock from d-1, 16 % from d-2, 3% from d-3 etc.

As the day goes by, more and more stock is from today's price and at 23:59 we're at 80% priced at current figure, 16 % from d-1, 3% from d-2 etc.

The model works well and can give hour by hour (24 periods) the evolution of stock costs, but only for one daily delivery.

As a side note, after analysing a sample about 40 000 real delivery schedules, the average number by the hour is very constant. Basically, you can just assume that time of the day /24*100 = % of total deliveries done for the day.

Also there's no need to go back earlier than 3 days for product costs as even for a store getting only a delivery once a week the improvement on precision is not worth it.

What I'm looking for is to get and understand the general equation or procedure to get these ratios for different delivery schedules: some locations get filled-up only once a week and others nearly twice a day.

Basically I've got 7 variables say:

a=average frequency of deliveries/week (different for each store from 9/week to 1/week, decimal)

b=period number/24 (hour of the day, integer)

c=cost of product on d day

c'=cost of product on d-1

c''= cost of product on d-2

c'''=cost of product on d-3

And I guess I'm looking for the equation that'd give a problable average cost of product in inventory for a location at a particular period of the day.

I hope this make sense ?

At the moment I don't even know what terms I should be googling. Any hint on how to approach the problem would be appreciated.

You can just keep a running value of the gas in the tank. Say you buy 1000 gallons at 3, so your inventory is worth 3000. You sell half the stock, leaving stock worth 1500. Now you buy 500 gallons at 3.2 for 1600, so your stock is 1000 gallons and cost 3100. You sell 800 gallons, so you have 200 gallons worth $0.8 \cdot 3100=248$ You buy more, add the cost to your running average, etc. The basic idea is