Tonic commited on
Commit
355ef3b
·
unverified ·
1 Parent(s): ae7bc70

adds historical and predicted price data

Browse files
Files changed (1) hide show
  1. app.py +40 -13
app.py CHANGED
@@ -2098,6 +2098,11 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
2098
  'uncertainty': final_uncertainty.tolist(),
2099
  'volume': volume_pred.tolist() if volume_pred is not None else None
2100
  },
 
 
 
 
 
2101
  'technical_indicators': {
2102
  'predictions': {k: v.tolist() for k, v in technical_predictions.items()},
2103
  'uncertainties': {k: v.tolist() for k, v in technical_uncertainties.items()}
@@ -3407,6 +3412,8 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3407
 
3408
  with gr.Column():
3409
  daily_plot = gr.Plot(label="Analysis and Prediction")
 
 
3410
 
3411
  with gr.Row():
3412
  with gr.Column():
@@ -3474,6 +3481,8 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3474
  with gr.Column():
3475
  hourly_plot = gr.Plot(label="Analysis and Prediction")
3476
  hourly_signals = gr.JSON(label="Trading Signals")
 
 
3477
 
3478
  with gr.Row():
3479
  with gr.Column():
@@ -3539,6 +3548,8 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3539
  with gr.Column():
3540
  min15_plot = gr.Plot(label="Analysis and Prediction")
3541
  min15_signals = gr.JSON(label="Trading Signals")
 
 
3542
 
3543
  with gr.Row():
3544
  with gr.Column():
@@ -3681,7 +3692,11 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3681
 
3682
  advanced_signals = signals.get("advanced_signals", {})
3683
 
3684
- return basic_signals, fig, product_metrics, risk_metrics, sector_metrics, regime_metrics, stress_results, ensemble_metrics, advanced_signals
 
 
 
 
3685
  except Exception as e:
3686
  error_message = str(e)
3687
  if "Market is currently closed" in error_message:
@@ -3696,7 +3711,7 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3696
  def daily_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3697
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3698
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3699
- uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3700
  """
3701
  Process daily timeframe stock analysis with enhanced features.
3702
 
@@ -3743,7 +3758,7 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3743
  When True, includes news sentiment analysis in the prediction model
3744
 
3745
  Returns:
3746
- Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3747
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3748
  Contains RSI, MACD, Bollinger Bands, SMA, and overall trading signals
3749
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
@@ -3762,13 +3777,17 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3762
  Ensemble method configuration and performance results
3763
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3764
  Advanced trading signals with confidence levels and sophisticated indicators
 
 
 
 
3765
 
3766
  Raises:
3767
  gr.Error: If data cannot be fetched, insufficient data points, or other analysis errors
3768
  Common errors include invalid symbols, market closure, or insufficient historical data
3769
 
3770
  Example:
3771
- >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced = daily_analysis(
3772
  ... "AAPL", 30, 365, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3, True, True
3773
  ... )
3774
 
@@ -3792,14 +3811,14 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3792
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha,
3793
  use_covariates, use_sentiment],
3794
  outputs=[daily_signals, daily_plot, daily_metrics, daily_risk_metrics, daily_sector_metrics,
3795
- daily_regime_metrics, daily_stress_results, daily_ensemble_metrics, daily_signals_advanced]
3796
  )
3797
 
3798
  # Hourly analysis button click
3799
  def hourly_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3800
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3801
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3802
- uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3803
  """
3804
  Process hourly timeframe stock analysis with enhanced features.
3805
 
@@ -3848,7 +3867,7 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3848
  When True, includes news sentiment analysis in the prediction model
3849
 
3850
  Returns:
3851
- Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3852
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3853
  Basic trading signals optimized for hourly timeframes
3854
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
@@ -3867,13 +3886,17 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3867
  Ensemble analysis configuration and results
3868
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3869
  Advanced signals with intraday-specific indicators
 
 
 
 
3870
 
3871
  Raises:
3872
  gr.Error: If market is closed, insufficient data, or analysis errors
3873
  Hourly data is only available during market hours (9:30 AM - 4:00 PM ET)
3874
 
3875
  Example:
3876
- >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced = hourly_analysis(
3877
  ... "AAPL", 3, 14, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3, True, True
3878
  ... )
3879
 
@@ -3898,14 +3921,14 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3898
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha,
3899
  use_covariates, use_sentiment],
3900
  outputs=[hourly_signals, hourly_plot, hourly_metrics, hourly_risk_metrics, hourly_sector_metrics,
3901
- hourly_regime_metrics, hourly_stress_results, hourly_ensemble_metrics, hourly_signals_advanced]
3902
  )
