This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results <- emh::is_random(my.zoo.object) | |
emh::plot_results(results) | |
View(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(devtools) | |
devtools::install_github(repo="stuartgordonreid/emh") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testRobustness <- function(t = (252 * 7)) { | |
# Generate an underlying signal. | |
signal <- sin(seq(1, t)) / 50 | |
signal <- signal - mean(signal) | |
# For different noise levels | |
sds <- seq(0.0, 0.020, 0.0005) | |
cratios <- c() | |
for (s in sds) { | |
# Generate a noisy signal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bettingStrategyProof <- function(t = (252 * 7), w = 5, sd = 0.02, sims = 30) { | |
# Store market and strategy returns. | |
markets <- NULL | |
strats <- NULL | |
for (i in 1:sims) { | |
# Generate an underlying signal. | |
signal <- sin(seq(1, t)) / 50 | |
signal <- signal - mean(signal) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testRobustness <- function(t = (252 * 7)) { | |
# Generate an underlying signal. | |
signal <- sin(seq(1, t)) / 50 | |
signal <- signal - mean(signal) | |
# For different noise levels | |
sds <- seq(0.0, 0.020, 0.0005) | |
cratios <- c() | |
for (s in sds) { | |
# Generate a noisy signal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compressionTest <- function(code, years = 7, algo = "g") { | |
# The generic Quandl API key for TuringFinance. | |
Quandl.api_key("t6Rn1d5N1W6Qt4jJq_zC") | |
# Download the raw price data. | |
data <- Quandl(code, rows = -1, type = "xts") | |
# Extract the variable we are interested in. | |
ix.ac <- which(colnames(data) == "Adjusted Close") | |
if (length(ix.ac) == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Given a log price process, X, compute the Z-score which can be used | |
#' to accept or reject the hypothesis that the process evolved according to a | |
#' Brownian Motion model with drift and stochastic volatility. | |
#' | |
#' @description Given a log price process, X, and a sampling interval, q, this | |
#' method returns a Z score indicating the confidence we have that X evolved | |
#' according to a Brownian Motion mode with drift and stochastic volatility. This | |
#' heteroskedasticity-consistent variance ratio test essentially checks to see | |
#' whether or not the observed Mr statistic for the number of observations, is | |
#' within or out of the limiting distribution defined by the Asymptotic Variance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Estimator for the value of the asymptotic variance of the Mr statistic. | |
#' This is equivalent to a weighted sum of the asymptotic variances for each of | |
#' the autocorrelation co-efficients under the null hypothesis. | |
#' | |
#' @details Given a log price process, X, and a sampling interval, q, this | |
#' method is used to estimate the asymptoticvariance of the Mr statistic in the | |
#' presence of stochastic volatility. In other words, it is a heteroskedasticity | |
#' consistent estimator of the variance of the Mr statistic. This parameter is | |
#' used to estimate the probability that the given log price process was | |
#' generated by a Brownian Motion model with drift and stochastic volatility. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Compute the Mr statistic. | |
#' | |
#' @description Compute the Mr statistic. The Md statistic is the ratio between | |
#' two estimate values for Sigma computed using the calibrateSigma function for | |
#' sampling intervals 1 and the estimate value for Sima computed using the | |
#' CalibrateSigmaOverlapping function for sampling inveral q minus 1. | |
#' This statistic should converge to zero. | |
#' | |
#' @inheritParams calibrateSigma | |
#' @return Mr double :: The Mr statistic defined by Lo and MacKinlay. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Compute the Md statistic. | |
#' | |
#' @description Compute the Md statistic. The Md statistic is the difference | |
#' between two estimate values for Sigma computed using the calibrateSigma | |
#' function for sampling intervals 1 and the estimate value for Sima computed | |
#' using the CalibrateSigmaOverlapping function for sampling inveral q. | |
#' This statistic should converge to zero. | |
#' | |
#' @inheritParams calibrateSigma | |
#' @return Md double :: The Md statistic defined by Lo and MacKinlay. |
NewerOlder