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
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 | |
""" |
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
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 |
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
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. | |
""" | |
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
import numpy | |
import numpy.random as nrand | |
def vol(returns): | |
# Return the standard deviation of returns | |
return numpy.std(returns) | |
def beta(returns, market): |
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
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. | |
""" | |
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
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 |
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
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. | |
""" | |
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
""" | |
Note that this Gist uses functions made available in another Gist - | |
https://gist.github.com/StuartGordonReid/67a1ec4fbc8a84c0e856 | |
""" | |
def treynor_ratio(er, returns, market, rf): | |
return (er - rf) / beta(returns, market) | |
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
""" | |
Note that this Gist uses functions made available in another Gist - | |
https://gist.github.com/StuartGordonReid/67a1ec4fbc8a84c0e856 | |
""" | |
def excess_var(er, returns, rf, alpha): | |
return (er - rf) / var(returns, alpha) | |
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
""" | |
Note that this Gist uses functions made available in another Gist - | |
https://gist.github.com/StuartGordonReid/67a1ec4fbc8a84c0e856 | |
""" | |
def omega_ratio(er, returns, rf, target=0): | |
return (er - rf) / lpm(returns, target, 1) | |
OlderNewer