Averages/Simple moving average: Difference between revisions
Content added Content deleted
m (added whitespace and highlighting to the task's preamble.) |
|||
Line 6:
A simple moving average is a method for computing an average of a stream of numbers by only averaging the last P numbers from the stream, where P 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 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().
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 ''stateful'' in the task description refers to the need for SMA() to remember certain information between calls to it:
* An ordered container of at least the last P numbers from each of its individual calls.▼
▲* The period, P
▲* An ordered container of at least the last P numbers from each of its individual calls.
<br>
''Stateful'' also means that successive calls to I(), the initializer, should return separate routines that do ''not'' share saved state so they could be used on two independent streams of data.
<pre>
function SMA(number: N):
Line 36 ⟶ 37:
;
* [[Standard Deviation]]
<br><br>
|