jmf1: Log-likelihood for the univariate bubble model by Fry (2014)

Description Usage Arguments Details Value Examples

View source: R/Fry_bubble.R

Description

This function computes the log-likelihood for the univariate bubble model by Fry (2014)

Usage

1
jmf1(x, data)

Arguments

x

is a 4 x 1 parameter vector

data

is a (n-1) x 1 numeric data vector

Details

This function computes the log-likelihood for the univariate bubble model by Fry (2014). The parameters vector consists of the following parameters:

x[1]: mean

x[2]: variance (sigma)

x[3]: alpha (from hazard function)

x[4]: beta (from hazard function)

Value

y a 1 x 1 scalar which is the log-likelihood

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 ## Not run: 
 #Create data set with log-returns
 library(PerformanceAnalytics)
 library(numDeriv)
 path.bit=system.file("extdata", "coindesk-bpi-USD-close.csv", package = "bubble")

 #load data on bitcoin downloaded from coindesk:  http://www.coindesk.com/price/
 dat <- read.table(path.bit, dec = ".", sep =",", header = TRUE)
 dat2 <- subset(dat, as.numeric(Date) > 898 & as.numeric(Date) < 1233)
 row.names(dat2) <- levels(dat2$Date)[dat2$Date]
 dat3 <- dat2[, 'Close', drop=FALSE]

 #compute log-returns
 bitret <- CalculateReturns(dat3, method="log")
 bitret = bitret[-1,]
 plot(bitret)
 plot(cumsum(bitret))

 #Set (good) starting values and optimize
 mu <- mean(bitret)
 n <- length(bitret)
 sigma <- sqrt(((n-1)/n)*var(bitret))
 startx.1 <- c(mu, sigma, 4, 4)
 result.1 <- optim(startx.1, jmf1, data=bitret,control=list(maxit=1000, fnscale=-1), hessian = TRUE)

 #Compute hessian and variance-covariance matrix
  hess <- hessian(x=result.1$par, data=bitret, func=jmf1)
  hess2 <- -solve(hess) # variance-covariance matrix
  hess2

 #Compute v and mu.tilde from estimated parameters and replicate
 #the parameter estimates of bubble model reported in Table 2, p.35, by Cheah and Fry (2015)
  mu.est <- result.1$par[1]; mu.est;
  sigma.est <- result.1$par[2]; sigma.est;
  alpha.est <- result.1$par[3]; alpha.est;
  beta.est <- result.1$par[4]; beta.est;

  v <- round((sqrt(sigma.est*alpha.est*(beta.est-1)^((1/beta.est)-1))),3)
  v
  mu.tilda <- round((mu.est + (1/2)*sigma.est), 5)
  mu.tilda

 
## End(Not run)

deanfantazzini/bubble documentation built on Oct. 22, 2020, 2:43 p.m.