Tradestation provides built-in linear regression functions LinearReg and LinearRegFC, which both use identical calculation algorithms except for the inclusion of the ExecOffset feature in the later function.

The FC suffix after a function name normally implies a fast calculation algorithm is being used. However, in the case of LinearReg and LinearRegFC, both are using the same algorithm, which has not been optimized for execution speed.

LinearRegFC contains the following code:

Fig 1. Original LinearRegFC Code
The area highlighted in yellow contains a loop and a summation that is performed with every new bar processed.

It is possible to optimize this section, replacing the loop and summation code with a simple addition/subtraction forumula, as shown in the optimized code:

Fig. 3. Formatting Liquidity Scan Symbol Universe
Table 1. Relative execution speeds of LinearRegFaster compared to LinearRegFC
Function LinearRegFast produces output identical to TS function LinearRegFC under all conditions.

Downloads

Initially posted version:  11/03/12

Latest Update:  11/03/12

*.ELD files are compiled for TS 9.0

All ELD and code text files packaged here:

LinearRegFaster.zip

Users of earlier versions fo TradeStation may compile the code
from the text files included in the above *.zip file.

The code may be visualized here:

Function LinearRegFaster

Method LinearRegFaster

Original TS Function LinearRefFC