I recently worked on a project where I had to perform financial calculations. The main project requirements where provided on an Excel and because of the sensitivity of the calculations(mortgage payments), I had to keep within 1cent accuracy.
After reviewing the needed calculations, my main issue was the NPV (Net Present Value); although I am familiar with the formula and applications of NPV, I was not sure of the exact implementation in Excel.
So, I jumped to Google to see if there was any implementations and found the Excel Financial Functions for .Net: “… a .NET library that provides the full set of financial functions from Excel.”.
Great! BUT. The library is actually implemented in F# and only the source code is provided, no compiled version…. No problem, since all .Net languages compile into IL (Intermediate Language), all I needed to do was to compile the F# project and then reference it on my C# one.
After I add ed the Financial.dll reference to my project (compiled version included in the provided source code), I am ready to use it on my code, however, note that the following reference is required:
using
System.Numeric;
With the reference in place, I can now use the NPV function as follow:
Comparing the signature of the NPV function on Financial.dll to excel, we can see they are virtually the same:
And even though I have shown mainly the NPV usage, this library contains implementation pretty much all financial functions in Excel (Complete List).
There you have it; if you ever have a project where you need to use Excel functions, you can refer t the Excel Financial Functions for .Net library; you can use the compiled library provided on this example, but I recommend reviewing the library page regularly to check for updates.
Hope this helps!
There is actually a pre-compiled Financial package, but it is in the VisualBasic namespace in the Microsoft.VisualBasic.dll in the GAC which freaks some C# folks out.
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.financial.aspx