1
Regresion no lineal para estimar los parametros \(\theta_2},{\theta_3}{\theta_4}\)
\[r(T; {\theta_1}, {\theta_2},{\theta_3}{\theta_4}) = {\theta_1}+({\theta_2}+{\theta_3T})exp(-{\theta_4}T)\]
1a)
Se cargan los datos y se ejecutan las funciones para determinar los thetas:
dat <- read.table("D:/USMP/2020/risk/practica/PC4/ZeroPrices.txt",header = T,sep ="")
#Se instalar minpack.lm para usar nlsLM, esto debido a compatibilidad en la forma de la funcion forward
fm2DNase1 <- nlsLM(price ~ theta1+(theta2+theta3*maturity)*exp(-theta4*maturity),
data = dat,
start = list(theta1 = 0,theta2 = 0,theta3 = 0,theta4 = 0))
summary(fm2DNase1)##
## Formula: price ~ theta1 + (theta2 + theta3 * maturity) * exp(-theta4 *
## maturity)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## theta1 16.3988182 0.4950504 33.126 <0.0000000000000002 ***
## theta2 83.4262172 0.4012845 207.898 <0.0000000000000002 ***
## theta3 -0.0003329 35.8131278 0.000 1.000
## theta4 0.0701837 0.4290096 0.164 0.871
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3268 on 36 degrees of freedom
##
## Number of iterations to convergence: 15
## Achieved convergence tolerance: 0.0000000149
1b)
## [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
# Calculo del rendimiento estimado
maturity <- dat[,1]
restimado <- -diff(log(16.3988182+(83.4262172+(-0.0003329*maturity))*exp(-0.0701837*maturity)))/diff(dat$maturity)
#Graficamos
plot(dat$maturity[2:length(dat$maturity)], rempirico , ylim = c(0.010,
0.099), xlab = "maturity", ylab = "rendimiento empirico & rendimiento estimado",
type = "b", cex = 0.99, lwd = 2,
main = "Rendimientos")
# Se a昼㸱ade la linea de rendimiento estimado
lines(dat$maturity[2:length(dat$maturity)],restimado, lwd = 2, col = "2")
legend("bottomleft",legend=c("Rendimientos empirico","Rendimientos estimado"),
col=c(1,2),lty=1)2
2a)
Determinar el valor del rendimiento :
## [1] 3.846995
El rendimiento es de 3.84%
2b)
## [1] 815.2707
El valor del bono es de 815.27
2c)
## [1] -1.53736
El retorno del bono es negativo en 1.53%
3
3a)
Tasa forward: \[r(t) = 0,028 + 0,00042t\] Calculo del rendimiento a 20 years
## [1] 3.22
El rendimiento es de 3.22%
3b)
Calculo del bono cupon cero anual con la siguiente formula.
\[PRICE= \frac{VN}{(1+y))^t}\]
VN: Valor Nominal, y: Rendimiento del bono, T: Tiempo en terminos anuales
## [1] 0.03115
## [1] 631.2077
El precio del bono es de 631.20 a 15 anos
4
Tasa forward:
\[r(t) = 0,028 + 0,0002t - 0,0003t^2\]
4a)
Rendimiento a 8 years
## [1] 1.04
## [1] 1.04
El rendimiento es 1.04%
4b)
Podemos analizarlo por dos metodos
El primero metodo financiero de futuros :
\[PRICE= \frac{VN}{exp(ty(t))}\]
Donde t: tiempo en anos, VN: Valor nomial , y: tasa
Tambien por la siguifiente formula como metodo convencional:
\[PRICE= \frac{VN}{(1+(\frac{y}{m}))^mt}\]
## [1] 0.0215
## [1] 898.0765
## [1] 899.1003
Los precios son de 898 en formula exponencial y 899 en financiero convencional.
4c)
Creacion de las tasas a futuro y rendimientos
r4c = function(t){0.028 + 0.0002 * t - 0.0003*t^2}
#creacion de secuencia para tasas forward
c <- seq(1:40)
TForward <- r4c(c)
TForward## [1] 0.0279 0.0272 0.0259 0.0240 0.0215 0.0184 0.0147 0.0104 0.0055
## [10] 0.0000 -0.0061 -0.0128 -0.0201 -0.0280 -0.0365 -0.0456 -0.0553 -0.0656
## [19] -0.0765 -0.0880 -0.1001 -0.1128 -0.1261 -0.1400 -0.1545 -0.1696 -0.1853
## [28] -0.2016 -0.2185 -0.2360 -0.2541 -0.2728 -0.2921 -0.3120 -0.3325 -0.3536
## [37] -0.3753 -0.3976 -0.4205 -0.4440
#creacio de secuencia de precios a tasas forward para su rendimiento
p <- c(1:40)
Rendimiento <- -diff(log(p))/diff(TForward)
#Graficamos
plot(TForward[2:length(TForward)], Rendimiento , ylim = c(0.00,
40), xlab = "maturity", ylab = "rendimiento empirico & rendimiento estimado",
type = "b", cex = 0.99, lwd = 2,
main = "Rendimientos")
# Se a昼㸱ade la linea de rendimiento estimado
lines(TForward,TForward, lwd = 2, col = "2")
legend("bottomleft",legend=c("curva de rendimientos","Tasas forwards"),
col=c(1,2),lty=1)Las tasas forward tienen comportamiento o forma concava por tener caidas negativas. Los rendimientos son de tendencia convexa o positiva.
4d)
## [1] 0.019
## [1] 0.019
## [1] 828.4345
## [1] 1162.501
## [1] 40.32508
El rentimiento es del 40.32%
5
Formula para calculo de bonos
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
}5a)
price <- 1200
c <- 40
T <- 30
par <- 1000
r <- seq(0.02, 0.05, length = 300)
uniroot(function(r) r^2-0.5,c(0.7,0.8))## $root
## [1] 0.707107
##
## $f.root
## [1] 0.0000003766118
##
## $iter
## [1] 3
##
## $init.it
## [1] NA
##
## $estim.prec
## [1] 0.00006103516
## $x
## [1] 1200
##
## $y
## [1] 0.03239813
La madurez es de 0.032, 3.2%.
5b)
price <- 9800
c <- 280
T <- 8
par <- 10000
r <- seq(0.02, 0.05, length = 300)
V5b <- bondvalue(c, T*2, r/2, par)
YTM <- spline(V5b, r, xout = price)
YTM## $x
## [1] 9800
##
## $y
## [1] 0.05793221
La madurez es de 5.7%
5c)
## $root
## [1] 0.707107
##
## $f.root
## [1] 0.0000003766118
##
## $iter
## [1] 3
##
## $init.it
## [1] NA
##
## $estim.prec
## [1] 0.00006103516
## $x
## [1] 1050
##
## $y
## [1] 0.06626954
La madurez es de 6.6%
5d)
price <- 950.1
T <- 5
par <- 1000
r <- 0.035
c <- seq(0.02, 0.05, length = 300)
V5b <- bondvalue(c, T, r, par)
VC <- spline(V5b, c, xout = price)
VC## $x
## [1] 950.1
##
## $y
## [1] 28.97218
El cupon es de 28.97