Calculating a Weighted Average and its Variance

Hi I am not sure this constitutes an advanced query or a basic one. It has me beaten! I am trying to find a formula and so construct a computer algorithm for calculating the weighted average and variance (taking into account the weights) for a series of data. The application is a series of stock data (weighted by volume) and for computational efficiency I'd like to use an algorithm that does not need to re-iterate the whole series when a new piece of data is added to the sample.

For a non weighted series its straight forward for each point (n) in the series the variance and mean are

for each piece of data in the series

n=n+1

Mean = Sum/n

Variance = (SumSqrs - Square(Sum)/n)/(n-1)

end

When new data arrives the loop can be run once more for the new data. For a weighted series I need to scale each point by

Weight(n)/Weight(total)

The problem I have is that each time a new piece of data is added the Total Weight increases. As far as I can see this will require each point in the series to be re-weighed using the new total weighting?

My maths isn't good enough to do it by raw brain power (I tried). I also used a trial and error approach ...adding weighting in different places...keeping a sum of the weights etc. But while close it dose not appear to be correct.

There are a number of clever algorithms Algorithms for calculating variance - Wikipedia, the free encyclopedia for calculating variance in no weighted series but I have not found anything for weighted?

Any suggestions would be welcome

Thanks in advance,

Nick.