Financial Functions for .NET released !


Tags: C# F# Financial

Today I released the following library on CodeGallery. It is the result of three months of coding during my paternity leave in Italy. You can get it from here.

What is it?
This is a .NET library that provides the full set of financial functions from Excel. The main goal for the library is compatibility with Excel, by providing the same functions, with the same behaviour. Note though that this is not a wrapper over the Excel library; the functions have been re-implemented in managed code so that you do not need to have Excel installed to use this library. 
** Where I can find documentation on these functions?
Just open Excel and click on Formulas/Financial or go to this
I don’t think one of the function is right. Excel produces the wrong results! Why don’t you do it right?**
My goal is to replicate Excel results (right and wrong). Feel free to contribute to the effort by coding what you think is the right solution and I’ll add an ExcelCompliant flag to the function to conditionally invoke your code.
How do I use the library?**
Just add Financial.dll to the references in your project. The functions are provided as static methods on a Financial class in the System.Numeric namespace
I see the library was implemented with F#. But I don’t want to redistribute F# along with my application. What should I do?
There are two versions of the library. One of them statically links the F# libraries so that there is no dependency on F#. However, this assembly larger, so if you have F# installed, you can use the FinancialNotStandalone.dll instead.
How do I run the tests?**
Run FinancialTests.exe. You need Excel 12 for the tests to work because they use Excel to test that the results are correct. You don’t need Excel 12 to use the library in your own application.
How do I compile the library?**
You need to have F# September CTP installed (you can get it from here). There are two batch files (CreateLibraryStandalone.bat and CreateLibraryNotStandalon.bat). Run them to compile the dll. You might have to change the path to the F# compiler inside these files
How do I compile the tests?**
Run CreateTests.bat
Have you tested this thing?**
Yes, I do have 201,349 testcases running against it. You can easily raise that number significantly by adding new values to test in testdef.fs. If you have a multiproc machine the testcases will run faster as I parallelize their execution.
Have you run performance tests on it?**
Not at all. The only thing I checked is that all the recursive functions are tail recursive. Feel free to let me know if they are slow.
Are there any functions that behave different from Excel?**
Yes, there are two of them.
The Excel algorithm seems wrong in that it doesn’t respect the following:
coupDays = coupDaysBS + coupDaysNC.
This equality should stand. By manually counting the days, I’m pretty confident that my algorithm is correct.My result differs from Excel by +/- one or two days when the date spans a leap year.
In the excel version of this algorithm the depreciation in the period (0,1) is not the same as the sum of the depreciations in periods (0,0.5) (0.5,1).
VDB(100,10,13,0,0.5,1,0) + VDB(100,10,13,0.5,1,1,0) <> VDB(100,10,13,0,1,1,0)
Notice that in Excel by using ‘1’ (no_switch) instead of ‘0’ as the last parameter everything works as expected. The last parameter should have no influence in the calculation given that in the first period there is no switch to sln depreciation.
Overall, I think my algorithm is correct, even if it disagrees with Excel when startperiod is fractional.
Can you list the functions with their testcases results?**
Succeeded 18401840 for PV
Succeeded 20242024 for FV
Succeeded 22402240 for PMT
Succeeded 853853 for NPER
Succeeded 53555355 for IPMT
Succeeded 53555355 for PPMT
Succeeded 208208 for CUMIPMT
Succeeded 208208 for CUMPRINC
Succeeded 624624 for ISPMT
Succeeded 1212 for FVSCHEDULE
Succeeded 99 for IRR
Succeeded 2121 for NPV
Succeeded 147147 for MIRR
Succeeded 1818 for XIRR
Succeeded 396396 for DB
Succeeded 2424 for SLN
Succeeded 132132 for SYD
Succeeded 456456 for DDB
Succeeded 25442544 for VDB excluding fractional startdates
Succeeded 1152011520 for AMORLINC
Succeeded 2304023040 for AMORDEGRC
Succeeded 1515 for COUPDAYS excluding leap years
Succeeded 915915 for COUPDAYSBS
Succeeded 915915 for COUPDAYSNC
Succeeded 915915 for COUPNUM
Succeeded 915915 for COUPPCD
Succeeded 915915 for COUPNCD
Succeeded 360360 for ACCRINTM
Succeeded 19201920 for ACCRINT
Succeeded 1098010980 for PRICE
Succeeded 19401940 for PRICEMAT
Succeeded 29102910 for YIELDMAT
Succeeded 13951395 for YEARFRAC
Succeeded 27452745 for INTRATE
Succeeded 12901290 for RECEIVED
Succeeded 27452745 for DISC
Succeeded 36603660 for PRICEDISC
Succeeded 27452745 for YIELDDISC
Succeeded 4848 for TBILLEQ
Succeeded 6969 for TBILLYIELD
Succeeded 8181 for TBILLPrice
Succeeded 1212 for DOLLARDE
Succeeded 1212 for DOLLARFR
Succeeded 1212 for EFFECT
Succeeded 1212 for NOMINAL
Succeeded 54905490 for DURATION
Succeeded 54905490 for MDURATION
Succeeded 1932019320 for ODDFPRICE
Succeeded 3060030600 for ODDLPRICE
Succeeded 4590045900 for ODDLYIELD
Test Cases Succeeded 201349201349

comments powered by Disqus Updated: 2019-01-23 11:41:32 +0100 +0100, Version: 6668e21