QuantumLearner commited on
Commit
f712ed8
·
verified ·
1 Parent(s): 6b78629

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -285,6 +285,7 @@ st.title('Technical Analysis Indicators')
285
 
286
  # Sidebar for method selection
287
  with st.sidebar.expander("Method Selection", expanded=True):
 
288
  selected = st.radio("Select Indicator", ["Rolling Z-Score", "Rate of Change (ROC)", "Stochastic Oscillator", "Relative Strength Index (RSI)", "MACD", "Bollinger Bands", "K Reversal", "Awesome Oscillator", "Williams %R", "Aroon Oscillator"])
289
 
290
  # Sidebar for "How to Use" instructions specific to the selected method
@@ -374,9 +375,10 @@ with st.sidebar.expander("How to Use", expanded=False):
374
 
375
  # Sidebar for input parameters inside an expander
376
  with st.sidebar.expander("Input Parameters", expanded=True):
377
- ticker = st.text_input('Enter Stock or Crypto Symbol (e.g., AAPL or BTC-USD)', 'AAPL')
378
- start_date = st.date_input('Start Date', pd.to_datetime('2019-01-01'))
379
- end_date = st.date_input('End Date', pd.to_datetime(pd.Timestamp.now().date() + pd.Timedelta(days=1)))
 
380
 
381
  # Fetch data
382
  if 'data' not in st.session_state or st.sidebar.button('Fetch Data'):
@@ -409,9 +411,9 @@ if selected == "Rolling Z-Score":
409
  - **Oversold Condition:** Z-score below a set threshold (e.g., -2.0) suggests the stock may be oversold.
410
  """)
411
 
412
- periods = st.sidebar.multiselect('Periods to Compare', options=[10, 20, 30, 40, 50], default=[20])
413
- z_thresh = st.sidebar.slider('Z-Score Threshold', min_value=0.5, max_value=3.0, value=2.0, step=0.1)
414
- n_days = st.sidebar.number_input('Number of Days', min_value=1, value=10)
415
  fig = plot_z_score(close_prices, periods, z_thresh, n_days)
416
  st.plotly_chart(fig)
417
 
@@ -434,7 +436,7 @@ elif selected == "Rate of Change (ROC)":
434
  - **Sell Signal:** Occurs when the ROC crosses below zero, indicating potential downward momentum.
435
  """)
436
 
437
- n_days = st.sidebar.number_input('Number of Days', min_value=1, value=14)
438
  fig = plot_roc(close_prices, n_days)
439
  st.plotly_chart(fig)
440
 
@@ -458,8 +460,8 @@ elif selected == "Stochastic Oscillator":
458
  - **Sell Signal:** Occurs when %K crosses below a set threshold (e.g., 80), indicating potential downward momentum.
459
  """)
460
 
461
- buy_thresh = st.sidebar.slider('Stochastic Buy Threshold', min_value=0, max_value=100, value=5)
462
- sell_thresh = st.sidebar.slider('Stochastic Sell Threshold', min_value=0, max_value=100, value=95)
463
  fig = plot_stochastic_oscillator(data, buy_thresh, sell_thresh)
464
  st.plotly_chart(fig)
465
 
@@ -483,8 +485,8 @@ elif selected == "Relative Strength Index (RSI)":
483
  - **Sell Signal:** Occurs when the RSI crosses above a set threshold (e.g., 70), indicating the stock may be overbought.
484
  """)
485
 
486
- buy_thresh = st.sidebar.slider('RSI Buy Threshold', min_value=0, max_value=100, value=30)
487
- sell_thresh = st.sidebar.slider('RSI Sell Threshold', min_value=0, max_value=100, value=70)
488
  fig = plot_rsi(close_prices, buy_thresh, sell_thresh)
489
  st.plotly_chart(fig)
490
 
@@ -559,9 +561,9 @@ elif selected == "K Reversal":
559
  - **Sell Signal:** Occurs when the K value crosses above a set threshold (e.g., 80), indicating the stock may be overbought.
560
  """)
561
 
562
- k_period = st.sidebar.number_input('K Reversal Period', min_value=1, value=14)
563
- k_buy_thresh = st.sidebar.slider('K Reversal Buy Threshold', min_value=0.0, max_value=100.0, value=10.0)
564
- k_sell_thresh = st.sidebar.slider('K Reversal Sell Threshold', min_value=0.0, max_value=100.0, value=90.0)
565
  fig = plot_k_reversal(data, k_period, k_buy_thresh, k_sell_thresh)
566
  st.plotly_chart(fig)
567
 
@@ -593,9 +595,9 @@ elif selected == "Awesome Oscillator":
593
  - **Sell Signal:** Occurs when the AO crosses below the signal line, indicating potential downward momentum.
594
  """)
595
 
