mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-05-06 22:12:12 +08:00
Add stoch to technical analysis
This commit is contained in:
@@ -52,10 +52,11 @@ def print_help(s_ticker, s_start, b_is_market_open):
|
||||
print(" ratings company ratings from strong sell to strong buy")
|
||||
|
||||
print("\nTechnical Analysis:")
|
||||
print(" sma simple moving average")
|
||||
print(" ema exponential moving average")
|
||||
print(" macd moving average convergence/divergence")
|
||||
print(" vwap volume weighted average price")
|
||||
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(" stoch stochastic oscillator [daily]")
|
||||
|
||||
print("\nPrediction:")
|
||||
print(" ma")
|
||||
@@ -96,7 +97,9 @@ def main():
|
||||
main_parser = argparse.ArgumentParser(prog='stock_market_bot', add_help=False)
|
||||
|
||||
# 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', 'ratings'])
|
||||
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers' ,'view', 'load', 'clear',
|
||||
'sma', 'ema', 'macd', 'vwap', 'stoch',
|
||||
'ratings'])
|
||||
|
||||
# Print first welcome message and help
|
||||
print("\nWelcome to Didier's Stock Market Bot\n")
|
||||
@@ -158,6 +161,8 @@ def main():
|
||||
smfa.ratings(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
#from alpha_vantage.fundamentaldata import FundamentalData
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# -------------------------------------------- TECHNICAL ANALYSIS ----------------------------------------------
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
@@ -181,6 +186,11 @@ def main():
|
||||
elif ns_known_args.cmd == 'vwap':
|
||||
smta.vwap(l_args, s_ticker, s_start)
|
||||
continue
|
||||
|
||||
# ---------------------------------------------------- STOCH ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'stoch':
|
||||
smta.stoch(l_args, s_ticker, df_stock)
|
||||
continue
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# ------------------------------------------------ PREDICTION --------------------------------------------------
|
||||
|
||||
@@ -131,7 +131,7 @@ def vwap(l_args, s_ticker, s_start):
|
||||
try:
|
||||
ts = TimeSeries(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas')
|
||||
s_interval = str(ns_parser.n_interval)+'min'
|
||||
df_stock, d_stock_metadata = ts.get_intraday(symbol=s_ticker, outputsize='full', interval=s_interval)
|
||||
df_stock, d_stock_metadata = ts.get_intraday(symbol=s_ticker, outputsize='full', interval=s_interval)
|
||||
|
||||
if s_start:
|
||||
df_stock = df_stock[s_start:]
|
||||
@@ -145,4 +145,48 @@ def vwap(l_args, s_ticker, s_start):
|
||||
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
return
|
||||
|
||||
|
||||
# ----------------------------------------------------- STOCH -----------------------------------------------------
|
||||
def stoch(l_args, s_ticker, df_stock):
|
||||
parser = argparse.ArgumentParser(prog='stoch',
|
||||
description=""" The Stochastic Oscillator measures where the close is in relation
|
||||
to the recent trading range. The values range from zero to 100. %D values over 75
|
||||
indicate an overbought condition; values under 25 indicate an oversold condition.
|
||||
When the Fast %D crosses above the Slow %D, it is a buy signal; when it crosses
|
||||
below, it is a sell signal. The Raw %K is generally considered too erratic to use
|
||||
for crossover signals. """)
|
||||
|
||||
parser.add_argument('-k', "--fastkperiod", action="store", dest="n_fastkperiod", type=check_positive, default=5,
|
||||
help='The short period.')
|
||||
parser.add_argument('-d', "--slowdperiod", action="store", dest="n_slowdperiod", type=check_positive, default=3,
|
||||
help='The short period.')
|
||||
parser.add_argument("--slowkperiod", action="store", dest="n_slowkperiod", type=check_positive, default=3,
|
||||
help='The short period.')
|
||||
parser.add_argument("--slowkmatype", action="store", dest="n_slowkmatype", type=check_positive, default=0,
|
||||
help='The short period.')
|
||||
parser.add_argument("--slowdmatype", action="store", dest="n_slowdmatype", type=check_positive, default=0,
|
||||
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.stoch(high=df_stock['2. high'],
|
||||
low=df_stock['3. low'],
|
||||
close=df_stock['4. close'],
|
||||
k=ns_parser.n_fastkperiod,
|
||||
d=ns_parser.n_slowdperiod,
|
||||
smooth_k=ns_parser.n_slowkperiod).dropna()
|
||||
|
||||
plot_ta(s_ticker, df_ta, f"SlowK{ns_parser.n_slowkperiod}-SlowD{ns_parser.n_slowdperiod} STOCH")
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user