Macaulay Duration

Can anyone help me with a math library that calculates Macaulay Duration for US Government bonds?

I have the base formula online and have some legacy C code but it is not accurate.

I would have assumed that there would be a open source Math library out there I could use but I can't locate any.

Any help is much appreciated.

James TalvyAsked:
Who is Participating?
James TalvyConnect With a Mentor Author Commented:
Still working on this... I think may work but trying to compile on Solaris x86...
Kent OlsenData Warehouse Architect / DBACommented:
Hi James,

There are a lot of financial calculations, along with C implementations, documented here:

Hope it's what you need!

James TalvyAuthor Commented:
I will take a look.  Thanks.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

James TalvyAuthor Commented:
This is not ideal since you have to pass in to his functions all of the broken out coupons etc.

Typically I have maturity, settlement date, dated date, first coupon date and yield and the function would work out all of the details.
Kent OlsenData Warehouse Architect / DBACommented:

OptionMatrix claims to perform Macaulay calculations:


SourceCodeBrowser has a model in C++:


Its class is described here:

James TalvyAuthor Commented:
I got it compiled on Solaris x86 but have not yet successfully calculated yields that match established benchmarks.
James TalvyAuthor Commented:
own answer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.