Skip to content

Instantly share code, notes, and snippets.

Stuart Gordon Reid StuartGordonReid

View GitHub Profile
@StuartGordonReid
StuartGordonReid / AntNeighbourhoodFunction.py
Last active Aug 6, 2016
Ant Colony Neighbourhood Function
View AntNeighbourhoodFunction.py
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
"""
View InstallEMH.R
library(devtools)
devtools::install_github(repo="stuartgordonreid/emh")
View emh.R
results <- emh::is_random(my.zoo.object)
emh::plot_results(results)
View(results)
View AntColonyOptimizationGist.py
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
View BettingStrategy.R
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)
View RobustnessCheck.R
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
View CompressionTest.R
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 / RandomExcursionsVariant.py
Created Sep 13, 2015
Python implementation of the NIST random excursions variant cryptographic test for randomness
View RandomExcursionsVariant.py
def random_excursions_variant(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 total number of times that a particular state is visited (i.e., occurs) in a
cumulative sum random walk. The purpose of this test is to detect deviations from the expected number of visits
to various states in the random walk. This test is actually a series of eighteen tests (and conclusions), one
test and conclusion for each of the states: -9, -8, …, -1 and +1, +2, …, +9.
@StuartGordonReid
StuartGordonReid / RandomExcursions.py
Created Sep 13, 2015
Python implementation of the random excursions NIST cryptographic tests for randomness
View RandomExcursions.py
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 Sep 13, 2015
Python implementation of the cumulative sums NIST cryptographic test for randomness
View CumulativeSums.py
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
You can’t perform that action at this time.