Using the formula for beta that seems to be accepted for AFL I note a subtle difference when switching from sum() to ma(). I think that these plots should be identical as the substitution has a common factor. However, I must be missing something. Can you see what it is?

```
John
```

```
// init
market = ParamStr("Market", "$spx");
P = Foreign(Market, "C", 1);
periods = 125;
// Beta with SUM()
BetaS = (( Periods * Sum(ROC(C,1) * ROC(P,1), Periods )) -
(Sum(ROC(C,1), Periods) * Sum(ROC(P,1), Periods))) /
((Periods * Sum((ROC(P,1)^2 ), Periods)) -
(Sum(ROC(P,1 ), Periods)^2 ));
// Beta with MA()
BetaM = (( Periods * ma(ROC( C,1) * ROC(P,1), Periods )) -
(ma(ROC(C,1), Periods) * ma(ROC(P,1), Periods))) /
((Periods * ma((ROC(P,1)^2 ), Periods)) -
(ma(ROC(P,1 ), Periods)^2 ));
Plot(BetaS, "Sum", colorRed, styleLine);
Plot(BetaM, "MA", colorBlue, styleLine);
```