A moving weighted average algorithm under abnormal conditions
What is the moving weighted average method?
Baidu's explanation: The Moving weighted average method refers to the cost of each purchase plus the cost of the original inventory, divided by the quantity of each purchase and the original inventory of the quantity of the sum of stock,
Calculates the weighted average unit cost as a method of calculating the cost of the current month's inventory and the cost of ending inventory.
This can only be said to be the normal use of (or in the case of written ideal) moving weighted average algorithm.
This algorithm is built on the advanced goods (with the inventory cost), after the sale of the conditions can be calculated.
What do you mean, abnormal conditions?
Because there is the phenomenon of "first selling backward" exists. If the goods are not in stock, they will be sold. At this time, the product information is not perfect (only the price of goods, no price, no inventory quantity), the goods will be sold.
Each sale of a product reduces an inventory quantity, because there is no stock, so the inventory quantity of goods will appear "negative inventory".
Sales cost price is not known.
How to calculate the moving weighted average price of a commodity under unusual circumstances (hereinafter referred to as the average price)?
There are 3 kinds of situations:
1) When the original average price of a commodity = 0, the average price of the commodity = The cost price of the purchase
2) when the original average price of a commodity is null (the product has not been initialized, so the average price is null), the average price of the commodity = The cost price of the purchase
3) When the original average price of the goods >0, (original average price * Stock quantity + this purchase cost)/(stock quantity + this purchase quantity)
Stock Quantity = Original stock quantity + current purchase quantity
Inventory Cost = Average price * Inventory quantity
A moving weighted average algorithm under abnormal conditions