Created
January 29, 2013 00:22
-
-
Save ghalimi/4660557 to your computer and use it in GitHub Desktop.
TBILLEQ Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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