Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -288,7 +288,92 @@ st.title('Technical Analysis Indicators')
|
|
| 288 |
with st.sidebar.expander("Method Selection", expanded=True):
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
with st.sidebar.expander("Input Parameters", expanded=True):
|
| 293 |
ticker = st.text_input('Enter Stock or Crypto Symbol (e.g., AAPL or BTC-USD)', 'AAPL')
|
| 294 |
start_date = st.date_input('Start Date', pd.to_datetime('2019-01-01'))
|
|
@@ -301,24 +386,13 @@ if 'data' not in st.session_state or st.sidebar.button('Fetch Data'):
|
|
| 301 |
data = st.session_state.data
|
| 302 |
close_prices = data['Close']
|
| 303 |
|
| 304 |
-
# Expander for "How to" section
|
| 305 |
-
with st.expander("How to Use This App", expanded=False):
|
| 306 |
-
st.markdown("""
|
| 307 |
-
1. Use the sidebar to select an indicator and input parameters.
|
| 308 |
-
2. Enter the stock or cryptocurrency symbol (e.g., 'AAPL' for Apple or 'BTC-USD' for Bitcoin).
|
| 309 |
-
3. Choose the date range for the data.
|
| 310 |
-
4. Click 'Fetch Data' to load and visualize the data.
|
| 311 |
-
5. Use the parameter settings for each method to fine-tune the analysis.
|
| 312 |
-
""")
|
| 313 |
-
|
| 314 |
# Display results based on the selected method
|
| 315 |
if selected == "Rolling Z-Score":
|
|
|
|
|
|
|
|
|
|
| 316 |
with st.expander("Formula and Method Description", expanded=False):
|
| 317 |
st.markdown("""
|
| 318 |
-
### Rolling Z-Score
|
| 319 |
-
|
| 320 |
-
The rolling z-score method identifies overbought and oversold conditions by standardizing stock prices over different periods.
|
| 321 |
-
|
| 322 |
**How it Works:**
|
| 323 |
|
| 324 |
1. **Calculate Rolling Mean and Standard Deviation:**
|
|
@@ -334,16 +408,6 @@ if selected == "Rolling Z-Score":
|
|
| 334 |
3. **Identify Signals:**
|
| 335 |
- **Overbought Condition:** Z-score above a set threshold (e.g., 2.0) suggests the stock may be overbought.
|
| 336 |
- **Oversold Condition:** Z-score below a set threshold (e.g., -2.0) suggests the stock may be oversold.
|
| 337 |
-
|
| 338 |
-
**How to Use:**
|
| 339 |
-
1. Enter the stock ticker, start date, and end date.
|
| 340 |
-
2. Set the number of days for the z-score calculation.
|
| 341 |
-
3. Set the z-score threshold.
|
| 342 |
-
4. Click 'Fetch Data' to load the stock data.
|
| 343 |
-
5. The chart will display the rolling z-scores and highlight buy/sell signals based on the thresholds.
|
| 344 |
-
|
| 345 |
-
**Results:**
|
| 346 |
-
The chart shows the close prices with highlighted buy/sell signals and their correctness percentage over a specified period.
|
| 347 |
""")
|
| 348 |
|
| 349 |
periods = st.sidebar.multiselect('Periods to Compare', options=[10, 20, 30, 40, 50], default=[20])
|
|
@@ -353,10 +417,11 @@ if selected == "Rolling Z-Score":
|
|
| 353 |
st.plotly_chart(fig)
|
| 354 |
|
| 355 |
elif selected == "Rate of Change (ROC)":
|
|
|
|
|
|
|
|
|
|
| 356 |
with st.expander("Formula and Method Description", expanded=False):
|
| 357 |
st.markdown("""
|
| 358 |
-
### Rate of Change (ROC)
|
| 359 |
-
The Rate of Change (ROC) method measures the percentage change in stock prices over a specified period. It helps identify momentum and potential reversal points in the stock price.
|
| 360 |
**How it Works:**
|
| 361 |
1. **Calculate ROC:**
|
| 362 |
- For each day, calculate the ROC using the formula:
|
|
@@ -368,13 +433,6 @@ elif selected == "Rate of Change (ROC)":
|
|
| 368 |
2. **Identify Signals:**
|
| 369 |
- **Buy Signal:** Occurs when the ROC crosses above zero, indicating potential upward momentum.
|
| 370 |
- **Sell Signal:** Occurs when the ROC crosses below zero, indicating potential downward momentum.
|
| 371 |
-
**How to Use:**
|
| 372 |
-
1. Enter the stock ticker, start date, and end date.
|
| 373 |
-
2. Set the number of days for the ROC calculation.
|
| 374 |
-
3. Click 'Fetch Data' to load the stock data.
|
| 375 |
-
4. The chart will display the ROC and highlight buy/sell signals based on the ROC crossing zero.
|
| 376 |
-
**Results:**
|
| 377 |
-
The chart shows the stock prices with highlighted buy/sell signals based on ROC.
|
| 378 |
""")
|
| 379 |
|
| 380 |
n_days = st.sidebar.number_input('Number of Days', min_value=1, value=14)
|
|
@@ -382,10 +440,11 @@ elif selected == "Rate of Change (ROC)":
|
|
| 382 |
st.plotly_chart(fig)
|
| 383 |
|
| 384 |
elif selected == "Stochastic Oscillator":
|
|
|
|
|
|
|
|
|
|
| 385 |
with st.expander("Formula and Method Description", expanded=False):
|
| 386 |
st.markdown("""
|
| 387 |
-
### Stochastic Oscillator
|
| 388 |
-
The Stochastic Oscillator compares a stock's closing price to its price range over a specified period. It helps identify overbought and oversold conditions.
|
| 389 |
**How it Works:**
|
| 390 |
1. **Calculate %K and %D:**
|
| 391 |
- The %K line is calculated as follows:
|
|
@@ -398,13 +457,6 @@ elif selected == "Stochastic Oscillator":
|
|
| 398 |
2. **Identify Signals:**
|
| 399 |
- **Buy Signal:** Occurs when %K crosses above a set threshold (e.g., 20), indicating potential upward momentum.
|
| 400 |
- **Sell Signal:** Occurs when %K crosses below a set threshold (e.g., 80), indicating potential downward momentum.
|
| 401 |
-
**How to Use:**
|
| 402 |
-
1. Enter the stock ticker, start date, and end date.
|
| 403 |
-
2. Set the buy and sell thresholds.
|
| 404 |
-
3. Click 'Fetch Data' to load the stock data.
|
| 405 |
-
4. The chart will display the Stochastic Oscillator and highlight buy/sell signals based on thresholds.
|
| 406 |
-
**Results:**
|
| 407 |
-
The chart shows the closing prices with highlighted buy/sell signals and the %K and %D lines.
|
| 408 |
""")
|
| 409 |
|
| 410 |
buy_thresh = st.sidebar.slider('Stochastic Buy Threshold', min_value=0, max_value=100, value=5)
|
|
@@ -413,10 +465,11 @@ elif selected == "Stochastic Oscillator":
|
|
| 413 |
st.plotly_chart(fig)
|
| 414 |
|
| 415 |
elif selected == "Relative Strength Index (RSI)":
|
|
|
|
|
|
|
|
|
|
| 416 |
with st.expander("Formula and Method Description", expanded=False):
|
| 417 |
st.markdown("""
|
| 418 |
-
### Relative Strength Index (RSI)
|
| 419 |
-
The RSI measures the magnitude of recent price changes to evaluate overbought or oversold conditions.
|
| 420 |
**How it Works:**
|
| 421 |
1. **Calculate RSI:**
|
| 422 |
- Compute the average gains and average losses over a specified period (typically 14 days).
|
|
@@ -429,13 +482,6 @@ elif selected == "Relative Strength Index (RSI)":
|
|
| 429 |
2. **Identify Signals:**
|
| 430 |
- **Buy Signal:** Occurs when the RSI crosses below a set threshold (e.g., 30), indicating the stock may be oversold.
|
| 431 |
- **Sell Signal:** Occurs when the RSI crosses above a set threshold (e.g., 70), indicating the stock may be overbought.
|
| 432 |
-
**How to Use:**
|
| 433 |
-
1. Enter the stock ticker, start date, and end date.
|
| 434 |
-
2. Set the buy and sell thresholds.
|
| 435 |
-
3. Click 'Fetch Data' to load the stock data.
|
| 436 |
-
4. The chart will display the RSI and highlight buy/sell signals based on thresholds.
|
| 437 |
-
**Results:**
|
| 438 |
-
The chart shows the stock prices with highlighted buy/sell signals and the RSI line.
|
| 439 |
""")
|
| 440 |
|
| 441 |
buy_thresh = st.sidebar.slider('RSI Buy Threshold', min_value=0, max_value=100, value=30)
|
|
@@ -444,10 +490,11 @@ elif selected == "Relative Strength Index (RSI)":
|
|
| 444 |
st.plotly_chart(fig)
|
| 445 |
|
| 446 |
elif selected == "MACD":
|
|
|
|
|
|
|
|
|
|
| 447 |
with st.expander("Formula and Method Description", expanded=False):
|
| 448 |
st.markdown("""
|
| 449 |
-
### Moving Average Convergence Divergence (MACD)
|
| 450 |
-
The MACD is a trend-following momentum indicator that shows the relationship between two moving averages of a stock's price.
|
| 451 |
**How it Works:**
|
| 452 |
1. **Calculate MACD:**
|
| 453 |
- Compute the MACD line using the formula:
|
|
@@ -461,22 +508,17 @@ elif selected == "MACD":
|
|
| 461 |
2. **Identify Signals:**
|
| 462 |
- **Buy Signal:** Occurs when the MACD line crosses above the Signal line, indicating potential upward momentum.
|
| 463 |
- **Sell Signal:** Occurs when the MACD line crosses below the Signal line, indicating potential downward momentum.
|
| 464 |
-
**How to Use:**
|
| 465 |
-
1. Enter the stock ticker, start date, and end date.
|
| 466 |
-
2. Click 'Fetch Data' to load the stock data.
|
| 467 |
-
3. The chart will display the MACD line, Signal line, and Histogram, and highlight buy/sell signals based on MACD crossovers.
|
| 468 |
-
**Results:**
|
| 469 |
-
The chart shows the stock prices with highlighted buy/sell signals, MACD line, Signal line, and Histogram.
|
| 470 |
""")
|
| 471 |
|
| 472 |
fig = plot_macd(close_prices)
|
| 473 |
st.plotly_chart(fig)
|
| 474 |
|
| 475 |
elif selected == "Bollinger Bands":
|
|
|
|
|
|
|
|
|
|
| 476 |
with st.expander("Formula and Method Description", expanded=False):
|
| 477 |
st.markdown("""
|
| 478 |
-
### Bollinger Bands
|
| 479 |
-
Bollinger Bands consist of a middle band (Simple Moving Average) and two outer bands (standard deviations from the SMA). They help identify overbought and oversold conditions.
|
| 480 |
**How it Works:**
|
| 481 |
1. **Calculate Bollinger Bands:**
|
| 482 |
- Compute the middle band as the Simple Moving Average (SMA) of the stock prices over a specified period (typically 20 days).
|
|
@@ -493,22 +535,17 @@ elif selected == "Bollinger Bands":
|
|
| 493 |
2. **Identify Signals:**
|
| 494 |
- **Buy Signal:** Occurs when the stock price crosses below the lower band, indicating the stock may be oversold.
|
| 495 |
- **Sell Signal:** Occurs when the stock price crosses above the upper band, indicating the stock may be overbought.
|
| 496 |
-
**How to Use:**
|
| 497 |
-
1. Enter the stock ticker, start date, and end date.
|
| 498 |
-
2. Click 'Fetch Data' to load the stock data.
|
| 499 |
-
3. The chart will display the Bollinger Bands and highlight buy/sell signals based on price crossing the bands.
|
| 500 |
-
**Results:**
|
| 501 |
-
The chart shows the stock prices with highlighted buy/sell signals and the Bollinger Bands.
|
| 502 |
""")
|
| 503 |
|
| 504 |
fig = plot_bollinger_bands(close_prices)
|
| 505 |
st.plotly_chart(fig)
|
| 506 |
|
| 507 |
elif selected == "K Reversal":
|
|
|
|
|
|
|
|
|
|
| 508 |
with st.expander("Formula and Method Description", expanded=False):
|
| 509 |
st.markdown("""
|
| 510 |
-
### K Reversal
|
| 511 |
-
The K Reversal indicator helps identify potential reversal points based on the stock's high and low prices over a specified period.
|
| 512 |
**How it Works:**
|
| 513 |
1. **Calculate K Reversal:**
|
| 514 |
- Compute the highest high and lowest low over a specified period (e.g., 14 days).
|
|
@@ -521,14 +558,6 @@ elif selected == "K Reversal":
|
|
| 521 |
2. **Identify Signals:**
|
| 522 |
- **Buy Signal:** Occurs when the K value crosses below a set threshold (e.g., 20), indicating the stock may be oversold.
|
| 523 |
- **Sell Signal:** Occurs when the K value crosses above a set threshold (e.g., 80), indicating the stock may be overbought.
|
| 524 |
-
**How to Use:**
|
| 525 |
-
1. Enter the stock ticker, start date, and end date.
|
| 526 |
-
2. Set the period for the K Reversal calculation.
|
| 527 |
-
3. Set the buy and sell thresholds.
|
| 528 |
-
4. Click 'Fetch Data' to load the stock data.
|
| 529 |
-
5. The chart will display the K Reversal indicator and highlight buy/sell signals.
|
| 530 |
-
**Results:**
|
| 531 |
-
The chart shows the stock prices with the K Reversal indicator and highlighted buy/sell signals.
|
| 532 |
""")
|
| 533 |
|
| 534 |
k_period = st.sidebar.number_input('K Reversal Period', min_value=1, value=14)
|
|
@@ -538,10 +567,11 @@ elif selected == "K Reversal":
|
|
| 538 |
st.plotly_chart(fig)
|
| 539 |
|
| 540 |
elif selected == "Awesome Oscillator":
|
|
|
|
|
|
|
|
|
|
| 541 |
with st.expander("Formula and Method Description", expanded=False):
|
| 542 |
st.markdown("""
|
| 543 |
-
### Awesome Oscillator
|
| 544 |
-
The Awesome Oscillator measures market momentum by comparing the 34-period and 5-period simple moving averages of the midpoints of each candlestick.
|
| 545 |
**How it Works:**
|
| 546 |
1. **Calculate the Midpoint:**
|
| 547 |
- For each candlestick, compute the midpoint using:
|
|
@@ -562,14 +592,6 @@ elif selected == "Awesome Oscillator":
|
|
| 562 |
4. **Identify Signals:**
|
| 563 |
- **Buy Signal:** Occurs when the AO crosses above the signal line (e.g., 0), indicating potential upward momentum.
|
| 564 |
- **Sell Signal:** Occurs when the AO crosses below the signal line, indicating potential downward momentum.
|
| 565 |
-
**How to Use:**
|
| 566 |
-
1. Enter the stock ticker, start date, and end date.
|
| 567 |
-
2. Set the signal line period.
|
| 568 |
-
3. Set the buy and sell thresholds.
|
| 569 |
-
4. Click 'Fetch Data' to load the stock data.
|
| 570 |
-
5. The chart will display the Awesome Oscillator and highlight buy/sell signals based on thresholds.
|
| 571 |
-
**Results:**
|
| 572 |
-
The chart shows the stock prices with the Awesome Oscillator and highlighted buy/sell signals.
|
| 573 |
""")
|
| 574 |
|
| 575 |
signal_period = st.sidebar.number_input('Signal Line Period', min_value=1, value=9)
|
|
@@ -579,10 +601,11 @@ elif selected == "Awesome Oscillator":
|
|
| 579 |
st.plotly_chart(fig)
|
| 580 |
|
| 581 |
elif selected == "Williams %R":
|
|
|
|
|
|
|
|
|
|
| 582 |
with st.expander("Formula and Method Description", expanded=False):
|
| 583 |
st.markdown("""
|
| 584 |
-
### Williams %R
|
| 585 |
-
The Williams %R measures overbought and oversold levels.
|
| 586 |
**How it Works:**
|
| 587 |
1. **Calculate Williams %R:**
|
| 588 |
- Compute the highest high and lowest low over a specified look-back period (e.g., 14 days).
|
|
@@ -595,14 +618,6 @@ elif selected == "Williams %R":
|
|
| 595 |
2. **Identify Signals:**
|
| 596 |
- **Buy Signal:** Occurs when the Williams %R crosses below a set threshold (e.g., -80), indicating the stock may be oversold.
|
| 597 |
- **Sell Signal:** Occurs when the Williams %R crosses above a set threshold (e.g., -20), indicating the stock may be overbought.
|
| 598 |
-
**How to Use:**
|
| 599 |
-
1. Enter the stock ticker, start date, and end date.
|
| 600 |
-
2. Set the look-back period.
|
| 601 |
-
3. Set the buy and sell thresholds.
|
| 602 |
-
4. Click 'Fetch Data' to load the stock data.
|
| 603 |
-
5. The chart will display the Williams %R and highlight buy/sell signals based on thresholds.
|
| 604 |
-
**Results:**
|
| 605 |
-
The chart shows the stock prices with the Williams %R and highlighted buy/sell signals.
|
| 606 |
""")
|
| 607 |
|
| 608 |
williams_r_period = st.sidebar.number_input('Look-back Period', min_value=1, value=14)
|
|
@@ -612,10 +627,11 @@ elif selected == "Williams %R":
|
|
| 612 |
st.plotly_chart(fig)
|
| 613 |
|
| 614 |
elif selected == "Aroon Oscillator":
|
|
|
|
|
|
|
|
|
|
| 615 |
with st.expander("Formula and Method Description", expanded=False):
|
| 616 |
st.markdown("""
|
| 617 |
-
### Aroon Oscillator
|
| 618 |
-
The Aroon Oscillator measures the strength of a trend in the stock's price.
|
| 619 |
**How it Works:**
|
| 620 |
1. **Calculate Aroon Up and Aroon Down:**
|
| 621 |
- Compute the Aroon Up, which measures the time since the highest high during the look-back period:
|
|
@@ -640,13 +656,6 @@ elif selected == "Aroon Oscillator":
|
|
| 640 |
3. **Identify Signals:**
|
| 641 |
- **Buy Signal:** Occurs when the Aroon Oscillator crosses above zero, indicating a potential upward trend.
|
| 642 |
- **Sell Signal:** Occurs when the Aroon Oscillator crosses below zero, indicating a potential downward trend.
|
| 643 |
-
**How to Use:**
|
| 644 |
-
1. Enter the stock ticker, start date, and end date.
|
| 645 |
-
2. Set the look-back period.
|
| 646 |
-
3. Click 'Fetch Data' to load the stock data.
|
| 647 |
-
4. The chart will display the Aroon Oscillator and highlight buy/sell signals based on thresholds.
|
| 648 |
-
**Results:**
|
| 649 |
-
The chart shows the stock prices with the Aroon Oscillator and highlighted buy/sell signals.
|
| 650 |
""")
|
| 651 |
|
| 652 |
aroon_period = st.sidebar.number_input('Look-back Period', min_value=1, value=25)
|
|
|
|
| 288 |
with st.sidebar.expander("Method Selection", expanded=True):
|
| 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
|
| 292 |
+
with st.sidebar.expander("How to Use", expanded=True):
|
| 293 |
+
if selected == "Rolling Z-Score":
|
| 294 |
+
st.markdown("""
|
| 295 |
+
1. Enter the stock or crypto symbol (e.g., 'AAPL' for Apple or 'BTC-USD' for Bitcoin).
|
| 296 |
+
2. Choose the date range.
|
| 297 |
+
3. Set the number of days for the z-score calculation.
|
| 298 |
+
4. Set the z-score threshold.
|
| 299 |
+
5. Click 'Fetch Data' to load the data.
|
| 300 |
+
6. The chart will display the rolling z-scores and highlight buy/sell signals based on the thresholds.
|
| 301 |
+
""")
|
| 302 |
+
elif selected == "Rate of Change (ROC)":
|
| 303 |
+
st.markdown("""
|
| 304 |
+
1. Enter the stock or crypto symbol.
|
| 305 |
+
2. Choose the date range.
|
| 306 |
+
3. Set the number of days for the ROC calculation.
|
| 307 |
+
4. Click 'Fetch Data' to load the data.
|
| 308 |
+
5. The chart will display the ROC and highlight buy/sell signals based on ROC crossing zero.
|
| 309 |
+
""")
|
| 310 |
+
elif selected == "Stochastic Oscillator":
|
| 311 |
+
st.markdown("""
|
| 312 |
+
1. Enter the stock or crypto symbol.
|
| 313 |
+
2. Choose the date range.
|
| 314 |
+
3. Set the buy and sell thresholds.
|
| 315 |
+
4. Click 'Fetch Data' to load the data.
|
| 316 |
+
5. The chart will display the Stochastic Oscillator and highlight buy/sell signals.
|
| 317 |
+
""")
|
| 318 |
+
elif selected == "Relative Strength Index (RSI)":
|
| 319 |
+
st.markdown("""
|
| 320 |
+
1. Enter the stock or crypto symbol.
|
| 321 |
+
2. Choose the date range.
|
| 322 |
+
3. Set the buy and sell thresholds.
|
| 323 |
+
4. Click 'Fetch Data' to load the data.
|
| 324 |
+
5. The chart will display the RSI and highlight buy/sell signals.
|
| 325 |
+
""")
|
| 326 |
+
elif selected == "MACD":
|
| 327 |
+
st.markdown("""
|
| 328 |
+
1. Enter the stock or crypto symbol.
|
| 329 |
+
2. Choose the date range.
|
| 330 |
+
3. Click 'Fetch Data' to load the data.
|
| 331 |
+
4. The chart will display the MACD, Signal line, and Histogram, and highlight buy/sell signals based on MACD crossovers.
|
| 332 |
+
""")
|
| 333 |
+
elif selected == "Bollinger Bands":
|
| 334 |
+
st.markdown("""
|
| 335 |
+
1. Enter the stock or crypto symbol.
|
| 336 |
+
2. Choose the date range.
|
| 337 |
+
3. Click 'Fetch Data' to load the data.
|
| 338 |
+
4. The chart will display the Bollinger Bands and highlight buy/sell signals based on price crossing the bands.
|
| 339 |
+
""")
|
| 340 |
+
elif selected == "K Reversal":
|
| 341 |
+
st.markdown("""
|
| 342 |
+
1. Enter the stock or crypto symbol.
|
| 343 |
+
2. Choose the date range.
|
| 344 |
+
3. Set the period for the K Reversal calculation.
|
| 345 |
+
4. Set the buy and sell thresholds.
|
| 346 |
+
5. Click 'Fetch Data' to load the data.
|
| 347 |
+
6. The chart will display the K Reversal indicator and highlight buy/sell signals.
|
| 348 |
+
""")
|
| 349 |
+
elif selected == "Awesome Oscillator":
|
| 350 |
+
st.markdown("""
|
| 351 |
+
1. Enter the stock or crypto symbol.
|
| 352 |
+
2. Choose the date range.
|
| 353 |
+
3. Set the signal line period.
|
| 354 |
+
4. Set the buy and sell thresholds.
|
| 355 |
+
5. Click 'Fetch Data' to load the data.
|
| 356 |
+
6. The chart will display the Awesome Oscillator and highlight buy/sell signals.
|
| 357 |
+
""")
|
| 358 |
+
elif selected == "Williams %R":
|
| 359 |
+
st.markdown("""
|
| 360 |
+
1. Enter the stock or crypto symbol.
|
| 361 |
+
2. Choose the date range.
|
| 362 |
+
3. Set the look-back period.
|
| 363 |
+
4. Set the buy and sell thresholds.
|
| 364 |
+
5. Click 'Fetch Data' to load the data.
|
| 365 |
+
6. The chart will display the Williams %R and highlight buy/sell signals.
|
| 366 |
+
""")
|
| 367 |
+
elif selected == "Aroon Oscillator":
|
| 368 |
+
st.markdown("""
|
| 369 |
+
1. Enter the stock or crypto symbol.
|
| 370 |
+
2. Choose the date range.
|
| 371 |
+
3. Set the look-back period.
|
| 372 |
+
4. Click 'Fetch Data' to load the data.
|
| 373 |
+
5. The chart will display the Aroon Oscillator and highlight buy/sell signals based on thresholds.
|
| 374 |
+
""")
|
| 375 |
+
|
| 376 |
+
# Sidebar for input parameters inside an expander
|
| 377 |
with st.sidebar.expander("Input Parameters", expanded=True):
|
| 378 |
ticker = st.text_input('Enter Stock or Crypto Symbol (e.g., AAPL or BTC-USD)', 'AAPL')
|
| 379 |
start_date = st.date_input('Start Date', pd.to_datetime('2019-01-01'))
|
|
|
|
| 386 |
data = st.session_state.data
|
| 387 |
close_prices = data['Close']
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
# Display results based on the selected method
|
| 390 |
if selected == "Rolling Z-Score":
|
| 391 |
+
st.markdown("## Rolling Z-Score")
|
| 392 |
+
st.markdown("The rolling z-score method identifies overbought and oversold conditions by standardizing stock prices over different periods.")
|
| 393 |
+
|
| 394 |
with st.expander("Formula and Method Description", expanded=False):
|
| 395 |
st.markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
**How it Works:**
|
| 397 |
|
| 398 |
1. **Calculate Rolling Mean and Standard Deviation:**
|
|
|
|
| 408 |
3. **Identify Signals:**
|
| 409 |
- **Overbought Condition:** Z-score above a set threshold (e.g., 2.0) suggests the stock may be overbought.
|
| 410 |
- **Oversold Condition:** Z-score below a set threshold (e.g., -2.0) suggests the stock may be oversold.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
""")
|
| 412 |
|
| 413 |
periods = st.sidebar.multiselect('Periods to Compare', options=[10, 20, 30, 40, 50], default=[20])
|
|
|
|
| 417 |
st.plotly_chart(fig)
|
| 418 |
|
| 419 |
elif selected == "Rate of Change (ROC)":
|
| 420 |
+
st.markdown("## Rate of Change (ROC)")
|
| 421 |
+
st.markdown("The Rate of Change (ROC) method measures the percentage change in stock prices over a specified period. It helps identify momentum and potential reversal points in the stock price.")
|
| 422 |
+
|
| 423 |
with st.expander("Formula and Method Description", expanded=False):
|
| 424 |
st.markdown("""
|
|
|
|
|
|
|
| 425 |
**How it Works:**
|
| 426 |
1. **Calculate ROC:**
|
| 427 |
- For each day, calculate the ROC using the formula:
|
|
|
|
| 433 |
2. **Identify Signals:**
|
| 434 |
- **Buy Signal:** Occurs when the ROC crosses above zero, indicating potential upward momentum.
|
| 435 |
- **Sell Signal:** Occurs when the ROC crosses below zero, indicating potential downward momentum.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
""")
|
| 437 |
|
| 438 |
n_days = st.sidebar.number_input('Number of Days', min_value=1, value=14)
|
|
|
|
| 440 |
st.plotly_chart(fig)
|
| 441 |
|
| 442 |
elif selected == "Stochastic Oscillator":
|
| 443 |
+
st.markdown("## Stochastic Oscillator")
|
| 444 |
+
st.markdown("The Stochastic Oscillator compares a stock's closing price to its price range over a specified period. It helps identify overbought and oversold conditions.")
|
| 445 |
+
|
| 446 |
with st.expander("Formula and Method Description", expanded=False):
|
| 447 |
st.markdown("""
|
|
|
|
|
|
|
| 448 |
**How it Works:**
|
| 449 |
1. **Calculate %K and %D:**
|
| 450 |
- The %K line is calculated as follows:
|
|
|
|
| 457 |
2. **Identify Signals:**
|
| 458 |
- **Buy Signal:** Occurs when %K crosses above a set threshold (e.g., 20), indicating potential upward momentum.
|
| 459 |
- **Sell Signal:** Occurs when %K crosses below a set threshold (e.g., 80), indicating potential downward momentum.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
""")
|
| 461 |
|
| 462 |
buy_thresh = st.sidebar.slider('Stochastic Buy Threshold', min_value=0, max_value=100, value=5)
|
|
|
|
| 465 |
st.plotly_chart(fig)
|
| 466 |
|
| 467 |
elif selected == "Relative Strength Index (RSI)":
|
| 468 |
+
st.markdown("## Relative Strength Index (RSI)")
|
| 469 |
+
st.markdown("The RSI measures the magnitude of recent price changes to evaluate overbought or oversold conditions.")
|
| 470 |
+
|
| 471 |
with st.expander("Formula and Method Description", expanded=False):
|
| 472 |
st.markdown("""
|
|
|
|
|
|
|
| 473 |
**How it Works:**
|
| 474 |
1. **Calculate RSI:**
|
| 475 |
- Compute the average gains and average losses over a specified period (typically 14 days).
|
|
|
|
| 482 |
2. **Identify Signals:**
|
| 483 |
- **Buy Signal:** Occurs when the RSI crosses below a set threshold (e.g., 30), indicating the stock may be oversold.
|
| 484 |
- **Sell Signal:** Occurs when the RSI crosses above a set threshold (e.g., 70), indicating the stock may be overbought.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
""")
|
| 486 |
|
| 487 |
buy_thresh = st.sidebar.slider('RSI Buy Threshold', min_value=0, max_value=100, value=30)
|
|
|
|
| 490 |
st.plotly_chart(fig)
|
| 491 |
|
| 492 |
elif selected == "MACD":
|
| 493 |
+
st.markdown("## Moving Average Convergence Divergence (MACD)")
|
| 494 |
+
st.markdown("The MACD is a trend-following momentum indicator that shows the relationship between two moving averages of a stock's price.")
|
| 495 |
+
|
| 496 |
with st.expander("Formula and Method Description", expanded=False):
|
| 497 |
st.markdown("""
|
|
|
|
|
|
|
| 498 |
**How it Works:**
|
| 499 |
1. **Calculate MACD:**
|
| 500 |
- Compute the MACD line using the formula:
|
|
|
|
| 508 |
2. **Identify Signals:**
|
| 509 |
- **Buy Signal:** Occurs when the MACD line crosses above the Signal line, indicating potential upward momentum.
|
| 510 |
- **Sell Signal:** Occurs when the MACD line crosses below the Signal line, indicating potential downward momentum.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
""")
|
| 512 |
|
| 513 |
fig = plot_macd(close_prices)
|
| 514 |
st.plotly_chart(fig)
|
| 515 |
|
| 516 |
elif selected == "Bollinger Bands":
|
| 517 |
+
st.markdown("## Bollinger Bands")
|
| 518 |
+
st.markdown("Bollinger Bands consist of a middle band (Simple Moving Average) and two outer bands (standard deviations from the SMA). They help identify overbought and oversold conditions.")
|
| 519 |
+
|
| 520 |
with st.expander("Formula and Method Description", expanded=False):
|
| 521 |
st.markdown("""
|
|
|
|
|
|
|
| 522 |
**How it Works:**
|
| 523 |
1. **Calculate Bollinger Bands:**
|
| 524 |
- Compute the middle band as the Simple Moving Average (SMA) of the stock prices over a specified period (typically 20 days).
|
|
|
|
| 535 |
2. **Identify Signals:**
|
| 536 |
- **Buy Signal:** Occurs when the stock price crosses below the lower band, indicating the stock may be oversold.
|
| 537 |
- **Sell Signal:** Occurs when the stock price crosses above the upper band, indicating the stock may be overbought.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
""")
|
| 539 |
|
| 540 |
fig = plot_bollinger_bands(close_prices)
|
| 541 |
st.plotly_chart(fig)
|
| 542 |
|
| 543 |
elif selected == "K Reversal":
|
| 544 |
+
st.markdown("## K Reversal")
|
| 545 |
+
st.markdown("The K Reversal indicator helps identify potential reversal points based on the stock's high and low prices over a specified period.")
|
| 546 |
+
|
| 547 |
with st.expander("Formula and Method Description", expanded=False):
|
| 548 |
st.markdown("""
|
|
|
|
|
|
|
| 549 |
**How it Works:**
|
| 550 |
1. **Calculate K Reversal:**
|
| 551 |
- Compute the highest high and lowest low over a specified period (e.g., 14 days).
|
|
|
|
| 558 |
2. **Identify Signals:**
|
| 559 |
- **Buy Signal:** Occurs when the K value crosses below a set threshold (e.g., 20), indicating the stock may be oversold.
|
| 560 |
- **Sell Signal:** Occurs when the K value crosses above a set threshold (e.g., 80), indicating the stock may be overbought.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
""")
|
| 562 |
|
| 563 |
k_period = st.sidebar.number_input('K Reversal Period', min_value=1, value=14)
|
|
|
|
| 567 |
st.plotly_chart(fig)
|
| 568 |
|
| 569 |
elif selected == "Awesome Oscillator":
|
| 570 |
+
st.markdown("## Awesome Oscillator")
|
| 571 |
+
st.markdown("The Awesome Oscillator measures market momentum by comparing the 34-period and 5-period simple moving averages of the midpoints of each candlestick.")
|
| 572 |
+
|
| 573 |
with st.expander("Formula and Method Description", expanded=False):
|
| 574 |
st.markdown("""
|
|
|
|
|
|
|
| 575 |
**How it Works:**
|
| 576 |
1. **Calculate the Midpoint:**
|
| 577 |
- For each candlestick, compute the midpoint using:
|
|
|
|
| 592 |
4. **Identify Signals:**
|
| 593 |
- **Buy Signal:** Occurs when the AO crosses above the signal line (e.g., 0), indicating potential upward momentum.
|
| 594 |
- **Sell Signal:** Occurs when the AO crosses below the signal line, indicating potential downward momentum.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
""")
|
| 596 |
|
| 597 |
signal_period = st.sidebar.number_input('Signal Line Period', min_value=1, value=9)
|
|
|
|
| 601 |
st.plotly_chart(fig)
|
| 602 |
|
| 603 |
elif selected == "Williams %R":
|
| 604 |
+
st.markdown("## Williams %R")
|
| 605 |
+
st.markdown("The Williams %R measures overbought and oversold levels.")
|
| 606 |
+
|
| 607 |
with st.expander("Formula and Method Description", expanded=False):
|
| 608 |
st.markdown("""
|
|
|
|
|
|
|
| 609 |
**How it Works:**
|
| 610 |
1. **Calculate Williams %R:**
|
| 611 |
- Compute the highest high and lowest low over a specified look-back period (e.g., 14 days).
|
|
|
|
| 618 |
2. **Identify Signals:**
|
| 619 |
- **Buy Signal:** Occurs when the Williams %R crosses below a set threshold (e.g., -80), indicating the stock may be oversold.
|
| 620 |
- **Sell Signal:** Occurs when the Williams %R crosses above a set threshold (e.g., -20), indicating the stock may be overbought.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
""")
|
| 622 |
|
| 623 |
williams_r_period = st.sidebar.number_input('Look-back Period', min_value=1, value=14)
|
|
|
|
| 627 |
st.plotly_chart(fig)
|
| 628 |
|
| 629 |
elif selected == "Aroon Oscillator":
|
| 630 |
+
st.markdown("## Aroon Oscillator")
|
| 631 |
+
st.markdown("The Aroon Oscillator measures the strength of a trend in the stock's price.")
|
| 632 |
+
|
| 633 |
with st.expander("Formula and Method Description", expanded=False):
|
| 634 |
st.markdown("""
|
|
|
|
|
|
|
| 635 |
**How it Works:**
|
| 636 |
1. **Calculate Aroon Up and Aroon Down:**
|
| 637 |
- Compute the Aroon Up, which measures the time since the highest high during the look-back period:
|
|
|
|
| 656 |
3. **Identify Signals:**
|
| 657 |
- **Buy Signal:** Occurs when the Aroon Oscillator crosses above zero, indicating a potential upward trend.
|
| 658 |
- **Sell Signal:** Occurs when the Aroon Oscillator crosses below zero, indicating a potential downward trend.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
""")
|
| 660 |
|
| 661 |
aroon_period = st.sidebar.number_input('Look-back Period', min_value=1, value=25)
|