mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Add rsi to technical analysis
This commit is contained in:
@@ -55,8 +55,9 @@ def print_help(s_ticker, s_start, b_is_market_open):
|
||||
print(" sma simple moving average [daily]")
|
||||
print(" ema exponential moving average [daily]")
|
||||
print(" macd moving average convergence/divergence [daily]")
|
||||
print(" vwap volume weighted average price [intradaily]")
|
||||
print(" vwap volume weighted average price [intraday]")
|
||||
print(" stoch stochastic oscillator [daily]")
|
||||
print(" rsi relative strength index [daily]")
|
||||
|
||||
print("\nPrediction:")
|
||||
print(" ma")
|
||||
@@ -98,7 +99,7 @@ def main():
|
||||
|
||||
# Add list of arguments that the main parser accepts
|
||||
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers' ,'view', 'load', 'clear',
|
||||
'sma', 'ema', 'macd', 'vwap', 'stoch',
|
||||
'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi',
|
||||
'ratings'])
|
||||
|
||||
# Print first welcome message and help
|
||||
@@ -192,6 +193,11 @@ def main():
|
||||
smta.stoch(l_args, s_ticker, df_stock)
|
||||
continue
|
||||
|
||||
# ---------------------------------------------------- RSI ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'rsi':
|
||||
smta.rsi(l_args, s_ticker, df_stock)
|
||||
continue
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# ------------------------------------------------ PREDICTION --------------------------------------------------
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -62,8 +62,9 @@ def plot_ta(s_ticker, df_ta, s_ta):
|
||||
plt.title(f"{s_ta} on {s_ticker}")
|
||||
plt.xlim(df_ta.index[0], df_ta.index[-1])
|
||||
plt.xlabel('Time')
|
||||
plt.ylabel('Share Price ($)')
|
||||
plt.legend(df_ta.columns)
|
||||
#plt.ylabel('Share Price ($)')
|
||||
#if isinstance(df_ta, pd.DataFrame):
|
||||
# plt.legend(df_ta.columns)
|
||||
plt.grid(b=True, which='major', color='#666666', linestyle='-')
|
||||
plt.minorticks_on()
|
||||
plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2)
|
||||
|
||||
@@ -190,3 +190,33 @@ def stoch(l_args, s_ticker, df_stock):
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
# ----------------------------------------------------- RSI -----------------------------------------------------
|
||||
def rsi(l_args, s_ticker, df_stock):
|
||||
parser = argparse.ArgumentParser(prog='rsi',
|
||||
description=""" The Relative Strength Index (RSI) calculates a ratio of the
|
||||
recent upward price movements to the absolute price movement. The RSI ranges
|
||||
from 0 to 100. The RSI is interpreted as an overbought/oversold indicator when
|
||||
the value is over 70/below 30. You can also look for divergence with price. If
|
||||
the price is making new highs/lows, and the RSI is not, it indicates a reversal. """)
|
||||
|
||||
parser.add_argument('-p', "--timeperiod", action="store", dest="n_timeperiod", type=check_positive, default=60,
|
||||
help='The short period.')
|
||||
|
||||
try:
|
||||
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
|
||||
except SystemExit:
|
||||
print("")
|
||||
return
|
||||
|
||||
if l_unknown_args:
|
||||
print(f"The following args couldn't be interpreted: {l_unknown_args}")
|
||||
|
||||
try:
|
||||
df_ta = ta.rsi(df_stock['5. adjusted close'], time_period=ns_parser.n_timeperiod).dropna()
|
||||
|
||||
plot_ta(s_ticker, df_ta, f"{ns_parser.n_timeperiod} RSI")
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
Reference in New Issue
Block a user