Limit plotting data

This commit is contained in:
George 2024-10-07 11:46:46 -07:00
parent 52d0ef1971
commit 93d4b74f5e

View File

@ -38,23 +38,23 @@ pd.options.mode.chained_assignment = None # default='warn'
load_dotenv() load_dotenv()
LB_YEAR = 3 # years of stock data to retrieve LB_YEAR = 3 # years of stock data to retrieve
# PLT_YEAR = 2 # number of years data to plot PLT_YEAR = 2.7 # number of years data to plot
LB_TRIGGER = 5 # days to lookback for triggering events LB_TRIGGER = 5 # days to lookback for triggering events
def intelligent_loop_plots(sym, stk_data): def intelligent_loop_plots(sym : str, stk_data):
# Only plot ones that are standing out meaning: """calculated indicators
# 1. outside of bollinger bands or recently crossed over (within 9 days)
# 2. RSI above 70 or below 30
# 3. VoRSI above 70 or below 30
# 4. when normalized MACD hist (by dividing slower moving average) is
# above 2% or below -2%.
# 5. near golden cross or death cross
# 6. price cross (near) 200 day moving average
# 7. MACD histogram zero crossing (bullish or bearish)
# symbol = ['AMZN', 'SPY', 'GOOG', 'BAC', 'BA', 'XLE', 'CTL', 'ATVI', 'JD',\ Args:
# 'COST', 'HD', 'UBER', 'XOM', 'UAL', 'LUV', 'T', 'WMT'] sym (str): ticker
stk_data (DataFrame): stock data
Returns:
DataFrame: price
DataFrame: volume
DataFrame: macd
DataFrame: rsi
str: detected indicators
"""
price = stk_data["adjclose"] price = stk_data["adjclose"]
vol = stk_data["volume"] vol = stk_data["volume"]
stk = security(sym, price, vol) stk = security(sym, price, vol)
@ -385,11 +385,15 @@ def update_graph(col_chosen):
sym = col_chosen.split()[0] sym = col_chosen.split()[0]
end_date = dt.datetime.today() end_date = dt.datetime.today()
start_date = end_date - dt.timedelta(days = 365 * LB_YEAR) start_date = end_date - dt.timedelta(days = round(365 * LB_YEAR))
# plot_sd = end_date - dt.timedelta(days = 365 * plt_year) days_to_drop = round(365 * (LB_YEAR-PLT_YEAR))
# plot_ed = end_date days_to_drop = days_to_drop if days_to_drop > 0 else 0
tmp = fetch_stk_data(sym, start_date) # cached function all tmp = fetch_stk_data(sym, start_date) # cached function all
data, vol, macd, rsi, plot_ind = intelligent_loop_plots(sym, tmp) data, vol, macd, rsi, plot_ind = intelligent_loop_plots(sym, tmp)
data.drop(data.index[:days_to_drop], inplace=True)
vol.drop(vol.index[:days_to_drop], inplace=True)
macd.drop(macd.index[:days_to_drop], inplace=True)
rsi.drop(rsi.index[:days_to_drop], inplace=True)
fig = make_subplots( fig = make_subplots(
rows=3, rows=3,