Last active
February 9, 2018 03:32
-
-
Save Pooh3Mobi/56fb786b3ca14d0297778da432821e96 to your computer and use it in GitHub Desktop.
Signal source for QuantX
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 _mavg_signal(data): | |
.... | |
# bollinger band %B day 20 | |
c = data["close_price_adj"].fillna(method='ffill') | |
m20 = c.rolling(window=20, center=False).mean() | |
s20 = c.rolling(window=20, center=False).std() | |
ub = m20 + s20 * 2 | |
lb = m20 - s20 * 2 | |
pb = (c - lb) / (ub - lb) | |
.... | |
return { | |
.... | |
"UpperBB:price":ub, | |
"LowerBB:price":lb, | |
"BB %B:ratio":pb, | |
.... | |
} |
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 macd(values, short_period, long_period, signal_period): | |
shorts = values.ewm(span=short_period).mean() | |
longs = values.ewm(span=long_period).mean() | |
_macd = shorts - longs | |
return _macd, _macd.ewm(span=signal_period).mean() |
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 rsi(data, period): | |
diff = data.diff(1) | |
pos = diff.clip_lower(0).ewm(alpha=1/period).mean() | |
neg = diff.clip_upper(0).ewm(alpha=1/period).mean() | |
return pos / (pos - neg) | |
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 _mavg_signal(data): | |
.... | |
close = data["close_price_adj"] | |
l14 = data["low_price_adj"].rolling(window=14).min() | |
h14 = data["high_price_adj"].rolling(window=14).max() | |
pk = 100 * ((close - l14) / (h14 - l14)) | |
pd = pk.rolling(window=3).mean() | |
.... | |
return { | |
.... | |
"%K:ratio": pk, | |
"%D:ratio": pd, | |
.... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment