Site icon R-bloggers

Cont model – Part II

[This article was first published on R snippets, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In my last post I have investigated properties of Cont model (you can download the paper here). Today I would like to show how we can use simulations to further simplify its analysis.

First let us start with the observation that the model does not really require two parameters d and l as they are directly linked. If we multiply d by 2 and divide l by 2 we obtain exactly the same simulated returns path (scaled by 2). Let me motivate this result using simulation. The code that performs verification is simple (for explanation of the code logic look at my previous post):

cont.run <- function(burn.in, reps, n, d, l ,s) {< o:p>
  tr <- rep(0, n)< o:p>
  sig <- rnorm(reps, 0, d)< o:p>
  r <- rep(0, reps)< o:p>
  for (i in 1:reps) {< o:p>
    r[i] <- (sum(sig[i] > tr) sum(sig[i] < (-tr))) / (l * n)< o:p>
    tr[runif(n) < s] <- abs(r[i])< o:p>
  }< o:p>
  return(r[burn.in:reps])< o:p>
}< o:p>

set.seed(1)< o:p>
sim.points <- 100< o:p>
d <- runif(sim.points, 0.002, 0.01)< o:p>
l <- runif(sim.points, 5, 10)< o:p>
s <- runif(sim.points, 0.01, 0.1)< o:p>
m <- runif(sim.points, 1, 2) # comparison multiplier< o:p>
seeds <- runif(sim.points)   # common random numbers seeds< o:p>

range(mapply(function(d, l, s, m, seed) {< o:p>
    set.seed(seed)< o:p>
    r1 <- cont.run(1000, 10000, 1000, d, l ,s)< o:p>
    set.seed(seed)< o:p>
    r2 <- cont.run(1000, 10000, 1000, d / m, l * m ,s)< o:p>
    range(r1 / m r2)< o:p>

  }, d, l, s, m, seeds)) # -2.775558e-17  1.387779e-17< o:p>

We can see that r1/m and r2 vectors are almost identical in all 100 simulations.

This finding means that we can limit ourselves to analysis of d*l product in simulation output analysis. So we go back to sim_output.txt file and modify the visualization as follows:

library(lattice)< o:p>

data.set <- read.table(“sim_output.txt”, head = T,< o:p>
                       colClasses = rep(“numeric”, 4))< o:p>
data.set$dl <- data.set$d * data.set$l< o:p>
data.set$cs <- cut(data.set$s, seq(0.01, 0.1, len = 10))< o:p>
data.set$cdl <- cut(data.set$dl, seq(0, 0.2, len = 11))< o:p>
sum.data <- aggregate(k ~ cdl + cs, data = data.set, mean)< o:p>
trellis.par.set(regions=list(col=topo.colors(100)))< o:p>
levelplot(k~cdl+cs, data=sum.data,scales=list(x=list(rot=90)),< o:p>
          xlab = “d * l”, ylab = “s”)

Here is the final plot showing average k as a function of d*l and s:
We can see that the model produces excess kurtosis when d*l is small. What does it mean? In this case we have low d and low l. So new incoming information has low standard deviation but daily returns are allowed to be large. The conclusion is that kurtosis will be present if there is low level of trading on the market (the sum sum(sig[i] > tr) + sum(sig[i] < (-tr)) is relatively low).

We will use simulation again to verify this hypothesis. Here is the code with added trading volume variable (t):

cont.run.vol <- function(burn.in, reps, n, d, l ,s) {< o:p>
  tr <- rep(0, n)< o:p>
  sig <- rnorm(reps, 0, d)< o:p>
  r <- rep(0, reps)< o:p>
  t <- rep(0, reps)< o:p>
  for (i in 1:reps) {< o:p>
    r[i] <- (sum(sig[i] > tr) sum(sig[i] < (-tr))) / (l * n)< o:p>
    t[i] <- (sum(sig[i] > tr) + sum(sig[i] < (-tr))) / n
    tr[runif(n) < s] <- abs(r[i])< o:p>
  }< o:p>
  c(kurtosis(r[burn.in:reps]), mean(t[burn.in:reps]))
}< o:p>

sim.points <- 100< o:p>
d <- runif(sim.points,0.001,0.01)< o:p>
l <- runif(sim.points,5,20)< o:p>
s <- runif(sim.points,0.01,0.1)< o:p>
data.set <- mapply(function(d, l, s) {< o:p>
              cont.run.vol(1000, 10000, 1000, d, l ,s)< o:p>
            }, d, l, s)< o:p>
data.set <- t(data.set)< o:p>
colnames(data.set) <- c(“kurtosis”, “volume”)< o:p>
data.set <- data.set[, 2:1]< o:p>
par(mar=c(4, 4, 1, 1))
plot(data.set)

The resulting plot confirms our reasoning:


The final question, that I will leave open here, is whether the observed relationship is an artifact of the model or the relationship that currently I am working on to verify empirically.

To leave a comment for the author, please follow the link and comment on their blog: R snippets.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.