Simple algorithm for online outlier detection of a generic time series
I've got data on quantities sold and average price, by date, for a number of commodities and a number of outlets. Because of the provenance of the data, some of the observations are wrong. I'd like to be able to flag the potential anomalies so that they can be checked.
I've done some context-independent analysis (looking for values outside specified bounds), but I'd like to try some context-dependent analysis - for example, price for a particular commodity out of line by looking across outlets for a single date, or quantity out of line by looking across dates for a single outlet.
For the latter, I'm thinking that some sort of moving window would be the thing to use - I'm pretty sure that for some commodities there are both long term trends and seasonal variation going on, so what I'm looking for is spikes.
My current thoughts are something along the lines of: for each observation, flag it if it's more than some distance from the mean or median of the comparator observations, where the comparator observations would be either those for the same commodity and outlet in a time window, or those for the same date and commodity for all (other) outlets.
Is this anything like any standard technique? If so, what's its name, and what drawbacks does it have? (Once I've got a name I'll be able to search for more descriptions, and hopefully an R implementation).
Thanks for any pointers.