Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Average

Status
Not open for further replies.

jr8rdt

IS-IT--Management
Feb 9, 2006
59
US
I have hundreds of thousands of data points stored in @data and need to do 100 data point moving average. Can anybody share the logic? I know I have to do pop or shift but just can't figure out how to do the moving average.

thanks in advance
 
I think you are going to need to explain what you are trying to do in detail. Or maybe some knows what "100 data point moving average" means. Sample in and sample out data will be helpful.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
There are a few different ways to define a moving average. Not in terms of perl (since that's your question) what algorithm would you use to calculate the moving average?

For example, a simple moving average for 100 data points would be something like:

Code:
SMA = (p + p-1 + ... + p-99) / 100
Is that what you're looking for?
 
This looks a little academic, so just in case I'll explain versus writing code here:
- Loop over your data pushing the data points into an array
- Track a 'running_total' of the values along the way
- If size of array < 99, goto start
- calc & print average
- shift array and subtract that amount from your running_total
- end of loop;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top