\[r(T;\theta_1,\theta_2,\theta_3,\theta_4) = \theta_1 + (\theta 2 + \theta_3 T)exp(- \theta_4 T)\]
Realice una regresion no-lineal para estimar los parametros \(\theta_1,\theta_2,\theta_3,\theta_4\).
\(\theta_1,\theta_2,\theta_3, \theta_4\)
Calcula la función logística.
options(scipen=999)
pkges<-c("statespacer","YieldCurve","tidyverse","xts")
lapply(pkges,"library",character.only=T)
## Warning: package 'statespacer' was built under R version 4.0.2
## Warning: package 'YieldCurve' was built under R version 4.0.2
## 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 packages ---------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 4.0.2
## -- Conflicts ------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::first() masks xts::first()
## x dplyr::lag() masks stats::lag()
## x dplyr::last() masks xts::last()
## [[1]]
## [1] "statespacer" "stats" "graphics" "grDevices" "utils"
## [6] "datasets" "methods" "base"
##
## [[2]]
## [1] "YieldCurve" "xts" "zoo" "statespacer" "stats"
## [6] "graphics" "grDevices" "utils" "datasets" "methods"
## [11] "base"
##
## [[3]]
## [1] "forcats" "stringr" "dplyr" "purrr" "readr"
## [6] "tidyr" "tibble" "ggplot2" "tidyverse" "YieldCurve"
## [11] "xts" "zoo" "statespacer" "stats" "graphics"
## [16] "grDevices" "utils" "datasets" "methods" "base"
##
## [[4]]
## [1] "forcats" "stringr" "dplyr" "purrr" "readr"
## [6] "tidyr" "tibble" "ggplot2" "tidyverse" "YieldCurve"
## [11] "xts" "zoo" "statespacer" "stats" "graphics"
## [16] "grDevices" "utils" "datasets" "methods" "base"
Descarga la archivo ZeroPrices.txt
ZeroPrices <- read.table("C:/Users/HP/Desktop/ZeroPrices.txt", header=TRUE, quote="\"")
dat <- ZeroPrices
price <- dat$price
mat_1 <-dat$maturity
REALIZANDO LOS DATOS LA CURVA DE RENDIMIENTO EMPIRICA
emp <- -diff(log(price))/diff(mat_1)
emp
## [1] 0.068366973 0.058925449 0.054993006 0.056349054 0.054791121
## [6] 0.050717961 0.058412867 0.072354061 0.035525392 0.052467335
## [11] 0.054139530 0.046383538 0.059953965 0.060077495 0.045589908
## [16] 0.072439959 0.020464603 0.051912506 0.055172803 0.047946773
## [21] 0.051428758 0.033918751 0.040031610 0.053134944 0.046044831
## [26] 0.037205070 0.044377979 0.052637916 0.009572937 0.052212822
## [31] 0.027240785 0.065549383 0.048617001 0.007742893 0.049567183
## [36] 0.049924827 0.024688979 0.069163973 -0.020711090
d <- as.Date(c("2020-08-16"))
treasury_yield_curve <- matrix(c(0.068366973, 0.058925449, 0.054993006, 0.056349054, 0.054791121, 0.050717961, 0.058412867,
0.072354061, 0.035525392, 0.052467335, 0.054139530, 0.046383538, 0.059953965, 0.060077495,
0.045589908, 0.072439959, 0.020464603, 0.051912506, 0.055172803, 0.047946773, 0.051428758,
0.033918751, 0.040031610, 0.053134944, 0.046044831, 0.037205070, 0.044377979, 0.052637916,
0.009572937, 0.052212822, 0.027240785, 0.065549383, 0.048617001, 0.007742893, 0.049567183,
0.049924827, 0.024688979, 0.069163973, -0.020711090), nrow = 1, ncol = 39)
treasury_yield_curve.xts <- xts(treasury_yield_curve, order.by=d)
Muestra los eficientes thetas estimados son :
NSParameters_treasury <- Nelson.Siegel(rate=treasury_yield_curve.xts, maturity=mat_1[2:length(mat_1)])
NSParameters_treasury
## Warning: timezone of object (UTC) is different than current timezone ().
## beta_0 beta_1 beta_2 lambda
## 2020-08-16 0.0008346745 0.0577263 0.06413145 0.1392349
Estimando valores para cada mes:
mat2 <- c(1:300)
y_treasury2 <- NSrates(NSParameters_treasury, mat2)
plot(mat_1[2:length(mat_1)], treasury_yield_curve, ylim = c(-0.1,
0.15), xlab = "madurez", ylab = "empirical forward rate",
type = "b", cex = 0.75, lwd = 2,
main = "Grafico de Curvas de Rendimiento")
lines(mat2,y_treasury2, col=4)
legend("bottomleft",legend=c("Curva de Rendimientos Empirica","Curva de Rendimientos Estimada"),
col=c(1,4),lty=1)
vf = 1000
vp = 828
n = 5
r_2a = ((vf/vp) ^ (1/n) ) - 1
r_2a
## [1] 0.03846995
El valor de r es 3.85 %
vf = 1000
r_2b = 0.0425
n = 5
P_2b = vf / ((1+r_2a) * (1+r_2b)^(n-1))
P_2b
## [1] 815.2707
El precio del bono es $ 815.27 dolares.
P_2b = 815.2707
vp = 828
ValorINv = P_2b - vp
ValorINv
## [1] -12.7293
El valor de la inversion es $ -12.7293 dolares.
P_2b = 815.2707
vp = 828
Retor_neto = (P_2b - vp) / vp
Retor_neto
## [1] -0.01537355
Se puede obtener una tasa de rendimiento anual del - 1,53 %.
\[r(t) = 0.028 + 0.00042t\]
r_3a <- function(t) {
tasaforw <- numeric()
{
0.028 + 0.00042*t}
}
r3a <- r_3a(t=20)
r3a
## [1] 0.0364
t=20
r3_1 = 0.0284
r3_2 = 0.0288
r3_3 = 0.0292
r3_4 = 0.0296
r3_5 = 0.0301
r3_6 = 0.0305
r3_7 = 0.0309
r3_8 = 0.0313
r3_9 = 0.0317
r3_10 = 0.0322
r3_11 = 0.0326
r3_12 = 0.0330
r3_13 = 0.0334
r3_14 = 0.0338
r3_15 = 0.0343
r3_16 = 0.0347
r3_17 = 0.0351
r3_18 = 0.0355
r3_19 = 0.0359
r3_20 = 0.0364
yn_3a <- (((1+r3_1)*(1+r3_2)*(1+r3_3)*(1+r3_4)*(1+r3_5)*
(1+r3_6)*(1+r3_7)*(1+r3_8)*(1+r3_9)*(1+r3_10)*
(1+r3_11)*(1+r3_12)*(1+r3_13)*(1+r3_14)*(1+r3_15)*
(1+r3_16)*(1+r3_17)*(1+r3_18)*(1+r3_19)*(1+r3_20))^(1/t)) - 1
yn_3a
## [1] 0.03236716
El rendimiento al vencimiento de un bono a 20 años es 3.236 %
t=15
r3_1 = 0.0284
r3_2 = 0.0288
r3_3 = 0.0292
r3_4 = 0.0296
r3_5 = 0.0301
r3_6 = 0.0305
r3_7 = 0.0309
r3_8 = 0.0313
r3_9 = 0.0317
r3_10 = 0.0322
r3_11 = 0.0326
r3_12 = 0.0330
r3_13 = 0.0334
r3_14 = 0.0338
r3_15 = 0.0343
yn_3b <- (((1+r3_1)*(1+r3_2)*(1+r3_3)*(1+r3_4)*(1+r3_5)*
(1+r3_6)*(1+r3_7)*(1+r3_8)*(1+r3_9)*(1+r3_10)*
(1+r3_11)*(1+r3_12)*(1+r3_13)*(1+r3_14)*(1+r3_15))^(1/t)) - 1
yn_3b
## [1] 0.0313184
t=15
vf = 1000
yn_3b = 0.0313184
Pb_3b <- vf / ((1+yn_3b) ^ (t))
Pb_3b
## [1] 629.6635
El precio de un bono cupon cero es $ 629.66. dolares.
\[ r(t) = 0,028 + 0,0002t - 0,0003t^2\]
r_4a <- function(t) {
tasaforw <- numeric()
{
0.028 + 0.0002*t - 0.0003*(t^2)}
}
r4a <- r_4a(t=8)
r4a
## [1] 0.0104
t=8
r4_1 = 0.0279
r4_2 = 0.0272
r4_3 = 0.0259
r4_4 = 0.024
r4_5 = 0.0215
r4_6 = 0.0184
r4_7 = 0.0147
r4_8 = 0.0104
yn_4a <- (((1+r4_1)*(1+r4_2)*(1+r4_3)*(1+r4_4)*(1+r4_5)*
(1+r4_6)*(1+r4_7)*(1+r4_8))^(1/t)) - 1
yn_4a
## [1] 0.02123297
El rendimiento al vencimiento de un bono es 2.12 %
t=5
r4_1 = 0.0279
r4_2 = 0.0272
r4_3 = 0.0259
r4_4 = 0.024
r4_5 = 0.0215
yn_4b <- (((1+r4_1)*(1+r4_2)*(1+r4_3)*(1+r4_4)*(1+r4_5))^(1/t)) - 1
yn_4b
## [1] 0.02529738
vf = 1000
t = 5
yn_4b = 0.02529738
Pb_4b <- vf / ((1+yn_4b)^ (t))
Pb_4b
## [1] 882.5733
El precio de un bono cupon cero es $ 882.57 dolares.
Datos de los Rendimientos y Tasas Forward a 8 años, extraida con la funcion:
\[ r(t) = 0,028 + 0,0002t - 0,0003t^2\]
yn_4emp <- c( 0.0279, 0.02754994, 0.02699967, 0.02624893, 0.02529738, 0.02278999, 0.02414458, 0.02123297)
forward <- c(r4_1, r4_2, r4_3,r4_4, r4_5, r4_6,r4_7,r4_8)
matur4c <- seq(1, 8, length =8)
Rta: la curva de tasas forward presenta mayor concavidad comparado con la curva de rendimiento. La curva de rendimiento presenta una ligera concavidad, y tambien una tendencia a la baja menos que las tasas forward.
plot(matur4c, yn_4emp, ylim = c(0.01, 0.035), xlab = "madurez", ylab = "empirical forward rate",
type = "b", cex = 0.75, lwd = 2,
main = "Grafico de CUrva de Rendimiento - Tasas Forward")
lines(forward, col=3)
legend("bottomleft",legend=c("curva de rendimientos","Tasas Forward"),
col=c(1,3),lty=1)
Muestra el rendimiento al vencimiento a 10 años
t=10
r4_1 = 0.0279
r4_2 = 0.0272
r4_3 = 0.0259
r4_4 = 0.024
r4_5 = 0.0215
r4_6 = 0.0184
r4_7 = 0.0147
r4_8 = 0.0104
r4_9 = 0.0055
r4_10 = 0
yn_4d <- (((1+r4_1)*(1+r4_2)*(1+r4_3)*(1+r4_4)*(1+r4_5)*
(1+r4_6)*(1+r4_7)*(1+r4_8)*(1+r4_9)*(1+r4_10))^(1/t)) - 1
yn_4d
## [1] 0.01750856
Muestra el precio del bono a 10 años
vf = 1000
t = 10
yn_4d = 0.01750856
Pb_4d <- vf / ((1+yn_4d)^ (t))
Pb_4d
## [1] 840.6579
Muestra el rendimiento al vencimiento un año despues.
yn_4d_1 <- ((1+r4_2)*(1+r4_3)*(1+r4_4)*(1+r4_5)*
(1+r4_6)*(1+r4_7)*(1+r4_8)*(1+r4_9)*(1+r4_10))^(1/(t-1)) - 1
yn_4d_1
## [1] 0.01636046
Muestra el precio del bono un año despues.
vf = 1000
t = 10
yn_4d_1 = 0.01636046
Pb_4d_1 <- vf / ((1+yn_4d_1)^ (t-1))
Pb_4d_1
## [1] 864.1122
Pb_4d_1 = 864.1122
vp4 = 840.6579
ValorInv4 = Pb_4d_1 - vp4
ValorInv4
## [1] 23.4543
El valor de la inversion es $ 23.45 dolares.
retorno_4d <- (Pb_4d_1 - vp4)/ vp4
retorno_4d
## [1] 0.02789993
El retorno es de 2.79 %
bondvalue = function (c, T, r, par)
{
# Calcula bv = valores de bonos (precios actuales) correspondientes
# a todos los valores de rendimiento al vencimiento en el
# vector de entrada r
#
# ENTRADA
# c = pago del cupón (semestral)
# T = tiempo hasta el vencimiento (en años)
# r = vector de rendimientos al vencimiento (tasas semestrales)
# par = valor nominal
#
bv = c / r + (par - c / r) * (1 + r)^( -2 * T)
bv
}
price = 1200 # precio actual del bono
c = 40 # cupón de pago
T= 30 # tiempo hasta la madurez
par = 1000 # valor nominal del bono
r = seq(0.02, 0.05, length = 300)
value5a = bondvalue(c, T, r, par)
yield5a = spline(value5a, r, xout = price) # interpolación spline
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 # precio actual del bono
c = 280 # cupón de pago
T = 8 * 2 # tiempo hasta la madurez
par = 10000 # valor nominal del bono
r = seq(0.02, 0.05, length = 300)
value5b = bondvalue(c, T, r, par)
yield5b = spline(value5b, r, xout = price) # interpolación spline
yield5b
## $x
## [1] 9800
##
## $y
## [1] 0.0289672
El retorno a la madurez de un bono es de 2.89 %
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)
price = 1050 # precio actual del bono
c = 35 # cupón de pago
T = 20*2 # tiempo hasta la madurez
par = 1000 # valor nominal del bono
r = seq(0.02, 0.05, length = 300)
value5c = bondvalue(c, T, r, par)
yield5c = spline(value5c, r, xout = price) # spline interpolation
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)
Suponiendo precio <par ⇒ tasa de cupón <rendimiento actual <rendimiento al vencimiento.
price = 950.10 # precio actual del bono
c = seq(0.02, 0.05, length = 300)
T = 5 # tiempo hasta la madurez
par = 1000 # valor nominal del bono
r = 0.035
value5d = bondvalue(c, T, r, par)
cd5d = spline(value5d, c, xout = price) # spline
cd5d
## $x
## [1] 950.1
##
## $y
## [1] 28.97218
El valor del cupon de $ 28.97 dolares