# Inconsistent Timing on FinancialBond valuations

I need to do bond valuations (lots of them across lots of data) using FinancialBond.

Context & Background

I have daily interest rate data on 30 year US Treasury bonds from 1977 through the present. Each data element looks like this:

{{1977, 2, 15, 0, 0, 0.},0.077}


A DateList and interest rate.

Given a starting date (e.g., {1977, 2, 15, 0, 0, 0.}) I assume a 30 year maturity from the starting date.

At a future date, but prior to the assumed maturity date, I (1) find the interest rate associated with that future date and (2) calculate the "Settlement" value (essentially a proportion of the projected maturity date) like this...

maturityDate = DatePlus[{1977, 2, 15, 0, 0, 0.}, {30, "Years"}];
settlement = 30 - DateDifference[{1979, 2, 20, 0, 0, 0.}, maturityDate,"Years"]

2.0137


Then things begin to get odd...

Can anyone provide an explanation of the following?

The 3rd function takes over 36 seconds to run. The 4th crashes the kernel.

Code so anyone can replicate the problem.

Timing[FinancialBond[{"FaceValue" -> 1000, "Coupon" -> 0.077,
"Maturity" -> 30,"CouponInterval" -> 1/2}, {"InterestRate" -> 0.0902,
"Settlement" -> 2}]]

Timing[FinancialBond[{"FaceValue" -> 1000, "Coupon" -> 0.077,
"Maturity" -> 30,"CouponInterval" -> 1/2}, {"InterestRate" -> 0.0902,
"Settlement" -> 2.25}]]

Timing[FinancialBond[{"FaceValue" -> 1000, "Coupon" -> 0.077,
"Maturity" -> 30,"CouponInterval" -> 1/2}, {"InterestRate" -> 0.0902,
"Settlement" -> 2.0137}]]

Timing[FinancialBond[{"FaceValue" -> 1000, "Coupon" -> 0.077,
"Maturity" -> 30,"CouponInterval" -> 1/2}, {"InterestRate" -> 0.0902,
"Settlement" -> 2.01}]]


It appears that FinancialBond doesn't like certain fractions of a year (e.g., 2.0137 or 2.01).

Thoughts appreciated.

• In a current debugging kernel I am getting an out-of-memory exception as a result. Granted, that's better than a kernel crash. But still bad. I'll poke it a bit more and see what shows up. Feb 11, 2023 at 18:18
• Filing a bug report for this. Feb 11, 2023 at 21:07
• @DanielLichtblau - Many thanks for continuing to improve the platform. Feb 11, 2023 at 22:46

Looking at the examples in the documentation for FinancialBond, you can see that the parameters are almost always provided as exact numbers. This hints that for certain numeric parameters, some numerical errors probably accumulate and lead to memory overflow.

A simple solution is to use only exact numbers.

Timing[FinancialBond[{"FaceValue" -> 1000, "Coupon" -> 0.077,
"Maturity" -> 30,
"CouponInterval" -> 1/2}, {"InterestRate" -> 0.0902,
"Settlement" -> Rationalize[2.01]}]]

(* {0.0625, 866.027} *)


Otherwise, I don't know much about finances and what this function actually does. But you can try diving into the source code yourself with

GeneralUtilitiesPrintDefinitions[FinancialBond]
`

and debug the issue. Probably, there is some "while-like" loop that never finishes due to numerical errors.

• Good workaround. Thx. Feb 11, 2023 at 18:35