Print Page  
FORMULA FUNCTIONS / INDIVIDUAL SECURITY
LoopSum("formula(CTR)",iterations[,start,increment,noNAs,break])
Full Description
Evaluates a formula multiple times using an offset dynamically updated using a CTR variable. These functions are typically used with line item functions (like Sales and EPS) and technical functions.

For historical statistics that require evaluating ratios like PriceToSales in the past see the FHist functions.

The following versions exist:

LoopAvg("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopSum("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopProd("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopMedian("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopMax("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopMin("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopStdDev("formula(CTR)", iterations[, start, increment, noNAs, break])
LoopRelStdDev("formula(CTR)", iterations[, start, increment, noNAs, break])

Parameters:
formula: the formula to be executed in the loop.
iterations: the number of times to execute the formula (up to 502)
start: the starting value of CTR (default 0)
increment: how much CTR is incremented for each iteration (default 1)
noNAs: when set to 1 any NAs will return NA, when set to 0 (the default) NAs are skipped
break: when set to 1 the loop will break when it encounters an NA and will return the result to that point, when set to 0 (the default) the function will return NA if it encounters any NA in the loop

Relative Standard Deviation
Relative SD is calculated as follows: RSD = 100 * (SD/Abs(mean))

Example 1
Recreating the simple moving average of closing prices. You can recreate SMA(5) in these ways:

LoopSum("Close(CTR)", 5) / 5
 or
LoopAvg("Close(CTR)", 5)
 or
(Close(0) + Close(1) + Close(2) + Close(3) + Close(4)) / 5

Example 2
Count the number of times the close price is greater than the previous day for the past 10 bars:

LoopSum("Close(CTR) > Close(CTR + 1)", 10)

The ">" test is executed 10 times and returns either 1 (TRUE) or 0 (FALSE). The values are added together. The sum returns from 0-10, with 10 being stocks that have had higher closing prices for the past 10 bars vs the previous day.

Example 3
Find companies that have increased quarterly income after tax at least 8 of the last 10 quarters

LoopSum("IncAftTax(CTR, QTR) > IncAftTax(CTR + 1, QTR)", 10) >= 8