Volume-Weighted Mean and Standard Deviation from Series or Arrays
Summary
This document presents reusable calculations for weighted mean, variance, standard deviation, mean squared error, and root mean squared error. It provides two implementations: one for time series and another for arrays. Both multiply observations by their corresponding weights, calculate a weighted mean, then aggregate weighted squared deviations. The standard deviation uses a correction based on the count of nonzero weights, while MSE and RMSE use the weighted squared-error sum directly.
The examples apply the series method to closing prices weighted by volume and the array method to closing prices with linearly increasing weights favoring recent observations. Both plot the weighted mean with bands two standard deviations above and below it. The script illustrates calculation and visualization, but supplies no trading rules, performance results, or evidence that either band predicts price behavior. Users should also ensure weights and samples are valid, since zero total weight or too few nonzero weights can make the calculations undefined.
Key ideas
- Weighted mean and dispersion can be calculated from either time-series inputs or arrays.
- The variance calculation adjusts the weighted squared-error sum using the count of nonzero weights.
- The examples compare volume weights with linearly increasing weights on recent observations.
- The plotted bands show the weighted mean plus or minus twice the calculated standard deviation.
- The script demonstrates statistical calculations but provides no evidence of trading performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.