
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 latter 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:

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 formula, as shown in the optimized code:


Function LinearRegFaster 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
Users of earlier versions of TradeStation may compile the code from the text files included in the above *.zip file.
The code may be visualized here:
