- # Function that reads Reuters CSV tick data and converts Reuters dates
- # Assumes format is Date,Tick
- readRTD <- function(filename) {
- tickData <- read.csv(file=filename, header=TRUE, col.names=c("Date","Tick"))
- tickData$Date <- as.POSIXct(strptime(tickData$Date, format="%d/%m/%Y %H:%M:%S"))
- tickData
- }
-
- # Boilerplate function for Reuters FX tick data transformation and density plot
- plot.reutersFXDensity <- function() {
- filenames <- c("data/eur_usd_tick_26_10_2007.csv",
- "data/eur_usd_1min_26_10_2007.csv",
- "data/eur_usd_5min_26_10_2007.csv",
- "data/eur_usd_hourly_26_10_2007.csv",
- "data/eur_usd_daily_26_10_2007.csv")
- labels <- c("Tick", "1 Minute", "5 Minutes", "Hourly", "Daily")
-
- par(mfrow=c(length(filenames), 2),mar=c(0,0,2,0), cex.main=2)
- tickData <- c()
- i <- 1
- for (filename in filenames) {
- tickData[[i]] <- readRTD(filename)
- # Transform: `$Y = \nabla\log(X_i)[color=#373737][b]Frequently we will want to estimate the empirical probability density function of real-world data and compare it to the theoretical density from one or more probability distributions. The following example shows the empirical and theoretical normal density for EUR/USD high-frequency tick data [/b][/color]
- logtick <- diff(log(tickData[[i]]$Tick))
- # Normalize: `$\frac{(Y-\mu_Y)}{\sigma_Y}[color=#373737][b]Frequently we will want to estimate the empirical probability density function of real-world data and compare it to the theoretical density from one or more probability distributions. The following example shows the empirical and theoretical normal density for EUR/USD high-frequency tick data [/b][/color]
- logtick <- (logtick-mean(logtick))/sd(logtick)
- # Theoretical density range: `$\left[\lfloor\mathrm{min}(Y)\rfloor,\lceil\mathrm{max}(Y)\rceil\right][color=#373737][b]Frequently we will want to estimate the empirical probability density function of real-world data and compare it to the theoretical density from one or more probability distributions. The following example shows the empirical and theoretical normal density for EUR/USD high-frequency tick data [/b][/color]
- x <- seq(floor(min(logtick)), ceiling(max(logtick)), .01)
- plot(density(logtick), xlab="", ylab="", axes=FALSE, main=labels[i])
- lines(x,dnorm(x), lty=2)
- #legend("topleft", legend=c("Empirical","Theoretical"), lty=c(1,2))
- plot(density(logtick), log="y", xlab="", ylab="", axes=FALSE, main="Log Scale")
- lines(x,dnorm(x), lty=2)
- i <- i + 1
- }
- par(op)
- }
上面的代码解疑:
https://bbs.pinggu.org/thread-3622629-1-1.html
大数据研究:
https://bbs.pinggu.org/thread-3621697-1-1.html
文献:
本帖隐藏的内容