3903
 
3904
  # 15-minute analysis button click
3905
  def min15_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3906
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3907
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3908
- uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3909
  """
3910
  Process 15-minute timeframe stock analysis with enhanced features.
3911
 
@@ -3951,7 +3974,7 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3951
  Alpha parameter for exponential smoothing methods
3952
 
3953
  Returns:
3954
- Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3955
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3956
  Basic trading signals optimized for 15-minute timeframes
3957
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
@@ -3970,13 +3993,17 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
3970
  Ensemble analysis configuration and results
3971
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3972
  Advanced signals with 15-minute-specific indicators
 
 
 
 
3973
 
3974
  Raises:
3975
  gr.Error: If market is closed, insufficient data points, or analysis errors
3976
  15-minute data requires at least 64 data points and is only available during market hours
3977
 
3978
  Example:
3979
- >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced = min15_analysis(
3980
  ... "AAPL", 1, 3, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3
3981
  ... )
3982
 
@@ -4000,7 +4027,7 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
4000
  chronos_weight, technical_weight, statistical_weight,
4001
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha],
4002
  outputs=[min15_signals, min15_plot, min15_metrics, min15_risk_metrics, min15_sector_metrics,
4003
- min15_regime_metrics, min15_stress_results, min15_ensemble_metrics, min15_signals_advanced]
4004
  )
4005
 
4006
  return demo
 
2098
  'uncertainty': final_uncertainty.tolist(),
2099
  'volume': volume_pred.tolist() if volume_pred is not None else None
2100
  },
2101
+ 'historical': {
2102
+ 'dates': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
2103
+ 'prices': df['Close'].tolist(),
2104
+ 'volume': df['Volume'].tolist() if 'Volume' in df.columns else None
2105
+ },
2106
  'technical_indicators': {
2107
  'predictions': {k: v.tolist() for k, v in technical_predictions.items()},
2108
  'uncertainties': {k: v.tolist() for k, v in technical_uncertainties.items()}
 
3412
 
3413
  with gr.Column():
3414
  daily_plot = gr.Plot(label="Analysis and Prediction")
3415
+ daily_historical_json = gr.JSON(label="Historical Data")
3416
+ daily_predicted_json = gr.JSON(label="Predicted Data")
3417
 
3418
  with gr.Row():
3419
  with gr.Column():
 
3481
  with gr.Column():
3482
  hourly_plot = gr.Plot(label="Analysis and Prediction")
3483
  hourly_signals = gr.JSON(label="Trading Signals")
3484
+ hourly_historical_json = gr.JSON(label="Historical Data")
3485
+ hourly_predicted_json = gr.JSON(label="Predicted Data")
3486
 
3487
  with gr.Row():
3488
  with gr.Column():
 
3548
  with gr.Column():
3549
  min15_plot = gr.Plot(label="Analysis and Prediction")
3550
  min15_signals = gr.JSON(label="Trading Signals")
3551
+ min15_historical_json = gr.JSON(label="Historical Data")
3552
+ min15_predicted_json = gr.JSON(label="Predicted Data")
3553
 
3554
  with gr.Row():
3555
  with gr.Column():
 
3692
 
3693
  advanced_signals = signals.get("advanced_signals", {})
3694
 
3695
+ # In analyze_stock, extract historical and predicted values for UI
3696
+ historical = signals.get('historical', {})
3697
+ predicted = signals.get('prediction', {})
3698
+
3699
+ return basic_signals, fig, product_metrics, risk_metrics, sector_metrics, regime_metrics, stress_results, ensemble_metrics, advanced_signals, historical, predicted
3700
  except Exception as e:
3701
  error_message = str(e)
3702
  if "Market is currently closed" in error_message:
 
3711
  def daily_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3712
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3713
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3714
+ uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3715
  """
3716
  Process daily timeframe stock analysis with enhanced features.
3717
 
 
3758
  When True, includes news sentiment analysis in the prediction model
3759
 
3760
  Returns:
3761
+ Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3762
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3763
  Contains RSI, MACD, Bollinger Bands, SMA, and overall trading signals
3764
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
 
3777
  Ensemble method configuration and performance results
3778
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3779
  Advanced trading signals with confidence levels and sophisticated indicators
3780
+ [9] Dict: Historical Data - Output value for the "Historical Data" Json component
3781
+ Historical data for the selected stock
3782
+ [10] Dict: Predicted Data - Output value for the "Predicted Data" Json component
3783
+ Predicted data for the selected stock
3784
 
3785
  Raises:
3786
  gr.Error: If data cannot be fetched, insufficient data points, or other analysis errors
3787
  Common errors include invalid symbols, market closure, or insufficient historical data
