Skip to content

Instantly share code, notes, and snippets.

View StuartGordonReid's full-sized avatar

Stuart Gordon Reid StuartGordonReid

View GitHub Profile
@StuartGordonReid
StuartGordonReid / AntNeighbourhoodFunction.py
Last active August 6, 2016 12:06
Ant Colony Neighbourhood Function
def get_probability(self, d, y, x, n, c):
"""
This gets the probability of drop / pickup for any given Datum, d
:param d: the datum
:param x: the x location of the datum / ant carrying datum
:param y: the y location of the datum / ant carrying datum
:param n: the size of the neighbourhood function
:param c: constant for convergence control
:return: the probability of
"""
library(devtools)
devtools::install_github(repo="stuartgordonreid/emh")
results <- emh::is_random(my.zoo.object)
emh::plot_results(results)
View(results)
import os
import math
import time
import numpy
import pandas
import random
import matplotlib
import numpy.random as nrand
import matplotlib.pylab as plt
from sklearn.preprocessing import normalize
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)
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
@StuartGordonReid
StuartGordonReid / CompressionTest.R
Created April 16, 2016 20:17
Compression Test
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)
@StuartGordonReid
StuartGordonReid / RandomExcursions.py
Created September 13, 2015 13:12
Python implementation of the random excursions NIST cryptographic tests for randomness
def random_excursions(self, bin_data):
"""
Note that this description is taken from the NIST documentation [1]
[1] http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf
The focus of this test is the number of cycles having exactly K visits in a cumulative sum random walk. The
cumulative sum random walk is derived from partial sums after the (0,1) sequence is transferred to the
appropriate (-1, +1) sequence. A cycle of a random walk consists of a sequence of steps of unit length taken at
random that begin at and return to the origin. The purpose of this test is to determine if the number of visits
to a particular state within a cycle deviates from what one would expect for a random sequence. This test is
@StuartGordonReid
StuartGordonReid / CumulativeSums.py
Created September 13, 2015 13:10
Python implementation of the cumulative sums NIST cryptographic test for randomness
def cumulative_sums(self, bin_data: str, method="forward"):
"""
Note that this description is taken from the NIST documentation [1]
[1] http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf
The focus of this test is the maximal excursion (from zero) of the random walk defined by the cumulative sum of
adjusted (-1, +1) digits in the sequence. The purpose of the test is to determine whether the cumulative sum of
the partial sequences occurring in the tested sequence is too large or too small relative to the expected
behavior of that cumulative sum for random sequences. This cumulative sum may be considered as a random walk.
For a random sequence, the excursions of the random walk should be near zero. For certain types of non-random
@StuartGordonReid
StuartGordonReid / Universal.py
Created August 25, 2015 16:03
Python implementation of the Universal cryptographic test for randomness
def universal(self, bin_data: str):
"""
Note that this description is taken from the NIST documentation [1]
[1] http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf
The focus of this test is the number of bits between matching patterns (a measure that is related to the
length of a compressed sequence). The purpose of the test is to detect whether or not the sequence can be
significantly compressed without loss of information. A significantly compressible sequence is considered
to be non-random. **This test is always skipped because the requirements on the lengths of the binary
strings are too high i.e. there have not been enough trading days to meet the requirements.