So this is really a programming problem, but I thought it best to ask here.
I'm trying to calculate the Standard Deviation for a massive list of numbers (I get a new number every second), but I'd rather not have to keep the list of numbers in memory + go through the entire list each time I acquire a new number.
I've figured out a way to do this for the mean:
newMean = (currentMean + newNumber/currentCount) / (1 + 1/currentCount)
Basically I only need to store two things: the average + the count of numbers. I don't have to worry about keeping the list of numbers, and can work off the new number alone.
Is there something similar I can do with the SD? It doesn't have to be 100% accurate, but could be a rough approximation.
There is a standard estimator for the variance, traditionally called the sample variance, and equal to $\frac{1}{n-1} \sum_{k=1}^n \left (x_k-\overline{x} \right )^2$. This is unbiased among some other nice properties. It is impossible to implement this exact estimator in a "running" fashion (without storing the $x_i$ to sum them all at the end).
There is a "running variance" estimator, however, which does not need all the $x_k$ at once. To compute it, you define the "running mean" $m_k$, which is exactly what you mentioned in the question: it is defined by the recurrence $m_{k+1}=\frac{km_k+x_{k+1}}{k+1}$ for $k \geq 0$ with the initial condition $m_0=0$. Then you sum up $(x_k-m_k)^2$ and divide by $n-1$ whenever you stop. This estimator is more badly behaved than the sample variance. In particular it is biased and the bias is somewhat serious (if I remember correctly, the expectation deviates from the true variance by something like $\log(n)/n$). But it is still consistent. See https://www.johndcook.com/blog/standard_deviation/ (the first thing I found on a quick Google search) for details.