Vous êtes sur la page 1sur 2

Consideremos ahora el modelo de Black-Scholes (movimiento Browniano Geometrico)

> require(stats4)
> require(sde)
> dcBS <- function(x, t, x0, theta, log = TRUE){
+ ml <- log(x0) + (theta[1]-theta[2]^2/2)*t
+ sl <- sqrt(t)*theta[2]
+ lik <- dlnorm(x, meanlog = ml, sdlog = sl, log=TRUE)
+ if(!log)
+ lik <- exp(lik)
+ lik
+ }
> BS.lik <- function(theta1,theta2) {
+ n <- length(X)
+ dt <- deltat(X)
+ -sum(dcBS(x=X[2:n], t=dt, x0=X[1:(n-1)], theta=c(theta1,theta2),
+ log=TRUE))
+ }
Y as encontramos los valores optimos para los parametros.
> set.seed(123)
> X <- sde.sim(model="BS", theta=c(.5,.2), delta=0.01)
> mle(BS.lik, start=list(theta1=1, theta2=1),
+ method="L-BFGS-B", lower=c(0.01,0.01)) -> fit
> coef(fit)

theta1 theta2
0.6773086 0.1816525

> length(X)*deltat(X)

[1] 1.01

> set.seed(123)
> X <- sde.sim(model="BS", theta=c(.5,.2), N=1000, delta=0.01)
> mle(BS.lik, start=list(theta1=1, theta2=1),
+ method="L-BFGS-B", lower=c(0.01,0.01)) -> fit
> coef(fit)

theta1 theta2
0.5319061 0.1982440

> length(X)*deltat(X)

[1] 10.01

> set.seed(123)
> X <- sde.sim(model="BS", theta=c(.5,.2), N=5000, delta=0.01)
> mle(BS.lik, start=list(theta1=1, theta2=1),
+ method="L-BFGS-B", lower=c(0.01,0.01)) -> fit
> coef(fit)

theta1 theta2
0.4986410 0.1988985

> length(X)*deltat(X)

[1] 50.01

1
>

Para el O-U
> OU.lik <- function(theta1, theta2, theta3){
+ n <- length(X)
+ dt <- deltat(X)
+ -sum(dcOU(X[2:n], dt, X[1:(n-1)], c(theta1,theta2,theta3), log=TRUE))
+ }
> require(stats4)
> require(sde)
> set.seed(123)
> X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1)
> mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
+ method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit
> summary(fit)

Maximum likelihood estimation

Call:
mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 0.5,
theta3 = 1), method = "L-BFGS-B", lower = c(-Inf, 0, 0))

Coefficients:
Estimate Std. Error
theta1 3.355322 0.28159504
theta2 1.106107 0.09010627
theta3 2.052815 0.07624441

-2 log L: 3366.389

> set.seed(123)
> X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1e-3)
> mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
+ method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit2
> summary(fit2)

Maximum likelihood estimation

Call:
mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 0.5,
theta3 = 1), method = "L-BFGS-B", lower = c(-Inf, 0, 0))

Coefficients:
Estimate Std. Error
theta1 13.303899 6.78849841
theta2 5.411345 3.08468505
theta3 1.984735 0.04448513

-2 log L: -2704.316

>

Vous aimerez peut-être aussi