c.0<- min(ZeroPrices$maturity)*0.5
modelo1 <- lm(log(maturity - c.0) ~ periodo, data=ZeroPrices)
pred1<-predict(modelo1)
start <- list(a=0.0001, d=-0.0001)
nonlin_mod=
nonlin_mod1<-nls2(maturity1~a+(pred1)*exp(-d*periodo),start=start, data=ZeroPrices, trace = FALSE, algorithm="port")
summary(modelo1)##
## Call:
## lm(formula = log(maturity - c.0) ~ periodo, data = ZeroPrices)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.2374 -0.1185 0.4252 0.5392 0.7223
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.6468 3.5304 2.449 0.019 *
## periodo -1.1422 0.6239 -1.831 0.075 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.053 on 38 degrees of freedom
## Multiple R-squared: 0.08105, Adjusted R-squared: 0.05687
## F-statistic: 3.352 on 1 and 38 DF, p-value: 0.07498
##
## Formula: maturity1 ~ a + (pred1) * exp(-d * periodo)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## a -0.02899 0.04610 -0.629 0.533
## d 0.47287 0.05196 9.101 4.38e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.06327 on 38 degrees of freedom
##
## Algorithm "port", convergence message: relative convergence (4)
En este caso los valores θ1 = 0.78785, θ2 = 4.0416, θ3 = -1.1422, θ4 = 0.22799
Por lo tanto aplicando estas tecnicas de aproximación quedaria de la siguiente manera: maturity1~0.78785+(4.0416-1.1422periodo)exp(-0.22799*periodo)
Que sería la ecuación de regresion no-lineal de mejor ajuste. Con un valor del coeficiente de determinación de bajo ajuste pero es la mejor dado que este tipo de algortimos usan metodología de aproximación sucesivas de Taylor, por regla matemática mejor se ajusta a los datos.
## [1] 0.03846995
Vf=1000 #Valor facial
r_2=0.0425 #Tasa r
t=5 #Tiempo de maduración
Vp_2= Vf/((1+r)*(1+r_2)^(t-1))
Vp_2## [1] 815.2707
## [1] -12.7293
## [1] 0.0322
## [1] 0.0322
## [1] 621.6446
## [1] 0.0104
## [1] 0.0215
## [1] 899.1003
#install.packages("ggplot2")
library(ggplot2)
ggplot(data.frame(x=c(0, 100)), aes(x)) +stat_function(fun=function(x) 0.028 + 0.0002*x - 0.0003*x^2)## [1] 0
## [1] -0.0061
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
}c= 40 # Cupón
T=30 # Tiempo de maduración
r=0 # Retorno a la madurez
par=1000 # Valor facial del bono
bv=1200 # Precio del actual del bono
uniroot(function(r) bv-(c/r+(par-c/r)*(1+r)^(-2*T)), interval= c(0.0001, 1), tol = 1e-9)$root## [1] 0.03239813
c=280 # Cupón
T=8 # Tiempo de maduración
r=0 # Retorno a la madurez
par=10000 # Valor facial del bono
bv=9800 # Precio del actual del bono
uniroot(function(r) bv-(c/r+(par-c/r)*(1+r)^(-2*T)), interval= c(0.0001, 1), tol = 1e-9)$root## [1] 0.0295872
c=35 # Cupón
T=20 # Tiempo de maduración
r=0 # Retorno a la madurez
par=1000 # Valor facial del bono
bv=1050 # Precio del actual del bono
uniroot(function(r) bv-(c/r+(par-c/r)*(1+r)^(-2*T)), interval= c(0.0001, 1), tol = 1e-9)$root## [1] 0.03274004
c=0 # Cupón
T=5 # Tiempo de maduración
r=0.035 # Retorno a la madurez
par=1000 # Valor facial del bono
bv=950.10 # Precio actual del bono
uniroot(function(c) bv-(c/r+(par-c/r)*(1+r)^(-2*T)), interval= c(0, 100), tol = 1e-9)$root## [1] 28.99996