Skip to content

Instantly share code, notes, and snippets.

@foxnewsnetwork
Last active November 30, 2017 04:34
Show Gist options
  • Save foxnewsnetwork/23a7353efb3291bd980546d3e5d84478 to your computer and use it in GitHub Desktop.
Save foxnewsnetwork/23a7353efb3291bd980546d3e5d84478 to your computer and use it in GitHub Desktop.
ch04-bond-present-value-supplemental
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
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
function spotRate(pvPercent, nYear)
1 / pvPercent ^ ( 1 / nYear) - 1
end
function forwardRate(currRateSp, prevRateSp, n)
((1 + currRateSp) ^ n) / ((1 + prevRateSp) ^ (n-1) ) - 1
end
@foxnewsnetwork
Copy link
Author

As a sanity check, consider the following:

image

Notice that when:

  • the couponRate is equal to the marketYield, then the bond sells at face value
  • the couponRate is much lower than the market yield, the bond is worthless
  • the coupon rate is much lower than the market yield, the bond's value scales up indefinitely with the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment