Last active
October 7, 2020 08:37
-
-
Save k1000/6ff976fca1cd1e973ec1c6722ca1d643 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
# FUNK from https://colab.research.google.com/drive/12rWn1enSZP6OTgYgRT1OYFhFnt7QFfIu#scrollTo=dwe_prwCn2HH | |
def moving_average(df, n): | |
MA = pd.Series(df['Close'].rolling(n, min_periods=n).mean(), name='MA_' + str(n)) | |
df = df.join(MA) | |
return df | |
def exponential_moving_average(df, n): | |
EMA = pd.Series(df['Close'].ewm(span=n, min_periods=n).mean(), name="EMA_" + str(n)) | |
df = df.join(EMA) | |
return df | |
def momentum(df, n): | |
M = pd.Series(df['Close'].diff(n), name="Momentum_"+str(n)) | |
df = df.join(M) | |
return df | |
def bollinger_bands(df, n): | |
MA = pd.Series(df['Close'].rolling(n, min_periods=n).mean()) | |
MSD = pd.Series(df['Close'].rolling(n, min_periods=n).std()) | |
b1 = 4 * MSD / MA | |
B1 = pd.Series(b1, name = "BollingerB_" + str(n)) | |
df = df.join(B1) | |
b2 = (df['Close'] - MA + 2 * MSD) / (4 * MSD) | |
B2 = pd.Series(b2, name='Bollinger%b_'+str(n)) | |
df = df.join(B2) | |
return df | |
def stochastic_oscillator(df ,n): | |
S0K = pd.Series((df['Close']- df['Low']) / (df['High']-df['Low']), name='S0k_' + str(n)) | |
df = df.join(S0K) | |
return df | |
def relative_strength_index(df, n): | |
delta = df['Close'].diff() | |
up = delta.clip(lower=0) | |
down = -1*delta.clip(upper=0) | |
ema_up = up.ewm(com=n, adjust=False).mean() | |
ema_down = down.ewm(com=n, adjust=False).mean() | |
rs = ema_up/ema_down | |
rsi = 100 - (100/(1 + rs)) | |
df['rsi_' + str(n)] = rsi | |
return df | |
def common_channel_index(df, n): | |
PP = (df['High'] + df['Low'] + df['Close']) / 3 | |
CCI = pd.Series((PP - PP.rolling(n, min_periods=n).mean()) / PP.rolling(n, min_periods=n).std(), name='CCI_' + str(n)) | |
df = df.join(CCI) | |
return df | |
def standart_deviation(df, n): | |
df = df.join(pd.Series(df['Close'].rolling(n, min_periods=n).std(), name='STD_' + str(n))) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment