Skip to content

Commit 4fa8b5f

Browse files
committed
Change precision on findroot to 1e-6. Fix #27.
1 parent 6539af3 commit 4fa8b5f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/ExcelFinancialFunctions/common.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module internal Common =
112112
// If the result is sensible (it exist and has the same sign as guess), then return it, else try bisection.
113113
// I'm sure more complex way to pick algos exist (i.e. Brent's method). But I favor simplicity here ...
114114
let findRoot f guess =
115-
let precision = 0.0000001 // Excel precision on this, from docs
115+
let precision = 0.000001 // Excel precision on this, from docs
116116
let newtValue = newton f guess 0 precision
117117
if newtValue.IsSome && sign guess = sign newtValue.Value
118118
then newtValue.Value

tests/ExcelFinancialFunctions.Tests/spottests.fs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ module SpotTests =
1515
Financial.Yield param
1616
|> shouldEqual (sprintf "YieldIssue8(%A)" param) -0.67428578540657702
1717

18+
[<Test>]
19+
let XirrIssue27() =
20+
let values = [ -177900000.; 8799805.85 ]
21+
let dates = [ DateTime(2020,7,3); DateTime(2021,2,25) ]
22+
Financial.XIrr (values, dates)
23+
|> shouldEqual (sprintf "XirrIssue27(%A,%A)" values dates) -0.990247691899517
24+
1825
[<Test>]
1926
let spotYield() =
2027
let param =

0 commit comments

Comments
 (0)