first working commit

This commit is contained in:
tomgwang 2024-06-21 21:26:27 -07:00
parent c2d00ff69a
commit e34780c1fe
2 changed files with 15 additions and 15 deletions

View File

@ -661,24 +661,24 @@ def intelligent_loop_plots():
# init # init
plot_indicator = "[" plot_indicator = "["
print('{:5}: '.format(sym), end = '') # print('{:5}: '.format(sym), end = '')
# RSI outside window (over bought / over sold) # RSI outside window (over bought / over sold)
rsi_tail = rsi.tail(lb_trigger) rsi_tail = rsi.tail(lb_trigger)
if (rsi_tail[sym] >= 70).any() or (rsi_tail[sym] <= 30).any(): if (rsi_tail[sym] >= 70).any() or (rsi_tail[sym] <= 30).any():
print('--RSI', end = '') # print('--RSI', end = '')
plot_indicator += 'RSI, ' plot_indicator += 'RSI, '
# VoRSI outside window (over bought / over sold) # VoRSI outside window (over bought / over sold)
vorsi_tail = vorsi.tail(lb_trigger) vorsi_tail = vorsi.tail(lb_trigger)
if (vorsi_tail[sym] >= 70).any() or (vorsi_tail[sym] <= 30).any(): if (vorsi_tail[sym] >= 70).any() or (vorsi_tail[sym] <= 30).any():
print('--VoRSI', end = '') # print('--VoRSI', end = '')
plot_indicator += 'VoRSI, ' plot_indicator += 'VoRSI, '
# Normalized MACD histogram out of 3% range # Normalized MACD histogram out of 3% range
norm_hist_tail = abs(norm_hist.tail(lb_trigger)) norm_hist_tail = abs(norm_hist.tail(lb_trigger))
if (abs(norm_hist_tail[sym]) >= 0.02).any(): if (abs(norm_hist_tail[sym]) >= 0.02).any():
print('--MACD/R', end = '') # outside normal range # print('--MACD/R', end = '') # outside normal range
plot_indicator += 'MACD/R, ' plot_indicator += 'MACD/R, '
# MACD histogram zero crossing # MACD histogram zero crossing
@ -686,7 +686,7 @@ def intelligent_loop_plots():
macd_hist_sign = np.sign(macd_hist_tail) macd_hist_sign = np.sign(macd_hist_tail)
macd_hist_diff = macd_hist_sign.diff() macd_hist_diff = macd_hist_sign.diff()
if (abs(macd_hist_diff[sym]) > 1).any(): if (abs(macd_hist_diff[sym]) > 1).any():
print('--MACD', end = '') # zero crossing # print('--MACD', end = '') # zero crossing
plot_indicator += 'MACD, ' plot_indicator += 'MACD, '
# Stock price crosses SMA50 # Stock price crosses SMA50
@ -694,7 +694,7 @@ def intelligent_loop_plots():
sma50_cross_sign = np.sign(sma50_cross_tail) sma50_cross_sign = np.sign(sma50_cross_tail)
sma50_cross_diff = sma50_cross_sign.diff() sma50_cross_diff = sma50_cross_sign.diff()
if (abs(sma50_cross_diff[sym]) > 1).any(): if (abs(sma50_cross_diff[sym]) > 1).any():
print('--SMA50', end = '') # print('--SMA50', end = '')
plot_indicator += 'SMA50, ' plot_indicator += 'SMA50, '
# Death cross or golden cross - SMA50 vs SMA200 # Death cross or golden cross - SMA50 vs SMA200
@ -702,7 +702,7 @@ def intelligent_loop_plots():
sma_cross_sign = np.sign(sma_cross_tail) sma_cross_sign = np.sign(sma_cross_tail)
sma_cross_diff = sma_cross_sign.diff() sma_cross_diff = sma_cross_sign.diff()
if (abs(sma_cross_diff[sym]) > 1).any(): if (abs(sma_cross_diff[sym]) > 1).any():
print('--Golden/Death', end = '') # print('--Golden/Death', end = '')
plot_indicator += 'Golden/Death, ' plot_indicator += 'Golden/Death, '
# Price outside bollinger band or crossing # Price outside bollinger band or crossing
@ -712,7 +712,7 @@ def intelligent_loop_plots():
price_high = price_tail - bol_up_tail.values price_high = price_tail - bol_up_tail.values
price_low = price_tail - bol_low_tail.values price_low = price_tail - bol_low_tail.values
if (price_high[sym] >= 0).any() or (price_low[sym] <= 0).any(): if (price_high[sym] >= 0).any() or (price_low[sym] <= 0).any():
print('--Bollinger', end ='') # print('--Bollinger', end ='')
plot_indicator += 'Bollinger, ' plot_indicator += 'Bollinger, '
# Price cross 200 day moving average # Price cross 200 day moving average
@ -721,7 +721,7 @@ def intelligent_loop_plots():
sma200_cross_sign = np.sign(sma200_cross) sma200_cross_sign = np.sign(sma200_cross)
sma200_cross_diff = sma200_cross_sign.diff() sma200_cross_diff = sma200_cross_sign.diff()
if (abs(sma200_cross_diff[sym]) > 1).any(): if (abs(sma200_cross_diff[sym]) > 1).any():
print('--SMA200', end = '') # print('--SMA200', end = '')
plot_indicator += 'SMA200, ' plot_indicator += 'SMA200, '
# Large trading volume trigger # Large trading volume trigger
@ -729,10 +729,10 @@ def intelligent_loop_plots():
vol_mean = vol.tail(50).mean() vol_mean = vol.tail(50).mean()
vol_std = vol.tail(50).std() vol_std = vol.tail(50).std()
if ((volume_tail[sym] - vol_mean[sym] - 2*vol_std[sym]) > 0).any(): if ((volume_tail[sym] - vol_mean[sym] - 2*vol_std[sym]) > 0).any():
print('--HiVol', end = '') # print('--HiVol', end = '')
plot_indicator += "HiVol, " plot_indicator += "HiVol, "
print(f"-- {watchlist.loc[sym, 'Notes']}") # carriage return # print(f"-- {watchlist.loc[sym, 'Notes']}") # carriage return
plot_indicator += ']' plot_indicator += ']'
note_field = watchlist.loc[sym, 'Notes'].strip().lower() note_field = watchlist.loc[sym, 'Notes'].strip().lower()
if note_field != "watch" and ( note_field == "skip" or \ if note_field != "watch" and ( note_field == "skip" or \

View File

@ -82,13 +82,13 @@ def get_data_range(df, dates):
return df_range return df_range
def yf_download(symbols, start, end): def yf_download(symbols, start, end):
df = pd.DataFrame(columns = pd.MultiIndex(levels=[["Adj Close", "Volume"],[]], codes=[[],[]], names=["adjclose", "volume"])) df = pd.DataFrame(columns = pd.MultiIndex(levels=[["Adj Close", "Volume"],[]], codes=[[],[]], names=["param", "tick"]))
for sym in symbols: for sym in symbols:
# tmp = si.get_data(sym, start_date=start) # tmp = si.get_data(sym, start_date=start)
tmp = si.get_data(sym, start_date=start)[["adjclose", "volume"]] tmp = si.get_data(sym, start_date=start)[["adjclose", "volume"]]
tuples = list(zip(tmp.columns.values.tolist(), \ tmp.rename(columns={"adjclose": "Adj Close", "volume": "Volume"}, inplace=True)
[symbols[0]]*len(tmp.columns.values))) tmp.columns = pd.MultiIndex.from_product([list(tmp.columns)] + [[sym]], names=["param", "tick"])
tmp.columns = pd.MultiIndex.from_tuples(tuples, names=[None, None])
df = df.join(tmp, how='outer') df = df.join(tmp, how='outer')
return df return df