Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 29, 2013 01:48
Show Gist options
  • Save ghalimi/4660977 to your computer and use it in GitHub Desktop.
Save ghalimi/4660977 to your computer and use it in GitHub Desktop.
TBILLYIELD Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function TBILLYIELD(settlement, maturity, price) {
// Return error if either date is invalid
if (!moment(settlement).isValid() || !moment(maturity).isValid()) return '#VALUE!';
// Return error if price is lower than or equal to zero
if (price <= 0) return '#NUM!';
// Return error if settlement is greater than maturity
if (moment(settlement).diff(moment(maturity)) > 0) return '#NUM!';
// Return error if maturity is more than one year after settlement
if (moment(maturity).diff(moment(settlement), 'years') > 1) return '#NUM!';
// Return bond-equivalent yield
return (100 - price) * 360 / (price * DAYS360(settlement, maturity));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment