Last active
August 29, 2015 14:08
-
-
Save caub/d0a35a162aad8c9f100d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from scipy import * | |
def sma(v, k): | |
weights = repeat(1.0,k)/k | |
return convolve(v, weights, 'valid') | |
def ema(v, k): | |
weights = exp(linspace(-1,0,k)) | |
weights /= weights.sum() | |
#print 'we: %s' % weights | |
#print 'c: %s' % convolve(v, weights) | |
return convolve(v, weights)[k-1:-(k-1)] | |
def rsi(v, k): | |
dUp, dDown = v.copy( ), v.copy( ) | |
dUp[ dUp < 0 ] = 0 | |
dDown[ dDown > 0 ] = 0 | |
RolUp = ema( dUp, k) | |
RolDown = ema( dDown, k) | |
# print dUp | |
# print RolUp | |
# print dDown | |
# print RolDown | |
RolDown *= -1.0 | |
rs = RolUp / RolDown | |
# print rs | |
return 100-100/(1+rs) | |
v = [1,.6,.2,-.1,-.4,-.5, -.5,-.5,0,-.2,.1,.15,.9,1.5,3] | |
delta=diff(v) | |
delta | |
print sma(delta, 3) | |
print ema(delta, 3) | |
print rsi(delta, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment