Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to calculate X days moving average.
Old 11-14-2009, 08:26 PM How to calculate X days moving average.
Novice Talker

Posts: 11
Trades: 0
Anybody knows How to easily calculate X days moving average for a 365days data. any source available?
__________________

Please login or register to view this content. Registration is FREE
rcajht is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-14-2009, 09:27 PM Re: How to calculate X days moving average.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can you clarify?

What is an "X days moving average"?
What is "365 days data"?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-15-2009, 06:11 AM Re: How to calculate X days moving average.
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I don't really get it. Do you mean that you have data of something's movement over 365 days, and you want to calculate it's avarge movement over a given number of days?

In general, you calculate avarages by adding the values together and dividing by the number of terms. Avarge of [2, 17, 3, -4, 0, 6] is (2+17+3-4+0+6)/6 = 24/6 = 4
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-20-2009, 10:36 PM Re: How to calculate X days moving average.
Novice Talker

Posts: 11
Trades: 0
thank you guys, you are right, I need to clarify it a little bit.
1. I saved data into a array, data[] (say 365 days data).
2. I need print X days average line on the screen.
3. I want to create a FUNCTION to do that.
4. user can define X=5 days or 10 days whatever they want.

the math is there, I knew that, but I am new to PHP, I need some help to make that FUNCTION to calculate.

my thought is:
first, take last X days data, dividen them by X, then sum them. save it to a array. then do second .......

but not get it yet, any open source available?
Thanks.
__________________

Please login or register to view this content. Registration is FREE

Last edited by rcajht; 11-20-2009 at 10:37 PM..
rcajht is offline
Reply With Quote
View Public Profile
 
Old 11-20-2009, 11:08 PM Re: How to calculate X days moving average.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
So you want to compute the average of the values in data[] over a certain interval?
PHP Code:
function computeAverage($data$begin$end)
{
     
$total 0;
     for(
$i $begin$i $end$i++)
     {
           
$total += $data[$i];
     }
     return (float) 
$total / ($end $begin);

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to How to calculate X days moving average.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15290 seconds with 12 queries