sma, mma and wma building blocks

Skip to first unread message

Paul Messier

Aug 8, 2013, 8:24:51 PM8/8/13

A slightly modified version of my formula is: Y = 1955 + 2.444^sma(V1,5) + if(wma(V2,160), sma(V3, 110) - 30 - sma(V4,20), 50 - if(mma(V5,50), -10, sma(V6,175)))

Despite some research, the sma, mma and wma building blocks still confuse me.From the documentation, it seems V1 through V6 in my formula are new measured values I want to test to determine Y. Starting with sma, this building block is defined as sma(v,c). 

Let’s say V1 relates to a variable named “Price” with the symbol “P.” One way to resolve sma(V1,5) seems to be:

A.      Take an average of V1 and the last 5 measured instances from the Price column (of the data I entered to create the Eureqa model). Like this: V1+P5+P4+P3+P2+P1/6.

OR another way…

B.     Since the first possible solution doesn't seem to rely on a “moving” average, perhaps I need to average P1&P2, take this result and average it with P3, take this result and average it with P4 etc.until I take the final “moving average” derived from P5 and average it with V1.

My formula also relies on mma and wma. I have the same issues here and would truly appreciate a walk through.

A side question is though I am pleased Eureqa tells me it is using sma (or mma and wma) I am puzzled as to why the program relies on me to calculate c in the expression sma(v,c). Wouldn't it be simple / advantageous to tell me what c is and remove a possibility for error?

I am quite new to the program and may well be out of my depth. A prod in the right direction would be greatly appreciated. Gratitude and any needed apologies in advance. 


Alison Reynolds

Aug 9, 2013, 3:31:02 PM8/9/13
Hi Paul,

The sma(v,c) (and mma and wma) take the moving average of the last c values (including the current value) of the variable v.

Here is a simple example as generated by Eureqa:

sma(A,2) A
nan 1
nan 2
2.5 3
3.5 4
4.5 5
5.5 6
6.5 7
7.5 8
8.5 9
9.5 10
10.5 11
11.5 12
12.5 13
13.5 14
14.5 15

You can see that with c=2, sma(A,2) is simply the average of the previous and current values of A.

As a slightly more complex example (trying to get more similar to your), you might imagine something like:

P = sma(V1,5) + 2*sma(V2,10)

Which would indicate that P (or price) can be predicted by taking the average value of V1 over the last 5 rows and adding that to 2 * (the average value of V2 over the last 10 rows).

With respect to specifying c, I'm not sure exactly what you mean... are you creating a custom target equation that specifically includes those building blocks?  If you specify an open ended target expression (e.g. "P = f(V1, V2, V3)") but then enable the sma, mma, and wma building blocks, Eureqa should be automatically choosing a value for c based on what fits the data best.

Hope that helps,

Paul Messier

Aug 13, 2013, 11:53:52 AM8/13/13

Dear Alison: This helps a great deal. Just to be sure I have it, let’s say I am trying to resolve P=sma(V,3).


The column below shows the last 4 rows of V plus the new value (the one I want to test) appearing in row 5.








Pin this case would = 7 as derived from (8+5+8)/3. Is this correct?  

From this example, how would P = wma(v,3) and P=mma(v,3) be resolved?


Many thanks for your patience.


Alison Reynolds

Aug 13, 2013, 5:22:20 PM8/13/13
Hi Paul,

Yes, that is correct.

Both wma (weighted moving average) and mma (modified moving average) gives weights to each value in the average such that newer values get more weight than older ones.  The weighting strategy differs for each.

With wma, if the window size is n, the latest values gets a weight of n, the previous value gets a weight of n-1, the previous value gets a weight of n-2 and so on down to a weight of 1 for the oldest value.

In your example, if P = wma(V,3), then P will be (8*3 + 5*2 + 8*1) / 6 = 7.  (It just happens to be the same value as sma in this case).

Mma is similar except that the weights decrease exponentially for older rows, though at the moment I don't have the exact formula used in Eureqa to determine the weights.

Wikipedia has pretty good definitions of these too if you are looking for more detail:


Paul Messier

Aug 15, 2013, 7:40:27 PM8/15/13
Dear Alison: Thanks for the further clarification regarding wma. Its a big help and I am nearly out of the woods. As for mma, the example from the wikipedia article is:
Using my column of numbers:


the solution to mma(V,3) could be:
Does that seem right? A possible glitch is "MMAyesterday" for which I simply used the previous value (5) without calculating a prior mma value. I guess it really just depends on how Eureqa uses mma. Any insight on this final detail would be appreciated. 
Reply all
Reply to author
0 new messages