mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-09 17:11:05 +00:00
feat(Data): added new derived features + asset pairs for crypto tickers (#6)
This commit is contained in:
committed by
GitHub
parent
b0b0d5bbba
commit
3fec439c08
@@ -0,0 +1,29 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def STOK(close, low, high, n):
|
||||
STOK = ((close - low.rolling(n).min()) / (high.rolling(n).max() - low.rolling(n).min())) * 100
|
||||
return STOK
|
||||
|
||||
def STOD(close, low, high, n):
|
||||
STOK = ((close - low.rolling(n).min()) / (high.rolling(n).max() - low.rolling(n).min())) * 100
|
||||
STOD = STOK.rolling(3).mean()
|
||||
return STOD
|
||||
|
||||
def RSI(series, period):
|
||||
delta = series.diff().dropna()
|
||||
u=delta*0
|
||||
d = u.copy()
|
||||
u[delta > 0] = delta[delta > 0]
|
||||
d[delta < 0] = -delta[delta < 0]
|
||||
u[u.index[period-1]] = np.mean( u[:period] ) #first value is sum of avg gains u = u.drop(u.index[:(period-1)])
|
||||
d[d.index[period-1]] = np.mean( d[:period] ) #first value is sum of avg losses d = d.drop(d.index[:(period-1)])
|
||||
rs = u.ewm(com=period-1, adjust=False).mean() / \
|
||||
d.ewm(com=period-1, adjust=False).mean()
|
||||
return 100-100/(1+rs)
|
||||
|
||||
def ROC(df, n):
|
||||
M = df.diff(n - 1)
|
||||
N = df.shift(n - 1)
|
||||
ROC = pd.Series(((M / N) * 100), name = 'ROC_' + str(n))
|
||||
return ROC
|
||||
Reference in New Issue
Block a user