3788
 
3789
  Example:
3790
+ >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced, historical, predicted = daily_analysis(
3791
  ... "AAPL", 30, 365, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3, True, True
3792
  ... )
3793
 
 
3811
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha,
3812
  use_covariates, use_sentiment],
3813
  outputs=[daily_signals, daily_plot, daily_metrics, daily_risk_metrics, daily_sector_metrics,
3814
+ daily_regime_metrics, daily_stress_results, daily_ensemble_metrics, daily_signals_advanced, daily_historical_json, daily_predicted_json]
3815
  )
3816
 
3817
  # Hourly analysis button click
3818
  def hourly_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3819
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3820
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3821
+ uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3822
  """
3823
  Process hourly timeframe stock analysis with enhanced features.
3824
 
 
3867
  When True, includes news sentiment analysis in the prediction model
3868
 
3869
  Returns:
3870
+ Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3871
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3872
  Basic trading signals optimized for hourly timeframes
3873
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
 
3886
  Ensemble analysis configuration and results
3887
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3888
  Advanced signals with intraday-specific indicators
3889
+ [9] Dict: Historical Data - Output value for the "Historical Data" Json component
3890
+ Historical data for the selected stock
3891
+ [10] Dict: Predicted Data - Output value for the "Predicted Data" Json component
3892
+ Predicted data for the selected stock
3893
 
3894
  Raises:
3895
  gr.Error: If market is closed, insufficient data, or analysis errors
3896
  Hourly data is only available during market hours (9:30 AM - 4:00 PM ET)
3897
 
3898
  Example:
3899
+ >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced, historical, predicted = hourly_analysis(
3900
  ... "AAPL", 3, 14, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3, True, True
3901
  ... )
3902
 
 
3921
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha,
3922
  use_covariates, use_sentiment],
3923
  outputs=[hourly_signals, hourly_plot, hourly_metrics, hourly_risk_metrics, hourly_sector_metrics,
3924
+ hourly_regime_metrics, hourly_stress_results, hourly_ensemble_metrics, hourly_signals_advanced, hourly_historical_json, hourly_predicted_json]
3925
  )
3926
 
3927
  # 15-minute analysis button click
3928
  def min15_analysis(s: str, pd: int, ld: int, st: str, ue: bool, urd: bool, ust: bool,
3929
  rfr: float, mi: str, cw: float, tw: float, sw: float,
3930
  rrp: int, usm: bool, smt: str, sww: float, sa: float,
3931
+ uc: bool, us: bool) -> Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]:
3932
  """
3933
  Process 15-minute timeframe stock analysis with enhanced features.
3934
 
 
3974
  Alpha parameter for exponential smoothing methods
3975
 
3976
  Returns:
3977
+ Tuple[Dict, go.Figure, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict, Dict]: Analysis results containing:
3978
  [0] Dict: Trading Signals - Output value for the "Trading Signals" Json component
3979
  Basic trading signals optimized for 15-minute timeframes
3980
  [1] go.Figure: Analysis and Prediction - Output value for the "Analysis and Prediction" Plot component
 
3993
  Ensemble analysis configuration and results
3994
  [8] Dict: Advanced Trading Signals - Output value for the "Advanced Trading Signals" Json component
3995
  Advanced signals with 15-minute-specific indicators
3996
+ [9] Dict: Historical Data - Output value for the "Historical Data" Json component
3997
+ Historical data for the selected stock
3998
+ [10] Dict: Predicted Data - Output value for the "Predicted Data" Json component
3999
+ Predicted data for the selected stock
4000
 
4001
  Raises:
4002
  gr.Error: If market is closed, insufficient data points, or analysis errors
4003
  15-minute data requires at least 64 data points and is only available during market hours
4004
 
4005
  Example:
4006
+ >>> signals, plot, metrics, risk, sector, regime, stress, ensemble, advanced, historical, predicted = min15_analysis(
4007
  ... "AAPL", 1, 3, "chronos", True, True, True, 0.02, "^GSPC", 0.6, 0.2, 0.2, 4, True, "exponential", 5, 0.3
4008
  ... )
4009
 
 
4027
  chronos_weight, technical_weight, statistical_weight,
4028
  random_real_points, use_smoothing, smoothing_type, smoothing_window, smoothing_alpha],
4029
  outputs=[min15_signals, min15_plot, min15_metrics, min15_risk_metrics, min15_sector_metrics,
4030
+ min15_regime_metrics, min15_stress_results, min15_ensemble_metrics, min15_signals_advanced, min15_historical_json, min15_predicted_json]
4031
  )
4032
 
4033
  return demo