Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

calculate a simple rolling / moving average using VB 2010

$
0
0
my code produces a variable with a column of numbers like this:

5248
5249
5258
5251
5247
5246
5251
5228
5235
5251
5241
5240
5247
5259
5261

what i want to do is use VB to give me the average for every x number of lines, and then store that in another var, and then have VB print the MAX and MIN of those averages.

for example, if i want to calculate the average for every 10 lines:

5248
5249
5258
5251
5247
5246
5251
5228
5235
5251 5246.4
5241 5245.7
5240 5244.8
5247 5243.7
5259 5244.5
5261 5245.9

so you can see that beginning with the 10th record the average is calculated for records 1-10, then 2-11, then 3-12, then 4-13, then 5-14, then 6-15

The MAX avg is 5246.4 and the MIN is 5243.7

if i wanted to get the average for every 5 records instead (for example), then the first average would calculate the avg of 1-5, then 2-6, then 3-7 and so on

what is the best way to code this to get the moving average and also find the MAX and MIN of that average

TIA

Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>