Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunho0130/44d115f31c8e021c152a7d81249e6431 to your computer and use it in GitHub Desktop.
Save yunho0130/44d115f31c8e021c152a7d81249e6431 to your computer and use it in GitHub Desktop.
##Download CSV file from Kaggle
# https://www.kaggle.com/ehallmar/daily-historical-stock-prices-1970-2018#historical_stock_prices.csv
##Hurst Exponent
simpleHurst <- function(y){
sd.y <- sd(y)
m <- mean(y)
y <- y - m
max.y <- max(cumsum(y))
min.y <- min(cumsum(y))
RS <- (max.y - min.y)/sd.y
H <- log(RS) / log(length(y))
return(H)
}
# X <- read.table("mac_backup/# Ph_d/19-01/파이낸스인텔리전스(IIE7561-01)/week11/Chaos/k200_from_2001.txt")
filename = "historical_stock_prices.csv"
X <- read.table(paste0("mac_backup/# Ph_d/19-01/파이낸스인텔리전스(IIE7561-01)/week11/daily-historical-stock-prices-1970-2018/",filename), sep = ",", header=TRUE)
is.data.frame(X)
head(X)
X_backup <- X
X2 <-subset(X, ticker=="IBM", select = c(date, adj_close))
head(X2)
X <- X2
Data <- as.numeric(unlist(X))
simpleHurst(Data)
Hurst <- array(dim=c(4000,1))
for(j in 10:4000){
DataVector <- array(dim=c(j,1))
for(i in 1:j){
DataVector[i,1] <- Data[i]
}
DataVector <- as.numeric(unlist(DataVector))
Hurst[j,1] <- simpleHurst(DataVector)
}
plot(Hurst)
##?ʿ??? ??Ű??
#install.packages("nonlinearTseries")
library("nonlinearTseries")
##Correlation Dimension
emb.dim = estimateEmbeddingDim(Data, number.points = length(Data), time.lag = 1, max.embedding.dim = 15)
emb.dim
result <- corrDim(Data, min.embedding.dim = emb.dim, max.embedding.dim = emb.dim + 5, min.radius = 1, max.radius = 200, n.points.radius = 40)
estimate(result, regression.range = c(1,200), use.embeddings = 9:14)
##Maximum Lyapunov Exponent
ml=maxLyapunov(time.series=Data, radius = 200, time.lag=1, min.neighs=2, min.embedding.dim=emb.dim, max.embedding.dim=emb.dim+5, min.ref.points=500, max.time.steps=40, theiler.window=4, do.plot=FALSE)
ml.estimation = estimate(ml,regression.range = c(1,200),use.embeddings = 9:14,do.plot = FALSE)
ml.estimation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment