Created
January 29, 2013 01:48
-
-
Save ghalimi/4660977 to your computer and use it in GitHub Desktop.
TBILLYIELD 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 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