Tonic commited on
Commit
7b4c6ac
·
unverified ·
1 Parent(s): 0d3e6c8

update gradio interface and market open/close

Browse files
Files changed (2) hide show
  1. README.md +56 -8
  2. app.py +243 -125
README.md CHANGED
@@ -1,23 +1,36 @@
1
  ---
2
- title: Stock Predictions
3
- emoji: 🐢
4
- colorFrom: yellow
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.33.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: Use Amazon Chronos To Predict Stock Prices
12
  tags:
13
  - mcp-server-track
 
 
 
 
 
14
  ---
15
 
16
- # Enhanced Stock Prediction System with Amazon Chronos
17
 
18
- A comprehensive stock prediction and analysis system that leverages Amazon's Chronos foundation model for time series forecasting, enhanced with advanced covariate data, sentiment analysis, and sophisticated uncertainty calculations.
19
 
20
- ## 🚀 Key Features
 
 
 
 
 
 
 
 
21
 
22
  ### Core Prediction Engine
23
  - **Amazon Chronos Integration**: Uses the state-of-the-art Chronos T5 foundation model for probabilistic time series forecasting
@@ -131,6 +144,41 @@ The application provides a comprehensive web interface with three main tabs:
131
  2. **Hourly Analysis**: Medium-term trading analysis (up to 7 days)
132
  3. **15-Minute Analysis**: Short-term scalping analysis (up to 3 days)
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  ### Advanced Settings
135
  - **Ensemble Methods**: Enable/disable multi-algorithm ensemble
136
  - **Regime Detection**: Enable/disable market regime detection
 
1
  ---
2
+ title: Advanced Stock Prediction Analysis with Amazon Chronos
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.33.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ short_description: Advanced AI-powered stock prediction system with Amazon Chronos foundation model
12
  tags:
13
  - mcp-server-track
14
+ - finance
15
+ - machine-learning
16
+ - time-series
17
+ - stock-prediction
18
+ - chronos
19
  ---
20
 
21
+ # 🚀 Advanced Stock Prediction Analysis with Amazon Chronos
22
 
23
+ A cutting-edge AI-powered stock prediction and analysis system with **580M+ parameters**, designed to analyze and predict stock prices across multiple timeframes. Equipped with **Amazon's Chronos foundation model** and **advanced ensemble methods**, it excels in both short-term trading and long-term investment analysis.
24
 
25
+ ## 🌟 Key Features
26
+
27
+ ### Market Status Monitoring
28
+ - **Real-Time Market Status**: Check if markets are open or closed with a simple click
29
+ - **Multi-Market Support**: Monitor US Stocks, European Markets, Asian Markets, Forex, Crypto, Futures, and Commodities
30
+ - **Timezone-Aware**: Accurate status based on each market's local timezone
31
+ - **Trading Hours**: Detailed information about market hours and next trading days
32
+ - **24/7 Markets**: Support for continuous trading markets like Forex and Crypto
33
+ - **User-Friendly Interface**: Simple dropdown menu and click-to-check functionality
34
 
35
  ### Core Prediction Engine
36
  - **Amazon Chronos Integration**: Uses the state-of-the-art Chronos T5 foundation model for probabilistic time series forecasting
 
144
  2. **Hourly Analysis**: Medium-term trading analysis (up to 7 days)
145
  3. **15-Minute Analysis**: Short-term scalping analysis (up to 3 days)
146
 
147
+ ### Market Status Check
148
+ The application includes a simple market status monitoring feature:
149
+
150
+ 1. **Quick Market Status Check**: Located at the top of the interface
151
+ 2. **Market Selection**: Dropdown menu with all supported markets:
152
+ - US Stock Market (NYSE, NASDAQ, AMEX)
153
+ - European Markets (London, Frankfurt, Paris)
154
+ - Asian Markets (Tokyo, Hong Kong, Shanghai)
155
+ - Forex Market (24/7 Global Currency Exchange)
156
+ - Cryptocurrency Market (24/7 Bitcoin, Ethereum, Altcoins)
157
+ - US Futures Market (24/7 CME, ICE, CBOT)
158
+ - Commodities Market (24/7 Gold, Silver, Oil, Natural Gas)
159
+ 3. **One-Click Check**: Click "Check Market Status" to get real-time information
160
+ 4. **Detailed Information**: Shows current status, trading hours, next trading day, and time until open/close
161
+
162
+ **Example Output:**
163
+ ```
164
+ 🟢 US Stock Market Status: OPEN
165
+
166
+ Current Status: US Stock Market is currently open
167
+
168
+ Market Details:
169
+ - Type: Stocks
170
+ - Symbol: ^GSPC
171
+ - Current Time: 14:30:00 EDT
172
+ - Last Updated: 2024-01-15 14:30:00 EDT
173
+
174
+ Trading Information:
175
+ - Next Trading Day: 2024-01-16
176
+ - Time Until Open: N/A (Market is open)
177
+ - Time Until Close: 1h 30m
178
+
179
+ Market Description: NYSE, NASDAQ, AMEX
180
+ ```
181
+
182
  ### Advanced Settings
183
  - **Ensemble Methods**: Enable/disable multi-algorithm ensemble
184
  - **Regime Detection**: Enable/disable market regime detection
app.py CHANGED
@@ -1666,11 +1666,11 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1666
  else: # 15m
1667
  pred_dates = pd.date_range(start=last_date + timedelta(minutes=15), periods=prediction_days * 96)
1668
 
1669
- # Create enhanced visualization
1670
- fig = make_subplots(rows=4, cols=1,
1671
  shared_xaxes=True,
1672
  vertical_spacing=0.05,
1673
- subplot_titles=('Price Prediction', 'Technical Indicators', 'Volume', 'Uncertainty Analysis'))
1674
 
1675
  # Add historical price
1676
  fig.add_trace(
@@ -1679,38 +1679,98 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1679
  row=1, col=1
1680
  )
1681
 
1682
- # Add predicted price with uncertainty bands
1683
  fig.add_trace(
1684
  go.Scatter(x=pred_dates, y=final_pred, name='Predicted Price',
1685
- line=dict(color='red', width=2)),
1686
  row=1, col=1
1687
  )
1688
 
1689
- # Add uncertainty bands
1690
- upper_band = final_pred + 2 * final_uncertainty
1691
- lower_band = final_pred - 2 * final_uncertainty
1692
-
1693
- fig.add_trace(
1694
- go.Scatter(x=pred_dates, y=upper_band, name='Upper Bound (95%)',
1695
- line=dict(color='red', width=1, dash='dash'), showlegend=False),
1696
- row=1, col=1
1697
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1698
 
1699
- fig.add_trace(
1700
- go.Scatter(x=pred_dates, y=lower_band, name='Lower Bound (95%)',
1701
- line=dict(color='red', width=1, dash='dash'), fill='tonexty',
1702
- fillcolor='rgba(255,0,0,0.1)', showlegend=False),
1703
- row=1, col=1
1704
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1705
 
1706
- # Add technical indicators
 
1707
  fig.add_trace(
1708
  go.Scatter(x=df.index, y=df['RSI'], name='RSI (Historical)',
1709
  line=dict(color='purple', width=1)),
1710
  row=2, col=1
1711
  )
1712
 
1713
- # Add predicted RSI if available
1714
  if 'RSI' in technical_predictions:
1715
  fig.add_trace(
1716
  go.Scatter(x=pred_dates, y=technical_predictions['RSI'], name='RSI (Predicted)',
@@ -1736,13 +1796,13 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1736
  row=2, col=1
1737
  )
1738
 
 
1739
  fig.add_trace(
1740
  go.Scatter(x=df.index, y=df['MACD'], name='MACD (Historical)',
1741
  line=dict(color='orange', width=1)),
1742
  row=2, col=1
1743
  )
1744
 
1745
- # Add predicted MACD if available
1746
  if 'MACD' in technical_predictions:
1747
  fig.add_trace(
1748
  go.Scatter(x=pred_dates, y=technical_predictions['MACD'], name='MACD (Predicted)',
@@ -1776,49 +1836,8 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1776
  row=2, col=1
1777
  )
1778
 
1779
- # Add Bollinger Bands if available
1780
- if 'BB_Upper' in df.columns and 'BB_Middle' in df.columns and 'BB_Lower' in df.columns:
1781
- fig.add_trace(
1782
- go.Scatter(x=df.index, y=df['BB_Upper'], name='BB Upper (Historical)',
1783
- line=dict(color='gray', width=1, dash='dash')),
1784
- row=1, col=1
1785
- )
1786
-
1787
- fig.add_trace(
1788
- go.Scatter(x=df.index, y=df['BB_Middle'], name='BB Middle (Historical)',
1789
- line=dict(color='gray', width=1)),
1790
- row=1, col=1
1791
- )
1792
-
1793
- fig.add_trace(
1794
- go.Scatter(x=df.index, y=df['BB_Lower'], name='BB Lower (Historical)',
1795
- line=dict(color='gray', width=1, dash='dash')),
1796
- row=1, col=1
1797
- )
1798
-
1799
- # Add predicted Bollinger Bands if available
1800
- if 'BB_Upper' in technical_predictions:
1801
- fig.add_trace(
1802
- go.Scatter(x=pred_dates, y=technical_predictions['BB_Upper'], name='BB Upper (Predicted)',
1803
- line=dict(color='darkgray', width=2, dash='dash')),
1804
- row=1, col=1
1805
- )
1806
-
1807
- fig.add_trace(
1808
- go.Scatter(x=pred_dates, y=technical_predictions['BB_Middle'], name='BB Middle (Predicted)',
1809
- line=dict(color='darkgray', width=2)),
1810
- row=1, col=1
1811
- )
1812
-
1813
- fig.add_trace(
1814
- go.Scatter(x=pred_dates, y=technical_predictions['BB_Lower'], name='BB Lower (Predicted)',
1815
- line=dict(color='darkgray', width=2, dash='dash')),
1816
- row=1, col=1
1817
- )
1818
-
1819
- # Add volume with better data handling
1820
  if 'Volume' in df.columns and not df['Volume'].isna().all():
1821
- # Ensure volume data is numeric and handle any NaN values
1822
  volume_data = pd.to_numeric(df['Volume'], errors='coerce').fillna(0)
1823
 
1824
  fig.add_trace(
@@ -1862,64 +1881,27 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1862
  row=3, col=1
1863
  )
1864
 
1865
- # Enhanced uncertainty analysis with confidence bands
1866
- if final_uncertainty is not None and len(final_uncertainty) > 0:
1867
- # Ensure uncertainty data is valid
1868
- uncertainty_clean = np.array(final_uncertainty)
1869
- uncertainty_clean = np.where(np.isnan(uncertainty_clean), 0, uncertainty_clean)
1870
-
1871
- # Create confidence bands
1872
- confidence_68 = uncertainty_clean # 1 standard deviation (68% confidence)
1873
- confidence_95 = 2 * uncertainty_clean # 2 standard deviations (95% confidence)
1874
- confidence_99 = 3 * uncertainty_clean # 3 standard deviations (99% confidence)
1875
-
1876
- # Plot uncertainty as confidence bands
1877
- fig.add_trace(
1878
- go.Scatter(x=pred_dates, y=final_pred + confidence_95, name='95% Confidence Upper',
1879
- line=dict(color='green', width=1, dash='dash'), showlegend=False),
1880
- row=4, col=1
1881
- )
1882
-
1883
- fig.add_trace(
1884
- go.Scatter(x=pred_dates, y=final_pred - confidence_95, name='95% Confidence Lower',
1885
- line=dict(color='green', width=1, dash='dash'), fill='tonexty',
1886
- fillcolor='rgba(0,255,0,0.1)', showlegend=False),
1887
- row=4, col=1
1888
- )
1889
-
1890
- fig.add_trace(
1891
- go.Scatter(x=pred_dates, y=final_pred + confidence_68, name='68% Confidence Upper',
1892
- line=dict(color='darkgreen', width=1, dash='dot'), showlegend=False),
1893
- row=4, col=1
1894
- )
1895
-
1896
- fig.add_trace(
1897
- go.Scatter(x=pred_dates, y=final_pred - confidence_68, name='68% Confidence Lower',
1898
- line=dict(color='darkgreen', width=1, dash='dot'), fill='tonexty',
1899
- fillcolor='rgba(0,128,0,0.1)', showlegend=False),
1900
- row=4, col=1
1901
- )
1902
-
1903
- # Add the main prediction line on top
1904
- fig.add_trace(
1905
- go.Scatter(x=pred_dates, y=final_pred, name='Prediction with Uncertainty',
1906
- line=dict(color='darkgreen', width=3)),
1907
- row=4, col=1
1908
- )
1909
-
1910
- # Add uncertainty magnitude as a separate line
1911
- fig.add_trace(
1912
- go.Scatter(x=pred_dates, y=uncertainty_clean, name='Uncertainty Magnitude',
1913
- line=dict(color='orange', width=2)),
1914
- row=4, col=1
1915
- )
1916
- else:
1917
- print("Warning: No valid uncertainty data available for plotting")
1918
 
1919
  # Update layout with better titles and axis labels
1920
  fig.update_layout(
1921
  title=f'Enhanced Stock Prediction for {symbol}',
1922
- height=1000, # Increased height for better visibility
1923
  showlegend=True,
1924
  legend=dict(
1925
  orientation="h",
@@ -1931,16 +1913,15 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
1931
  )
1932
 
1933
  # Update subplot titles and axis labels
1934
- fig.update_xaxes(title_text="Date", row=4, col=1)
1935
  fig.update_yaxes(title_text="Price ($)", row=1, col=1)
1936
  fig.update_yaxes(title_text="Technical Indicators", row=2, col=1)
1937
  fig.update_yaxes(title_text="Volume", row=3, col=1)
1938
- fig.update_yaxes(title_text="Price with Uncertainty ($)", row=4, col=1)
1939
 
1940
  # Update subplot titles
1941
  fig.update_annotations(
1942
  dict(
1943
- text="Price Prediction with Technical Indicators",
1944
  x=0.5,
1945
  y=0.95,
1946
  xref="paper",
@@ -2936,9 +2917,76 @@ def apply_financial_smoothing(data: np.ndarray, smoothing_type: str = "exponenti
2936
 
2937
  def create_interface():
2938
  """Create the Gradio interface with separate tabs for different timeframes"""
2939
- with gr.Blocks(title="Advanced Stock Prediction Analysis") as demo:
2940
- gr.Markdown("# Advanced Stock Prediction Analysis")
2941
- gr.Markdown("Analyze stocks with advanced features including regime detection, ensemble methods, and stress testing.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2942
 
2943
  # Add market status message with periodic updates
2944
  market_status_display = gr.Markdown(
@@ -2948,6 +2996,34 @@ def create_interface():
2948
  # Note: Market status updates automatically in the background thread every 10 minutes
2949
  # The display can be manually refreshed by users if needed
2950
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2951
 
2952
  # Add enhanced market information section
2953
  with gr.Accordion("🌍 Global Market Information", open=False):
@@ -4584,6 +4660,48 @@ def get_enhanced_market_summary() -> Dict:
4584
 
4585
  return market_summary
4586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4587
  if __name__ == "__main__":
4588
  import signal
4589
  import atexit
 
1666
  else: # 15m
1667
  pred_dates = pd.date_range(start=last_date + timedelta(minutes=15), periods=prediction_days * 96)
1668
 
1669
+ # Create enhanced visualization with uncertainties integrated
1670
+ fig = make_subplots(rows=3, cols=1,
1671
  shared_xaxes=True,
1672
  vertical_spacing=0.05,
1673
+ subplot_titles=('Price Prediction with Uncertainty', 'Technical Indicators with Uncertainty', 'Volume with Uncertainty'))
1674
 
1675
  # Add historical price
1676
  fig.add_trace(
 
1679
  row=1, col=1
1680
  )
1681
 
1682
+ # Add predicted price with integrated uncertainty bands
1683
  fig.add_trace(
1684
  go.Scatter(x=pred_dates, y=final_pred, name='Predicted Price',
1685
+ line=dict(color='red', width=3)),
1686
  row=1, col=1
1687
  )
1688
 
1689
+ # Add price uncertainty bands on the same subplot
1690
+ if final_uncertainty is not None and len(final_uncertainty) > 0:
1691
+ uncertainty_clean = np.array(final_uncertainty)
1692
+ uncertainty_clean = np.where(np.isnan(uncertainty_clean), 0, uncertainty_clean)
1693
+
1694
+ # Create confidence bands
1695
+ confidence_68 = uncertainty_clean # 1 standard deviation (68% confidence)
1696
+ confidence_95 = 2 * uncertainty_clean # 2 standard deviations (95% confidence)
1697
+
1698
+ # Plot 95% confidence bands
1699
+ fig.add_trace(
1700
+ go.Scatter(x=pred_dates, y=final_pred + confidence_95, name='95% Confidence Upper',
1701
+ line=dict(color='red', width=1, dash='dash'), showlegend=False),
1702
+ row=1, col=1
1703
+ )
1704
+
1705
+ fig.add_trace(
1706
+ go.Scatter(x=pred_dates, y=final_pred - confidence_95, name='95% Confidence Lower',
1707
+ line=dict(color='red', width=1, dash='dash'), fill='tonexty',
1708
+ fillcolor='rgba(255,0,0,0.1)', showlegend=False),
1709
+ row=1, col=1
1710
+ )
1711
+
1712
+ # Plot 68% confidence bands
1713
+ fig.add_trace(
1714
+ go.Scatter(x=pred_dates, y=final_pred + confidence_68, name='68% Confidence Upper',
1715
+ line=dict(color='darkred', width=1, dash='dot'), showlegend=False),
1716
+ row=1, col=1
1717
+ )
1718
+
1719
+ fig.add_trace(
1720
+ go.Scatter(x=pred_dates, y=final_pred - confidence_68, name='68% Confidence Lower',
1721
+ line=dict(color='darkred', width=1, dash='dot'), fill='tonexty',
1722
+ fillcolor='rgba(139,0,0,0.1)', showlegend=False),
1723
+ row=1, col=1
1724
+ )
1725
 
1726
+ # Add Bollinger Bands if available (on price subplot)
1727
+ if 'BB_Upper' in df.columns and 'BB_Middle' in df.columns and 'BB_Lower' in df.columns:
1728
+ fig.add_trace(
1729
+ go.Scatter(x=df.index, y=df['BB_Upper'], name='BB Upper (Historical)',
1730
+ line=dict(color='gray', width=1, dash='dash')),
1731
+ row=1, col=1
1732
+ )
1733
+
1734
+ fig.add_trace(
1735
+ go.Scatter(x=df.index, y=df['BB_Middle'], name='BB Middle (Historical)',
1736
+ line=dict(color='gray', width=1)),
1737
+ row=1, col=1
1738
+ )
1739
+
1740
+ fig.add_trace(
1741
+ go.Scatter(x=df.index, y=df['BB_Lower'], name='BB Lower (Historical)',
1742
+ line=dict(color='gray', width=1, dash='dash')),
1743
+ row=1, col=1
1744
+ )
1745
+
1746
+ # Add predicted Bollinger Bands if available
1747
+ if 'BB_Upper' in technical_predictions:
1748
+ fig.add_trace(
1749
+ go.Scatter(x=pred_dates, y=technical_predictions['BB_Upper'], name='BB Upper (Predicted)',
1750
+ line=dict(color='darkgray', width=2, dash='dash')),
1751
+ row=1, col=1
1752
+ )
1753
+
1754
+ fig.add_trace(
1755
+ go.Scatter(x=pred_dates, y=technical_predictions['BB_Middle'], name='BB Middle (Predicted)',
1756
+ line=dict(color='darkgray', width=2)),
1757
+ row=1, col=1
1758
+ )
1759
+
1760
+ fig.add_trace(
1761
+ go.Scatter(x=pred_dates, y=technical_predictions['BB_Lower'], name='BB Lower (Predicted)',
1762
+ line=dict(color='darkgray', width=2, dash='dash')),
1763
+ row=1, col=1
1764
+ )
1765
 
1766
+ # Add technical indicators with their uncertainties on the same subplot
1767
+ # RSI with uncertainty
1768
  fig.add_trace(
1769
  go.Scatter(x=df.index, y=df['RSI'], name='RSI (Historical)',
1770
  line=dict(color='purple', width=1)),
1771
  row=2, col=1
1772
  )
1773
 
 
1774
  if 'RSI' in technical_predictions:
1775
  fig.add_trace(
1776
  go.Scatter(x=pred_dates, y=technical_predictions['RSI'], name='RSI (Predicted)',
 
1796
  row=2, col=1
1797
  )
1798
 
1799
+ # MACD with uncertainty
1800
  fig.add_trace(
1801
  go.Scatter(x=df.index, y=df['MACD'], name='MACD (Historical)',
1802
  line=dict(color='orange', width=1)),
1803
  row=2, col=1
1804
  )
1805
 
 
1806
  if 'MACD' in technical_predictions:
1807
  fig.add_trace(
1808
  go.Scatter(x=pred_dates, y=technical_predictions['MACD'], name='MACD (Predicted)',
 
1836
  row=2, col=1
1837
  )
1838
 
1839
+ # Add volume with uncertainty on the same subplot
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1840
  if 'Volume' in df.columns and not df['Volume'].isna().all():
 
1841
  volume_data = pd.to_numeric(df['Volume'], errors='coerce').fillna(0)
1842
 
1843
  fig.add_trace(
 
1881
  row=3, col=1
1882
  )
1883
 
1884
+ # Add reference lines for technical indicators
1885
+ # RSI overbought/oversold lines
1886
+ fig.add_hline(y=70, line_dash="dash", line_color="red",
1887
+ annotation_text="Overbought (70)", row=2, col=1)
1888
+ fig.add_hline(y=30, line_dash="dash", line_color="green",
1889
+ annotation_text="Oversold (30)", row=2, col=1)
1890
+
1891
+ # MACD zero line
1892
+ fig.add_hline(y=0, line_dash="dash", line_color="black",
1893
+ annotation_text="MACD Zero", row=2, col=1)
1894
+
1895
+ # Add volume reference line (average volume)
1896
+ if 'Volume' in df.columns and not df['Volume'].isna().all():
1897
+ avg_volume = df['Volume'].mean()
1898
+ fig.add_hline(y=avg_volume, line_dash="dash", line_color="blue",
1899
+ annotation_text=f"Avg Volume: {avg_volume:,.0f}", row=3, col=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1900
 
1901
  # Update layout with better titles and axis labels
1902
  fig.update_layout(
1903
  title=f'Enhanced Stock Prediction for {symbol}',
1904
+ height=900, # Adjusted height for 3 subplots
1905
  showlegend=True,
1906
  legend=dict(
1907
  orientation="h",
 
1913
  )
1914
 
1915
  # Update subplot titles and axis labels
1916
+ fig.update_xaxes(title_text="Date", row=3, col=1)
1917
  fig.update_yaxes(title_text="Price ($)", row=1, col=1)
1918
  fig.update_yaxes(title_text="Technical Indicators", row=2, col=1)
1919
  fig.update_yaxes(title_text="Volume", row=3, col=1)
 
1920
 
1921
  # Update subplot titles
1922
  fig.update_annotations(
1923
  dict(
1924
+ text="Price Prediction with Uncertainty",
1925
  x=0.5,
1926
  y=0.95,
1927
  xref="paper",
 
2917
 
2918
  def create_interface():
2919
  """Create the Gradio interface with separate tabs for different timeframes"""
2920
+
2921
+ # Enhanced title and descriptions
2922
+ title = """# 🙋🏻‍♂️Welcome to 🌟Tonic's 🚀 Stock Prediction with 📦Amazon ⌚Chronos
2923
+ ---
2924
+ """
2925
+
2926
+ description = """
2927
+ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform with **580M+ parameters**, designed to analyze and predict stock prices across multiple timeframes. Equipped with **Amazon's Chronos foundation model** and **advanced ensemble methods**, it excels in both short-term trading and long-term investment analysis. The system supports **multi-timeframe analysis**, **real-time market monitoring**, and **comprehensive risk assessment**, enhancing its versatility for all types of traders and investors.
2928
+
2929
+ ### Key Features
2930
+ - **Multi-Timeframe Analysis**: Daily (up to 365 days), Hourly (up to 7 days), and 15-minute (up to 3 days) predictions
2931
+ - **Real-Time Market Status**: Check if markets are open with one-click monitoring
2932
+ - **Advanced Ensemble Methods**: Combines Chronos, Technical Analysis, and Statistical Models
2933
+ - **Enhanced Uncertainty Quantification**: Multiple uncertainty calculation methods for robust predictions
2934
+ - **Market Regime Detection**: Identifies bull, bear, and sideways market conditions
2935
+ - **Stress Testing**: Scenario analysis under various market conditions
2936
+ - **Sentiment Analysis**: News sentiment integration for enhanced predictions
2937
+
2938
+ ## Supported Markets
2939
+ - **US Stock Market** (NYSE, NASDAQ, AMEX): 9:30 AM - 4:00 PM ET
2940
+ - **European Markets** (London, Frankfurt, Paris): 8:00 AM - 4:30 PM GMT
2941
+ - **Asian Markets** (Tokyo, Hong Kong, Shanghai): 9:00 AM - 3:30 PM JST
2942
+ - **Forex Market** (24/7 Global Currency Exchange)
2943
+ - **Cryptocurrency Market** (24/7 Bitcoin, Ethereum, Altcoins)
2944
+ - **US Futures Market** (24/7 CME, ICE, CBOT)
2945
+ - **Commodities Market** (24/7 Gold, Silver, Oil, Natural Gas)
2946
+ """
2947
+
2948
+ model_info = """
2949
+ ## How to Use
2950
+ 1. **Market Status Check**: Use the dropdown to check if markets are open
2951
+ 2. **Select Analysis Type**: Choose from Daily, Hourly, or 15-minute analysis
2952
+ 3. **Enter Stock Symbol**: Input any valid stock symbol (e.g., AAPL, TSLA, GOOGL)
2953
+ 4. **Configure Parameters**: Adjust prediction days, lookback period, and advanced settings
2954
+ 5. **Click Analyze**: View comprehensive predictions with uncertainty estimates
2955
+
2956
+ ## Model Information
2957
+ - **Core Model**: Amazon Chronos T5 Foundation Model
2958
+ - **Ensemble Methods**: Random Forest, Gradient Boosting, SVR, Neural Networks
2959
+ - **Technical Indicators**: RSI, MACD, Bollinger Bands, Moving Averages
2960
+ - **Risk Metrics**: Sharpe Ratio, VaR, Maximum Drawdown, Beta
2961
+ - **Data Sources**: Yahoo Finance, Market Indices, Economic Indicators
2962
+ - **Environment**: PyTorch 2.1.2 + CUDA Support + Advanced ML Libraries
2963
+ """
2964
+
2965
+ join_us = """
2966
+ ## Join the Community
2967
+ 🌟 **Advanced Stock Prediction** is continuously evolving! Join our active builder's community 👻
2968
+
2969
+ [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/qdfnvSPcqP)
2970
+ [![Hugging Face](https://img.shields.io/badge/Hugging%20Face-Open%20Source-blue?logo=huggingface&style=flat-square)](https://huggingface.co/TeamTonic)
2971
+ [![GitHub](https://img.shields.io/badge/GitHub-Contribute-green?logo=github&style=flat-square)](https://github.com/Tonic-AI)
2972
+
2973
+ 🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
2974
+ """
2975
+
2976
+ with gr.Blocks(title="Advanced Stock Prediction Analysis", theme=gr.themes.Base()) as demo:
2977
+ with gr.Row():
2978
+ gr.Markdown(title)
2979
+
2980
+ with gr.Row():
2981
+ with gr.Column(scale=1):
2982
+ with gr.Group():
2983
+ gr.Markdown(description)
2984
+ with gr.Column(scale=1):
2985
+ with gr.Group():
2986
+ gr.Markdown(model_info)
2987
+ gr.Markdown(join_us)
2988
+
2989
+ gr.Markdown("---") # Add a separator
2990
 
2991
  # Add market status message with periodic updates
2992
  market_status_display = gr.Markdown(
 
2996
  # Note: Market status updates automatically in the background thread every 10 minutes
2997
  # The display can be manually refreshed by users if needed
2998
 
2999
+ # Add simple market status check feature
3000
+ with gr.Accordion("🌎 Global Market Information", open=False)
3001
+ with gr.Column(scale=1):
3002
+ gr.Markdown("### 📊 Quick Market Status Check")
3003
+ # Create user-friendly market choices
3004
+ market_choices = [(config['name'], key) for key, config in MARKET_CONFIGS.items()]
3005
+ market_dropdown = gr.Dropdown(
3006
+ choices=market_choices,
3007
+ label="Select Market",
3008
+ value="US_STOCKS",
3009
+ info="Choose a market to check its current status"
3010
+ )
3011
+ check_market_btn = gr.Button("🔍 Check Market Status", variant="primary")
3012
+
3013
+ with gr.Column(scale=2):
3014
+ market_status_result = gr.Markdown(
3015
+ value="Select a market and click 'Check Market Status' to see current trading status.",
3016
+ label="Market Status Result"
3017
+ )
3018
+
3019
+ # Connect the button to the function
3020
+ check_market_btn.click(
3021
+ fn=check_market_status_simple,
3022
+ inputs=[market_dropdown],
3023
+ outputs=[market_status_result]
3024
+ )
3025
+
3026
+ gr.Markdown("---") # Add a separator
3027
 
3028
  # Add enhanced market information section
3029
  with gr.Accordion("🌍 Global Market Information", open=False):
 
4660
 
4661
  return market_summary
4662
 
4663
+ def check_market_status_simple(market_key: str) -> str:
4664
+ """
4665
+ Simple function to check market status for a specific market.
4666
+
4667
+ Args:
4668
+ market_key (str): Market key from MARKET_CONFIGS
4669
+
4670
+ Returns:
4671
+ str: Formatted market status information
4672
+ """
4673
+ try:
4674
+ # Get market status
4675
+ status = market_status_manager.get_status(market_key)
4676
+
4677
+ # Create a user-friendly display
4678
+ status_emoji = "🟢" if status.is_open else "🔴"
4679
+ status_text = "OPEN" if status.is_open else "CLOSED"
4680
+
4681
+ result = f"""
4682
+ ## {status_emoji} {status.market_name} Status: {status_text}
4683
+
4684
+ **Current Status:** {status.status_text}
4685
+
4686
+ **Market Details:**
4687
+ - **Type:** {status.market_type.title()}
4688
+ - **Symbol:** {status.market_symbol}
4689
+ - **Current Time:** {status.current_time_et}
4690
+ - **Last Updated:** {status.last_updated}
4691
+
4692
+ **Trading Information:**
4693
+ - **Next Trading Day:** {status.next_trading_day}
4694
+ - **Time Until Open:** {status.time_until_open}
4695
+ - **Time Until Close:** {status.time_until_close}
4696
+
4697
+ **Market Description:** {MARKET_CONFIGS[market_key]['description']}
4698
+ """
4699
+
4700
+ return result
4701
+
4702
+ except Exception as e:
4703
+ return f"❌ Error checking market status: {str(e)}"
4704
+
4705
  if __name__ == "__main__":
4706
  import signal
4707
  import atexit