1
+ namespace Excel.FinancialFunctions
2
+
3
+ open NUnit.Framework
4
+ open TestInfrastructure
5
+ open Excel.FinancialFunctions .ExcelTesting
6
+ open Excel.FinancialFunctions .Tvm
7
+ open Excel.FinancialFunctions .Loan
8
+ open Excel.FinancialFunctions .Irr
9
+ open Excel.FinancialFunctions .Depreciation
10
+ open Excel.FinancialFunctions .DayCount
11
+ open Excel.FinancialFunctions .TestsDef
12
+ open Excel.FinancialFunctions .Bonds
13
+ open Excel.FinancialFunctions .TBill
14
+ open Excel.FinancialFunctions .Misc
15
+ open Excel.FinancialFunctions .OddBonds
16
+ open Excel.FinancialFunctions .TestPreconditions
17
+
18
+ [<Parallelizable( ParallelScope.Children) >]
19
+ type MatrixTests () =
20
+ let tests = [|
21
+ // --------------------------------------------------------------------------------------------------
22
+ //"RATE", Excel uses a different root finding algo. Sometimes mine is better, sometimes Excel's is. Using the TestRate function instead.
23
+ //"ODDFYIELD", Excel uses a different root finding algo. Sometimes mine is better, sometimes Excel's is. Using the TestOddFYield function instead.
24
+ //"XNPV", the excel object model has an xnpv function with a different number of args. Tested through XIRR and separate testcase.
25
+ //"YIELD", the excel object model lacks this function. Tested through the price function and separate testcase.
26
+ // --------------------------------------------------------------------------------------------------
27
+ " PV" , ( fun _ -> test5 calcPv pvEx rates npers pmts fvs dues tryPv);
28
+ " FV" , ( fun _ -> test5 calcFv fvEx rates npers pmts pvs dues tryFv);
29
+ " PMT" , ( fun _ -> test5 calcPmt pmtEx rates npers pvs fvs dues tryPmt);
30
+ " NPER" , ( fun _ -> test5 calcNper nperEx rates pmts pvs fvs dues tryNper);
31
+ " IPMT" , ( fun _ -> test6 calcIpmt ipmtEx rates pers npers pvs fvs dues tryIpmt);
32
+ " PPMT" , ( fun _ -> test6 calcPpmt ppmtEx rates pers npers pvs fvs dues tryPpmt);
33
+ " CUMIPMT" , ( fun _ -> test6 calcCumipmt cumipmtEx rates npers pvs pers endPers dues tryCumipmt);
34
+ " CUMPRINC" , ( fun _ -> test6 calcCumprinc cumprincEx rates npers pvs pers endPers dues tryCumprinc);
35
+ " ISPMT" , ( fun _ -> test4 calcIspmt ispmtEx rates pers npers pvs tryIspmt);
36
+ " FVSCHEDULE" , ( fun _ -> test2 calcFvSchedule fvScheduleEx pvs testInterests precondOk2);
37
+ " IRR" , ( fun _ -> test2 calcIrr irrEx testCfs guesses precondOk2);
38
+ " NPV" , ( fun _ -> test2 calcNpv npvEx rates testCfs tryNpv);
39
+ " MIRR" , ( fun _ -> test3 calcMirr mirrEx testCfs rates rates tryMirr);
40
+ //"XIRR", fun _-> test3 calcXirr xirrEx testCfs testDates guesses tryXirr;
41
+ " DB" , fun _ -> test5 calcDb dbEx testCosts testSalvages testLives testPeriods testMonths tryDb;
42
+ " SLN" , fun _ -> test3 calcSln slnEx testCosts testSalvages testLives trySln;
43
+ " SYD" , fun _ -> test4 calcSyd sydEx testCosts testSalvages testLives testPeriods trySyd;
44
+ " DDB" , fun _ -> test5 calcDdb ddbEx testCosts testSalvages testLives testDdbPeriods testFactors tryDdb;
45
+ " VDB excluding fractional startdates" , fun _ -> test7 vdbWrap vdbEx testCosts testSalvages testLives testPeriods testEndPeriods testFactors testVdbSwitch tryVdb;
46
+ " AMORLINC" , fun _ -> test7 calcAmorLinc amorLincEx testCosts testIssueDates testFirstInterestDates testSalvages testPeriods testBondRates testDayCountBasis tryAmorLinc;
47
+ " AMORDEGRC" , fun _ -> test7 amorDegrcWrapper amorDegrcEx testCosts testIssueDates testFirstInterestDates testSalvages testPeriods testDeprRates testDayCountBasis tryAmorDegrc;
48
+ " COUPDAYS excluding leap years" , fun _ -> test4 calcCoupDays coupDaysEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupDays;
49
+ " COUPDAYSBS" , fun _ -> test4 calcCoupDaysBS coupDaysBSEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupDaysBS;
50
+ " COUPDAYSNC" , fun _ -> test4 calcCoupDaysNC coupDaysNCEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupDaysNC;
51
+ " COUPNUM" , fun _ -> test4 calcCoupNum coupNumEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupNum;
52
+ " COUPPCD" , fun _ -> test4 coupPCDWrapper coupPCDEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupPCD;
53
+ " COUPNCD" , fun _ -> test4 coupNCDWrapper coupNCDEx testSettlDates testMatDates testFrequency testDayCountBasis tryCoupNCD;
54
+ " ACCRINTM" , fun _ -> test5 calcAccrIntM accrIntMEx testIssue testSettl testBondRates testPars testDayCountBasis tryAccrIntM;
55
+ " ACCRINT" , fun _ -> test7 calcAccrIntWrap accrIntEx testIssue testFirstInt testSettl testBondRates testPars testFrequency testDayCountBasis tryAccrInt;
56
+ " PRICE" , fun _ -> test7 calcPrice priceEx testSettlDates testMatDates testBondRates testYlds testRedemptions testFrequency testDayCountBasis tryPrice
57
+ " PRICEMAT" , fun _ -> test6 calcPriceMat priceMatEx testSettlDates testMatDates testIssue testBondRates testYlds testDayCountBasis tryPriceMat
58
+ " YIELDMAT" , fun _ -> test6 calcYieldMat yieldMatEx testSettlDates testMatDates testIssue testBondRates testPrices testDayCountBasis tryYieldMat
59
+ " YEARFRAC" , fun _ -> test3 calcYearFrac yearFracEx testSDates testEDates testDayCountBasis tryYearFrac;
60
+ " INTRATE" , fun _ -> test5 calcIntRate intRateEx testSettlDates testMatDates testInvestments testRedemptions testDayCountBasis tryIntRate;
61
+ " RECEIVED" , fun _ -> test5 calcReceived receivedEx testSettlDates testMatDates testInvestments testDiscounts testDayCountBasis tryReceived;
62
+ " DISC" , fun _ -> test5 calcDisc discEx testSettlDates testMatDates testInvestments testRedemptions testDayCountBasis tryDisc;
63
+ " PRICEDISC" , fun _ -> test5 calcPriceDisc priceDiscEx testSettlDates testMatDates testDiscounts testRedemptions testDayCountBasis tryPriceDisc;
64
+ " YIELDDISC" , fun _ -> test5 calcYieldDisc yieldDiscEx testSettlDates testMatDates testInvestments testRedemptions testDayCountBasis tryYieldDisc;
65
+ " TBILLEQ" , fun _ -> test3 calcTBillEq TBillEqEx testSettlDates testTBillMat testDiscounts tryTBillEq;
66
+ " TBILLYIELD" , fun _ -> test3 calcTBillYield TBillYieldEx testSettlDates testTBillMat testPrices tryTBillYield;
67
+ " TBILLPrice" , fun _ -> test3 calcTBillPrice TBillPriceEx testSettlDates testTBillMat testDiscounts tryTBillPrice;
68
+ " DOLLARDE" , fun _ -> test2 calcDollarDe dollarDeEx testFractionalDollars testFractions tryDollarDe;
69
+ " DOLLARFR" , fun _ -> test2 calcDollarFr dollarFrEx testFractionalDollars testFractions tryDollarFr;
70
+ " EFFECT" , fun _ -> test2 calcEffect effectEx rates testPeriods tryEffect;
71
+ " NOMINAL" , fun _ -> test2 calcNominal nominalEx rates testPeriods tryNominal;
72
+ " DURATION" , fun _ -> test6 calcDuration durationEx testSettlDates testMatDates testInvestments testYlds testFrequency testDayCountBasis tryDuration;
73
+ " MDURATION" , fun _ -> test6 calcMDuration mdurationEx testSettlDates testMatDates testInvestments testYlds testFrequency testDayCountBasis tryMDuration;
74
+ " ODDFPRICE" , fun _ -> test9 calcOddFPrice oddFPriceEx testSettlDates2 testMatDates testIssueDates testFirstInterestDates testBondRates testYlds testRedemptions testFrequency testDayCountBasis tryOddFPrice;
75
+ " ODDLPRICE" , fun _ -> test8 calcOddLPrice oddLPriceEx testSettlDates2 testMatDates testIssueDates testBondRates testYlds testRedemptions testFrequency testDayCountBasis tryOddLPrice;
76
+ " ODDLYIELD" , fun _ -> test8 calcOddLYield oddLYieldEx testSettlDates2 testMatDates testIssueDates testBondRates testRedemptions testRedemptions testFrequency testDayCountBasis tryOddLYield;
77
+ |]
78
+
79
+ [<TestCase( " PV" ) >]
80
+ [<TestCase( " FV" ) >]
81
+ [<TestCase( " PMT" ) >]
82
+ [<TestCase( " NPER" ) >]
83
+ [<TestCase( " IPMT" ) >]
84
+ [<TestCase( " PPMT" ) >]
85
+ [<TestCase( " CUMIPMT" , Category= " Fast" ) >]
86
+ [<TestCase( " CUMPRINC" , Category= " Fast" ) >]
87
+ [<TestCase( " ISPMT" ) >]
88
+ [<TestCase( " DB" ) >]
89
+ [<TestCase( " SLN" , Category= " Fast" ) >]
90
+ [<TestCase( " SYD" , Category= " Fast" ) >]
91
+ [<TestCase( " DDB" ) >]
92
+ [<TestCase( " VDB excluding fractional startdates" ) >]
93
+ [<TestCase( " FVSCHEDULE" , Category= " Fast" ) >]
94
+ [<TestCase( " MIRR" , Category= " Fast" ) >]
95
+ [<TestCase( " NPV" ) >]
96
+ [<TestCase( " ISPMT" ) >]
97
+ [<TestCase( " IRR" , Category= " Fast" ) >]
98
+ [<TestCase( " AMORLINC" ) >]
99
+ [<TestCase( " AMORDEGRC" ) >]
100
+ [<TestCase( " COUPDAYS excluding leap years" ) >]
101
+ [<TestCase( " COUPDAYSBS" ) >]
102
+ [<TestCase( " COUPDAYSNC" ) >]
103
+ [<TestCase( " COUPNUM" ) >]
104
+ [<TestCase( " COUPPCD" ) >]
105
+ [<TestCase( " COUPNCD" ) >]
106
+ [<TestCase( " ACCRINTM" ) >]
107
+ [<TestCase( " ACCRINT" ) >]
108
+ [<TestCase( " PRICE" ) >]
109
+ [<TestCase( " PRICEMAT" ) >]
110
+ [<TestCase( " YIELDMAT" ) >]
111
+ [<TestCase( " YEARFRAC" ) >]
112
+ [<TestCase( " INTRATE" ) >]
113
+ [<TestCase( " RECEIVED" ) >]
114
+ [<TestCase( " DISC" ) >]
115
+ [<TestCase( " PRICEDISC" ) >]
116
+ [<TestCase( " YIELDDISC" ) >]
117
+ [<TestCase( " TBILLEQ" ) >]
118
+ [<TestCase( " TBILLYIELD" , Category= " Fast" ) >]
119
+ [<TestCase( " TBILLPrice" , Category= " Fast" ) >]
120
+ [<TestCase( " DOLLARDE" , Category= " Fast" ) >]
121
+ [<TestCase( " DOLLARFR" , Category= " Fast" ) >]
122
+ [<TestCase( " EFFECT" , Category= " Fast" ) >]
123
+ [<TestCase( " NOMINAL" , Category= " Fast" ) >]
124
+ [<TestCase( " DURATION" ) >]
125
+ [<TestCase( " MDURATION" ) >]
126
+ [<TestCase( " ODDFPRICE" ) >]
127
+ [<TestCase( " ODDLPRICE" ) >]
128
+ [<TestCase( " ODDLYIELD" ) >]
129
+ member __.RunMatrix test =
130
+ let found = Array.tryFind ( fun x -> fst x = test) tests
131
+ let ( _ , func ) = found.Value
132
+ let ( tries , success , _ , _ ) = func ()
133
+ Assert.AreEqual( success, tries)
0 commit comments