Thoughts about what it takes to keep up with the demands of investing in credit from a technology/software perspective.

Tuesday, November 25, 2008

SQL 2008 Excel-like LINEST Function

Once again, I find myself replicating functionality in SQL that Excel provides out of the box. A necessary step if you find yourself analyzing large data sets with rigorous math. This time, it's the LINEST function, Excel's tried and true linear regression function. Admittedly, what I built does not provide the same level of information, but it does provide the big three: slope, y-intercept, and r-Squared. Once the base linear regression function is built, extending to handle exponential regression becomes straightforward, but I will save that for a different post.

Caveat

This will work out of the box for SQL 2008. You'll need to modify for lower versions of SQL Server.

I have no idea if you are still tracking this as I have been away from it for a while now, but to answer your question (if I think I understand it), no I have not implemented multi-linear (LINEST with multiple values) regression in SQL. That said, I do have a C# implementation since multi-linear regression involves linear algebra and I found SQL to be a bit "clunky" when I thought about it as an implementation language. I would be more than willing to share it with you if you'd like.