3
$\begingroup$

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.

$\endgroup$
3
  • 3
    $\begingroup$ 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. $\endgroup$ Feb 11 at 18:18
  • 1
    $\begingroup$ Filing a bug report for this. $\endgroup$ Feb 11 at 21:07
  • $\begingroup$ @DanielLichtblau - Many thanks for continuing to improve the platform. $\endgroup$
    – Jagra
    Feb 11 at 22:46

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Good workaround. Thx. $\endgroup$
    – Jagra
    Feb 11 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.