Limit plotting data
This commit is contained in:
parent
52d0ef1971
commit
93d4b74f5e
@ -38,23 +38,23 @@ pd.options.mode.chained_assignment = None # default='warn'
|
||||
load_dotenv()
|
||||
|
||||
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
|
||||
|
||||
def intelligent_loop_plots(sym, stk_data):
|
||||
# Only plot ones that are standing out meaning:
|
||||
# 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)
|
||||
def intelligent_loop_plots(sym : str, stk_data):
|
||||
"""calculated indicators
|
||||
|
||||
# symbol = ['AMZN', 'SPY', 'GOOG', 'BAC', 'BA', 'XLE', 'CTL', 'ATVI', 'JD',\
|
||||
# 'COST', 'HD', 'UBER', 'XOM', 'UAL', 'LUV', 'T', 'WMT']
|
||||
Args:
|
||||
sym (str): ticker
|
||||
stk_data (DataFrame): stock data
|
||||
|
||||
Returns:
|
||||
DataFrame: price
|
||||
DataFrame: volume
|
||||
DataFrame: macd
|
||||
DataFrame: rsi
|
||||
str: detected indicators
|
||||
"""
|
||||
price = stk_data["adjclose"]
|
||||
vol = stk_data["volume"]
|
||||
stk = security(sym, price, vol)
|
||||
@ -385,11 +385,15 @@ def update_graph(col_chosen):
|
||||
|
||||
sym = col_chosen.split()[0]
|
||||
end_date = dt.datetime.today()
|
||||
start_date = end_date - dt.timedelta(days = 365 * LB_YEAR)
|
||||
# plot_sd = end_date - dt.timedelta(days = 365 * plt_year)
|
||||
# plot_ed = end_date
|
||||
start_date = end_date - dt.timedelta(days = round(365 * LB_YEAR))
|
||||
days_to_drop = round(365 * (LB_YEAR-PLT_YEAR))
|
||||
days_to_drop = days_to_drop if days_to_drop > 0 else 0
|
||||
tmp = fetch_stk_data(sym, start_date) # cached function all
|
||||
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(
|
||||
rows=3,
|
||||
|
Loading…
x
Reference in New Issue
Block a user