Instantly share code, notes, and snippets.

# Stuart Gordon ReidStuartGordonReid

• Sort options
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 """
Created Jun 8, 2015
This is a Gist of the repository https://github.com/StuartGordonReid/Ant-Colony-Optimization
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
Last active Sep 20, 2019
 import math import numpy import numpy.random as nrand """ Note - for some of the metrics the absolute value is returns. This is because if the risk (loss) is higher we want to discount the expected excess return from the portfolio by a higher amount. Therefore risk should be positive. """
Created Jun 12, 2015
Volatility Risk Metrics
View Volatility.py
 import numpy import numpy.random as nrand def vol(returns): # Return the standard deviation of returns return numpy.std(returns) def beta(returns, market):
Created Jun 12, 2015
Value at Risk Gist
View ValueAtRisk.py
 import numpy import numpy.random as nrand """ Note - for some of the metrics the absolute value is returns. This is because if the risk (loss) is higher we want to discount the expected excess return from the portfolio by a higher amount. Therefore risk should be positive. """
Created Jun 12, 2015
Lower and Higher Partial Moments
View PartialMoments.py
 import numpy import numpy.random as nrand def lpm(returns, threshold, order): # This method returns a lower partial moment of the returns # Create an array he same length as returns containing the minimum return threshold threshold_array = numpy.empty(len(returns)) threshold_array.fill(threshold) # Calculate the difference between the threshold and the returns
Last active Jul 26, 2019
View MaximumDrawdown.py
 import numpy import numpy.random as nrand """ Note - for some of the metrics the absolute value is returns. This is because if the risk (loss) is higher we want to discount the expected excess return from the portfolio by a higher amount. Therefore risk should be positive. """
Created Jun 12, 2015
Risk adjusted returns based on volatility