3

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?

enter image description here

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.

Jagra
  • 14,343
  • 1
  • 39
  • 81

1 Answers1

2

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

GeneralUtilities`PrintDefinitions[FinancialBond]

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

Domen
  • 23,608
  • 1
  • 27
  • 45