Skip to content

Commit

Permalink
Update indicators.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Stell0 authored Nov 4, 2024
1 parent df7d863 commit eb9c193
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
LINEARREG_timeperiod = int(os.environ.get("LINEARREG_timeperiod",10))

def rsi(df,timeperiod=14,label="RSI",):
df[label] = ta.RSI(df['Close'], timeperiod=timeperiod)
df[label] = ta.RSI(df['Close'].to_numpy(), timeperiod=timeperiod)
return df

def sma(df,timeperiod=200,label="SMA"):
df[label] = ta.SMA(df['Close'], timeperiod=timeperiod)
return df

def linearreg(df,timeperiod=10):
df['LINEARREG'] = ta.LINEARREG(df['Close'], timeperiod=timeperiod) # b+m*(period-1)
df['LINEARREG_SLOPE'] = ta.LINEARREG_SLOPE(df['Close'], timeperiod=timeperiod) # m
df['LINEARREG_INTERCEPT'] = ta.LINEARREG_INTERCEPT(df['Close'], timeperiod=timeperiod) # b
df['LRFORECAST'] = df['LINEARREG_INTERCEPT'] + df['LINEARREG_SLOPE'] * timeperiod
df['LINEARREG'] = ta.LINEARREG(df['Close'].to_numpy(), timeperiod=timeperiod) # b+m*(period-1)
df['LINEARREG_SLOPE'] = ta.LINEARREG_SLOPE(df['Close'].to_numpy(), timeperiod=timeperiod) # m
df['LINEARREG_INTERCEPT'] = ta.LINEARREG_INTERCEPT(df['Close'].to_numpy(), timeperiod=timeperiod) # b
df['LRFORECAST'] = df['LINEARREG_INTERCEPT'].to_numpy() + df['LINEARREG_SLOPE'].to_numpy() * timeperiod
return df

def macd(df,fastperiod=12,slowperiod=26,signalperiod=9):
macd, macdsignal, macdhist = ta.MACD(df['Close'], fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod)
macd, macdsignal, macdhist = ta.MACD(df['Close'].to_numpy(), fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod)
df['MACD'] = macd
df['MACD_SIGNAL'] = macdsignal
df['MACD_HIST'] = macdhist
return df

def bb(df,timeperiod=20,nbdevup=2,nbdevdn=2,matype=0):
upperband, middleband, lowerband = ta.BBANDS(df['Close'], timeperiod=timeperiod, nbdevup=nbdevup, nbdevdn=nbdevdn, matype=matype)
upperband, middleband, lowerband = ta.BBANDS(df['Close'].to_numpy(), timeperiod=timeperiod, nbdevup=nbdevup, nbdevdn=nbdevdn, matype=matype)
df['BB_UPPER'] = upperband
df['BB_MIDDLE'] = middleband
df['BB_LOWER'] = lowerband
return df
return df

0 comments on commit eb9c193

Please sign in to comment.