Last active
November 30, 2017 04:34
-
-
Save foxnewsnetwork/23a7353efb3291bd980546d3e5d84478 to your computer and use it in GitHub Desktop.
ch04-bond-present-value-supplemental
This file contains hidden or 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
function maturityYield(presVal, couponRate, time) | |
f(y) = 1 / y ^ time + sigma(1:time, t -> couponRate / y ^ t) - presVal | |
fzero(f, 0.5, 2.5) | |
end |
This file contains hidden or 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
function sigma(range, fn) | |
output = 0 | |
for i = range | |
output += fn(i) | |
end | |
output | |
end | |
function presentValue(marketYield, couponRate, time) | |
1 / (1 + marketYield) ^ time + sigma(1:time, t -> couponRate / ( 1 + marketYield ) ^ t) | |
end |
This file contains hidden or 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
function spotRate(pvPercent, nYear) | |
1 / pvPercent ^ ( 1 / nYear) - 1 | |
end | |
function forwardRate(currRateSp, prevRateSp, n) | |
((1 + currRateSp) ^ n) / ((1 + prevRateSp) ^ (n-1) ) - 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a sanity check, consider the following:
Notice that when: