Skip to content

Instantly share code, notes, and snippets.

@Slater-Victoroff
Slater-Victoroff / find_key.py
Created May 21, 2014 19:56
Automatic Key Finding
class MissingKeyException(Exception):
"""
If we can't figure out what the key is of an item being saved, we just say so.
Should probably make a better error message that says what we can figure out and what they can do about it.
"""
def __init__(self, data_structure):
self.ds = data_structure
@Slater-Victoroff
Slater-Victoroff / skeleton.py
Created May 21, 2014 19:08
Boto Decorator Skeleton
import json
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
class BotoSave(object):
def __init__(self, bucket, filename=None):
"""
@Slater-Victoroff
Slater-Victoroff / ideal.py
Created May 21, 2014 18:55
Boto Save Ideal Decorator
@BotoSave('bucketname')
def method():
return {<key>: <data>}
@Slater-Victoroff
Slater-Victoroff / credentials.py
Last active August 29, 2015 14:01
AWS Credentials
import os
CREDENTIALS = ['AWSAccessKeyId', 'AWSSecretKey']
def credentials(filename=None):
"""
Generally made for standard AWS export format. Turns conf file into python dict
If no filename is given, will attempt to read environment variables instead, then global variables
import json, os
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
CREDENTIALS = ['AWSAccessKeyId', 'AWSSecretKey']
class MissingCredentialsException(Exception):
def __init__(self, credentials_dict):
from zipline.algorithm import TradingAlgorithm
from zipline.transforms import MovingAverage
from zipline.utils.factory import load_from_yahoo
from zipline.finance.slippage import FixedSlippage
from zipline.finance.commission import PerShare
from datetime import datetime
import matplotlib.pyplot as plt
class DualMovingAverage(TradingAlgorithm):
@Slater-Victoroff
Slater-Victoroff / normalize.py
Created March 10, 2014 08:07
Normalization
def normalize(vector, span=(0,1)):
minimum, maximum = (np.min(vector), np.max(vector))
scaling = (span[1] - span[0]) / (maximum - minimum)
return ((vector - minimum) * scaling) + span[0]
@Slater-Victoroff
Slater-Victoroff / neural_net.py
Created March 10, 2014 08:02
Simple Neural Net
import numpy as np
def normalize(vector, span=(0,1)):
minimum, maximum = (np.min(vector), np.max(vector))
scaling = (span[1] - span[0]) / (maximum - minimum)
return ((vector - minimum) * scaling) + span[0]
class NeuralNet(object):
def __init__(self, layer_sizes=(10,50,20), threshold=0.5):
@Slater-Victoroff
Slater-Victoroff / transfer.py
Created March 10, 2014 07:33
Neural Transfer Function
import numpy as np
def transfer_function(input_vector, weight_matrix, threshold):
return np.dot(input_vector, weight_matrix) > threshold
@Slater-Victoroff
Slater-Victoroff / and.py
Created March 10, 2014 06:58
Neural AND Gate
import numpy as np
def neural_logic_gate(input_vector, weight_matrix=[0.5, 0.5], threshold=0.75):
return np.dot(input_vector, weights) > threshold