596
- signal_period = st.sidebar.number_input('Signal Line Period', min_value=1, value=9)
597
- ao_buy_thresh = st.sidebar.slider('AO Buy Threshold', min_value=-100.0, max_value=100.0, value=0.0)
598
- ao_sell_thresh = st.sidebar.slider('AO Sell Threshold', min_value=-100.0, max_value=100.0, value=0.0)
599
  fig = plot_awesome_oscillator(data, signal_period, ao_buy_thresh, ao_sell_thresh)
600
  st.plotly_chart(fig)
601
 
@@ -619,9 +621,9 @@ elif selected == "Williams %R":
619
  - **Sell Signal:** Occurs when the Williams %R crosses above a set threshold (e.g., -20), indicating the stock may be overbought.
620
  """)
621
 
622
- williams_r_period = st.sidebar.number_input('Look-back Period', min_value=1, value=14)
623
- williams_r_buy_thresh = st.sidebar.slider('Williams %R Buy Threshold', min_value=-100.0, max_value=0.0, value=-90.0)
624
- williams_r_sell_thresh = st.sidebar.slider('Williams %R Sell Threshold', min_value=-100.0, max_value=0.0, value=-10.0)
625
  fig = plot_williams_r(data, williams_r_period, williams_r_buy_thresh, williams_r_sell_thresh)
626
  st.plotly_chart(fig)
627
 
@@ -657,13 +659,14 @@ elif selected == "Aroon Oscillator":
657
  - **Sell Signal:** Occurs when the Aroon Oscillator crosses below zero, indicating a potential downward trend.
658
  """)
659
 
660
- aroon_period = st.sidebar.number_input('Look-back Period', min_value=1, value=25)
661
  aroon_osc = aroon_oscillator(data, aroon_period)
662
  buy_signals = (aroon_osc > 0) & (aroon_osc.shift(1) <= 0)
663
  sell_signals = (aroon_osc < 0) & (aroon_osc.shift(1) >= 0)
664
  fig = plot_aroon(data, aroon_osc, buy_signals, sell_signals)
665
  st.plotly_chart(fig)
666
 
 
667
  hide_streamlit_style = """
668
  <style>
669
  #MainMenu {visibility: hidden;}
 
285
 
286
  # Sidebar for method selection
287
  with st.sidebar.expander("Method Selection", expanded=True):
288
+ st.write("Select an indicator to analyze the stock or crypto data.")
289
  selected = st.radio("Select Indicator", ["Rolling Z-Score", "Rate of Change (ROC)", "Stochastic Oscillator", "Relative Strength Index (RSI)", "MACD", "Bollinger Bands", "K Reversal", "Awesome Oscillator", "Williams %R", "Aroon Oscillator"])
290
 
291
  # Sidebar for "How to Use" instructions specific to the selected method
 
375
 
376
  # Sidebar for input parameters inside an expander
377
  with st.sidebar.expander("Input Parameters", expanded=True):
378
+ st.write("Set the parameters for data fetching and analysis.")
379
+ ticker = st.text_input('Enter Stock or Crypto Symbol (e.g., AAPL or BTC-USD)', 'AAPL', help="Enter the ticker symbol for the stock or cryptocurrency you want to analyze.")
380
+ start_date = st.date_input('Start Date', pd.to_datetime('2019-01-01'), help="Select the start date for the data range.")
381
+ end_date = st.date_input('End Date', pd.to_datetime(pd.Timestamp.now().date() + pd.Timedelta(days=1)), help="Select the end date for the data range.")
382
 
383
  # Fetch data
384
  if 'data' not in st.session_state or st.sidebar.button('Fetch Data'):
 
411
  - **Oversold Condition:** Z-score below a set threshold (e.g., -2.0) suggests the stock may be oversold.
412
  """)
413
 
414
+ periods = st.sidebar.multiselect('Periods to Compare', options=[10, 20, 30, 40, 50], default=[20], help="Select multiple periods to compare the rolling z-scores.")
415
+ z_thresh = st.sidebar.slider('Z-Score Threshold', min_value=0.5, max_value=3.0, value=2.0, step=0.1, help="Set the z-score threshold for identifying overbought and oversold conditions.")
416
+ n_days = st.sidebar.number_input('Number of Days', min_value=1, value=10, help="Set the number of days to shift for future price comparison.")
417
  fig = plot_z_score(close_prices, periods, z_thresh, n_days)
418
  st.plotly_chart(fig)
419
 
 
436
  - **Sell Signal:** Occurs when the ROC crosses below zero, indicating potential downward momentum.
437
  """)
438
 
439
+ n_days = st.sidebar.number_input('Number of Days', min_value=1, value=14, help="Set the number of days for the ROC calculation.")
440
  fig = plot_roc(close_prices, n_days)
441
  st.plotly_chart(fig)
442
 
 
460
  - **Sell Signal:** Occurs when %K crosses below a set threshold (e.g., 80), indicating potential downward momentum.
461
  """)
