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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
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.
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.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Kent OlsenDBACommented:

OptionMatrix claims to perform Macaulay calculations:


SourceCodeBrowser has a model in C++:


Its class is described here:

James TalvyAuthor Commented:
Still working on this... I think may work but trying to compile on Solaris x86...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Math / Science

From novice to tech pro — start learning today.