Guest User

Untitled

a guest
Feb 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. rm(list=ls())
  2.  
  3. library(ggplot2)
  4.  
  5. #generate Brownian motion
  6. t <- 1:1e3
  7. sig2 <- 0.01
  8. x <- rnorm(n = length(t) - 1, sd = sqrt(sig2))
  9. data <- c(0, cumsum(x))
  10.  
  11. #function to find Hurst exponent
  12. simpleHurst <- function(y){
  13. sd.y <- sd(y)
  14. m <- mean(y)
  15. y <- y - m
  16. max.y <- max(cumsum(y))
  17. min.y <- min(cumsum(y))
  18. RS <- (max.y - min.y)/sd.y
  19. return(RS)
  20. }
  21.  
  22. #find Hurst exponent of Brownian motion
  23. df.rs <- data.frame()
  24. for(i in c(1, 2, 4, 8, 16, 32)){
  25. RS <- 0
  26. n <- floor((length(data)/i))
  27. for(j in 0:(i-1)){
  28. X <- data[(1:n) + j*n]
  29. RS <- RS + simpleHurst(y = X)
  30. }
  31.  
  32. df.rs <- rbind(df.rs,
  33. data.frame("log.t" = log(length(X)),
  34. "log.RS"= log(RS / n)))
  35. }
  36.  
  37. ggplot(data=df.rs, aes(x=log.t, y=log.RS)) + geom_point(size=I(2))
Add Comment
Please, Sign In to add comment