Tonic commited on
Commit
8828171
·
1 Parent(s): 73dceb0

fix output figure returns

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -104,7 +104,7 @@ def calculate_bollinger_bands(prices: pd.Series, period: int = 20, std_dev: int
104
  return upper_band, middle_band, lower_band
105
 
106
  @spaces.GPU
107
- def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5, strategy: str = "chronos") -> Dict:
108
  """
109
  Make prediction using selected strategy.
110
 
@@ -115,7 +115,7 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
115
  strategy (str): Prediction strategy to use
116
 
117
  Returns:
118
- dict: Prediction results and visualization
119
  """
120
  try:
121
  # Get historical data
@@ -133,7 +133,7 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
133
  prediction = pipe.predict(
134
  context=context,
135
  prediction_length=prediction_days,
136
- num_samples=100 # Increased samples for better uncertainty estimation
137
  ).detach().cpu().numpy()
138
 
139
  mean_pred = prediction.mean(axis=0)
@@ -228,14 +228,15 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
228
  # Calculate trading signals
229
  signals = calculate_trading_signals(df)
230
 
231
- return {
 
232
  "symbol": symbol,
233
  "prediction": mean_pred.tolist(),
234
  "confidence": std_pred.tolist(),
235
- "dates": pred_dates.strftime('%Y-%m-%d').tolist(),
236
- "plot": fig,
237
- "signals": signals
238
- }
239
 
240
  except Exception as e:
241
  raise Exception(f"Prediction error: {str(e)}")
 
104
  return upper_band, middle_band, lower_band
105
 
106
  @spaces.GPU
107
+ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5, strategy: str = "chronos") -> Tuple[Dict, go.Figure]:
108
  """
109
  Make prediction using selected strategy.
110
 
 
115
  strategy (str): Prediction strategy to use
116
 
117
  Returns:
118
+ Tuple[Dict, go.Figure]: Trading signals and visualization plot
119
  """
120
  try:
121
  # Get historical data
 
133
  prediction = pipe.predict(
134
  context=context,
135
  prediction_length=prediction_days,
136
+ num_samples=100
137
  ).detach().cpu().numpy()
138
 
139
  mean_pred = prediction.mean(axis=0)
 
228
  # Calculate trading signals
229
  signals = calculate_trading_signals(df)
230
 
231
+ # Add prediction information to signals
232
+ signals.update({
233
  "symbol": symbol,
234
  "prediction": mean_pred.tolist(),
235
  "confidence": std_pred.tolist(),
236
+ "dates": pred_dates.strftime('%Y-%m-%d').tolist()
237
+ })
238
+
239
+ return signals, fig
240
 
241
  except Exception as e:
242
  raise Exception(f"Prediction error: {str(e)}")