Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 29, 2013 00:22
Show Gist options
  • Save ghalimi/4660557 to your computer and use it in GitHub Desktop.
Save ghalimi/4660557 to your computer and use it in GitHub Desktop.
TBILLEQ Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function TBILLEQ(settlement, maturity, discount) {
// Return error if either date is invalid
if (!moment(settlement).isValid() || !moment(maturity).isValid()) return '#VALUE!';
// Return error if discount is lower than or equal to zero
if (discount <= 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 (365 * discount) / (360 - discount * DAYS360(settlement, maturity));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment