Averages/Simple moving average: Difference between revisions

Content added Content deleted
m (added whitespace and highlighting to the task's preamble.)
Line 6:
 
 
''';Description'''<br>:
A simple moving average is a method for computing an average of a stream of numbers by only averaging the last &nbsp; P &nbsp; numbers from the stream, &nbsp; where &nbsp; P &nbsp; is known as the period.
It can be implemented by calling an initialing routine with P as its argument, I(P), which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last P of them, lets call this SMA().
 
It can be implemented by calling an initialing routine with &nbsp; P &nbsp; as its argument, &nbsp; I(P), &nbsp; which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last &nbsp; P &nbsp; of them, lets call this &nbsp; SMA().
The word stateful in the task description refers to the need for SMA() to remember certain information between calls to it:
 
* The period, P
The word &nbsp; ''stateful'' &nbsp; in the task description refers to the need for &nbsp; SMA() &nbsp; to remember certain information between calls to it:
* An ordered container of at least the last P numbers from each of its individual calls.
* &nbsp; The period, &nbsp; P
* &nbsp; An ordered container of at least the last &nbsp; P &nbsp; numbers from each of its individual calls.
 
<br>
''Stateful'' &nbsp; also means that successive calls to &nbsp; I(), &nbsp; the initializer, &nbsp; should return separate routines that do &nbsp; ''not'' &nbsp; share saved state so they could be used on two independent streams of data.
 
PseudocodePseudo-code for an implementation of &nbsp; SMA &nbsp; is:
<pre>
function SMA(number: N):
Line 36 ⟶ 37:
 
 
;SeeRelated alsotask:
* &nbsp; [[Standard Deviation]]
<br><br>