library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(statespacer)
library(YieldCurve)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
library(xts)
vf = 1000
vp = 828
n = 5
r2a = ((vf/vp) ^ (1/n) ) - 1
r2a
## [1] 0.03846995
El rendimiento fue de 3.85%
vf = 1000
r2b = 0.0425
n = 5
P2b = vf / ((1+r2a) * (1+r2b)^4)
P2b
## [1] 815.2707
El precio del bono es de 815.27 dolares
vp = 828
retorno_neto = vp - P2b
retorno_neto
## [1] 12.72934
El retorno neto fue de 12,72
r3a <- function(t) { tasaforw <- numeric()
{
0.028 + 0.00042*t}
}
r_3a <- r3a(t=20)
r_3a
## [1] 0.0364
t=20
D20 <- exp(-r_3a*t)
y3a <- -log(D20)/t
y3a
## [1] 0.0364
El rendimiento al vencimiento de un bono a 20 años es 3.64 %
r3b <- function(t) {
tasaforw <- numeric()
{
0.028 + 0.00042*t}
}
r_3b <- r3b(t=15)
r_3b
## [1] 0.0343
t=15
D15 <- exp(-r_3b*t)
y3b <- -log(D15)/t
y3b
## [1] 0.0343
vf = 1000
r3b = 0.0364
Pb3b <- vf / (exp(y3b*t))
Pb3b
## [1] 597.7994
El precio de un bono cupon cero es 597.7994 .
r4a <- function(t) {
tasaforw <- numeric()
{
0.028 + 0.0002*t - 0.0003*(t^2)}
}
r_4a <- r4a(t=8)
t=8
D8 <- exp(-r_4a*t)
y4a <- -log(D8)/t
y4a
## [1] 0.0104
El rendimiento al vencimiento de un bono es 1.04 %
r4b <- function(t) {
tasaforw <- numeric()
{
0.028 + 0.0002*t - 0.0003*(t^2)}
}
r_4b <- r4b(t=5)
t=5
D5 <- exp(-r_4b*t)
y4b <- -log(D5)/t
vf = 1000
m = 5
Pb4b <- vf / (exp(y4b*t))
Pb4b
## [1] 898.0765
El precio de un bono cupon cero es $ 898.0765
t = 10
D10 <- exp(-r_4b*t)
y4d <- -log(D10)/t
Pb4d <- vf / (exp(y4d*t))
Pb4d
## [1] 806.5414
Pb4d.1 <- vf / (exp(y4d*(t-1)))
retorno4d <- (Pb4d.1 - Pb4d)/ Pb4d
retorno4d
## [1] 0.02173279
El retorno es de 2.17 %
bondvalue = function (c, T , r , par)
{
# Computes bv = bond values ( current prices ) corresponding
# to all values of yield to maturity in the
# input vector r
#
# INPUT
# c = coupon payment ( semiannual )
# T = time to maturity (in years )
# r = vector of yields to maturity ( semiannual rates )
# par = par value
#
bv = c / r + (par - c / r ) * (1 + r )^( -2 * T )
bv
}
Utilice la funci´on uniroot() para resolver las siguiente preguntas.
price = 1200
c = 40
T= 30
par = 1000
r = seq(0.02, 0.05, length = 300)
value5a = bondvalue(c, T, r, par)
yield5a = spline(value5a, r, xout = price)
yield5a
## $x
## [1] 1200
##
## $y
## [1] 0.03239813
El retorno a la madurez de un bono es de 3.24 %
plot(r, value5a, xlab = "Rendimiento al vencimiento", ylab = "precio del bono",
type = "l", main = "par = 1000, coupon payment = 40, T = 30", lwd = 2)
abline(h = 1200)
abline(v = yield5a)
price = 9800
c = 280
T = 16
par = 10000
r = seq(0.02, 0.05, length = 300)
value5b = bondvalue(c, T, r, par)
yield5b = spline(value5b, r, xout = price)
yield5b
## $x
## [1] 9800
##
## $y
## [1] 0.0289672
El retorno a la madurez de un bono es de 2.90 %
plot(r, value5b, xlab = "Rendimiento al vencimiento", ylab = "precio del bono",
type = "l", main = "par = 10000, cupón de pago = 40, T = 8", lwd = 2)
abline(h = 9800)
abline(v = yield5b)
c) Utlice la funci´on uniroot() para hallar el retorno a la madurez de un bono a 20 a˜nos con valor nominal $ 1 000 y cupon semi-anual de $ 35 que se vende a $ 1 050.
price = 1050
c = 35
T = 40
par = 1000
r = seq(0.02, 0.05, length = 300)
value5c = bondvalue(c, T, r, par)
yield5c = spline(value5c, r, xout = price)
yield5c
## $x
## [1] 1050
##
## $y
## [1] 0.03320829
El retorno a la madurez de un bono es de 3.32%
plot(r, value5c, xlab = "Rendimiento al vencimiento", ylab = "precio del bono",
type = "l", main = "par = 1000, cupón de pago = 35, T = 20", lwd = 2)
abline(h = 1050)
abline(v = yield5c)
d) El retorno a la madurez de un bono es 0,035 en un bono con valor nominal de 1 000, un precio de $ 950,10 y madurez a 5 a˜nos. ¿Cu´al es el valor del cupon?
price = 950.10
c = 0.035*par
T = 5
par = 1000
r = seq(0.02, 0.05, length = 300)
value5d = bondvalue(c, T, r, par)
yield5d = spline(value5d, r, xout = price)
yield5d
## $x
## [1] 950.1
##
## $y
## [1] 0.04118868
El retorno a la madurez de un bono es de 4.11%
plot(r, value5d, xlab = "Rendimiento al vencimiento", ylab = "precio del bono",
type = "l", main = "par = 1000, cupón de pago = 35, T = 5", lwd = 2)
abline(h = 950.10)
abline(v = yield5d)