-
Notifications
You must be signed in to change notification settings - Fork 0
fix: inverting year fraction should give opposite sign #60
Conversation
daycount.go
Outdated
| alpha = -1.0 | ||
|
|
||
| remaining = from | ||
| from, to = to, remaining |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny detail. I think it makes the swap a bit more obvious if it is written as
| from, to = to, remaining | |
| from, to = to, from |
daycount.go
Outdated
|
|
||
| // This function uses backward induction from the later date, | ||
| // 'from' and 'to' are swapped if 'to' falls before 'from'. | ||
| alpha := 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would sign, directionality, dateOrdering, dateOrderingMultiplier, isAfter, fromAfterTo, isFromAfterTo be any better than alpha? (alpha might be just fine, I'm just sending in ideas).
Sadly, in Go, we cannot multiply by a bool (and we cannot simply cast a bool into an int), as alpha, really, should be a bool. Of course, we could do
sign := true
asInt := func(b bool) int {
if b {
return 1
}
return -1
}
return asInt(sign) * (float64(nbFullYears) + float64(remaining.Sub(from))/computeYearDurationAFB(from, remaining))
but that might be considered as over-engineering for such a small thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked myself the same question :)
It's generally called signum (at least in Java SDK)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like signum!
It is pronounced sig num (with the gueh sound), not sign um (with the nieh sound), right? 😅
ab230bf
Context
While comparing
daycountandelgorian, I noticed an inconsistency ondaycountside concerningActualActualAFBwhich produced a wrong value whentowas beforefromand a 29th February was comprise within the interval[to, from].Content
Since the year fraction computation is done on a backward induction, the function now inverts
fromandtoiftois beforefrom.A property test is added to make sure that inverting
fromandtoreturns the opposite value (* -1.0).