462
 
463
+ buy_thresh = st.sidebar.slider('Stochastic Buy Threshold', min_value=0, max_value=100, value=5, help="Set the threshold for generating buy signals using the Stochastic Oscillator.")
464
+ sell_thresh = st.sidebar.slider('Stochastic Sell Threshold', min_value=0, max_value=100, value=95, help="Set the threshold for generating sell signals using the Stochastic Oscillator.")
465
  fig = plot_stochastic_oscillator(data, buy_thresh, sell_thresh)
466
  st.plotly_chart(fig)
467
 
 
485
  - **Sell Signal:** Occurs when the RSI crosses above a set threshold (e.g., 70), indicating the stock may be overbought.
486
  """)
487
 
488
+ buy_thresh = st.sidebar.slider('RSI Buy Threshold', min_value=0, max_value=100, value=30, help="Set the RSI threshold for generating buy signals.")
489
+ sell_thresh = st.sidebar.slider('RSI Sell Threshold', min_value=0, max_value=100, value=70, help="Set the RSI threshold for generating sell signals.")
490
  fig = plot_rsi(close_prices, buy_thresh, sell_thresh)
491
  st.plotly_chart(fig)
492
 
 
561
  - **Sell Signal:** Occurs when the K value crosses above a set threshold (e.g., 80), indicating the stock may be overbought.
562
  """)
563
 
564
+ k_period = st.sidebar.number_input('K Reversal Period', min_value=1, value=14, help="Set the period for calculating the K Reversal.")
565
+ k_buy_thresh = st.sidebar.slider('K Reversal Buy Threshold', min_value=0.0, max_value=100.0, value=10.0, help="Set the threshold for generating buy signals using the K Reversal indicator.")
566
+ k_sell_thresh = st.sidebar.slider('K Reversal Sell Threshold', min_value=0.0, max_value=100.0, value=90.0, help="Set the threshold for generating sell signals using the K Reversal indicator.")
567
  fig = plot_k_reversal(data, k_period, k_buy_thresh, k_sell_thresh)
568
  st.plotly_chart(fig)
569
 
 
595
  - **Sell Signal:** Occurs when the AO crosses below the signal line, indicating potential downward momentum.
596
  """)
597
 
598
+ signal_period = st.sidebar.number_input('Signal Line Period', min_value=1, value=9, help="Set the period for the signal line in the Awesome Oscillator.")
599
+ ao_buy_thresh = st.sidebar.slider('AO Buy Threshold', min_value=-100.0, max_value=100.0, value=0.0, help="Set the threshold for generating buy signals using the Awesome Oscillator.")
600
+ ao_sell_thresh = st.sidebar.slider('AO Sell Threshold', min_value=-100.0, max_value=100.0, value=0.0, help="Set the threshold for generating sell signals using the Awesome Oscillator.")
601
  fig = plot_awesome_oscillator(data, signal_period, ao_buy_thresh, ao_sell_thresh)
602
  st.plotly_chart(fig)
603
 
 
621
  - **Sell Signal:** Occurs when the Williams %R crosses above a set threshold (e.g., -20), indicating the stock may be overbought.
622
  """)
623
 
624
+ williams_r_period = st.sidebar.number_input('Look-back Period', min_value=1, value=14, help="Set the look-back period for the Williams %R calculation.")
625
+ williams_r_buy_thresh = st.sidebar.slider('Williams %R Buy Threshold', min_value=-100.0, max_value=0.0, value=-90.0, help="Set the threshold for generating buy signals using Williams %R.")
626
+ williams_r_sell_thresh = st.sidebar.slider('Williams %R Sell Threshold', min_value=-100.0, max_value=0.0, value=-10.0, help="Set the threshold for generating sell signals using Williams %R.")
627
  fig = plot_williams_r(data, williams_r_period, williams_r_buy_thresh, williams_r_sell_thresh)
628
  st.plotly_chart(fig)
629
 
 
659
  - **Sell Signal:** Occurs when the Aroon Oscillator crosses below zero, indicating a potential downward trend.
660
  """)
661
 
662
+ aroon_period = st.sidebar.number_input('Look-back Period', min_value=1, value=25, help="Set the look-back period for the Aroon Oscillator calculation.")
663
  aroon_osc = aroon_oscillator(data, aroon_period)
664
  buy_signals = (aroon_osc > 0) & (aroon_osc.shift(1) <= 0)
665
  sell_signals = (aroon_osc < 0) & (aroon_osc.shift(1) >= 0)
666
  fig = plot_aroon(data, aroon_osc, buy_signals, sell_signals)
667
  st.plotly_chart(fig)
668
 
669
+ # Hide the default Streamlit menu and footer
670
  hide_streamlit_style = """
671
  <style>
672
  #MainMenu {visibility: hidden;}