omniverse1 commited on
Commit
8e72523
·
verified ·
1 Parent(s): 72779a3

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +15 -9
utils.py CHANGED
@@ -192,6 +192,20 @@ def predict_prices(data, model=None, tokenizer=None, prediction_days=30):
192
  print(f"Error in prediction: {e}")
193
  return {'values': [], 'dates': [], 'high_30d': 0, 'low_30d': 0, 'mean_30d': 0, 'change_pct': 0, 'summary': f'Prediction unavailable due to model error: {e}'}
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def create_price_chart(data, indicators):
196
  fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.05, subplot_titles=('Price & Moving Averages', 'RSI', 'MACD'), row_width=[0.2, 0.2, 0.7])
197
  fig.add_trace(go.Candlestick(x=data.index, open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], name='Price'), row=1, col=1)
@@ -210,12 +224,4 @@ def create_technical_chart(data, indicators):
210
  fig.add_trace(go.Scatter(x=data.index, y=data['Close'], name='Price', line=dict(color='black')), row=1, col=1)
211
  fig.add_trace(go.Scatter(x=data.index, y=indicators['bollinger']['upper_values'], name='Upper Band', line=dict(color='red', width=1)), row=1, col=1)
212
  fig.add_trace(go.Scatter(x=data.index, y=indicators['bollinger']['lower_values'], name='Lower Band', line=dict(color='green', width=1), fill='tonexty', fillcolor='rgba(0,255,0,0.1)'), row=1, col=1)
213
- fig.add_trace(go.Bar(x=data.index, y=data['Volume'], name='Volume', marker_color='lightblue'), row=1, col=2)
214
- fig.add_trace(go.Scatter(x=data.index, y=data['Close'], name='Price', line=dict(color='gray')), row=2, col=1)
215
- fig.add_trace(go.Scatter(x=data.index, y=indicators['moving_averages']['sma_20_values'], name='SMA 20', line=dict(color='orange', dash='dash')), row=2, col=1)
216
- fig.add_trace(go.Scatter(x=data.index, y=indicators['moving_averages']['sma_50_values'], name='SMA 50', line=dict(color='blue', dash='dash')), row=2, col=1)
217
- fig.add_trace(go.Scatter(x=data.index, y=indicators['rsi']['values'], name='RSI', line=dict(color='purple')), row=2, col=2)
218
- fig.add_hline(y=70, line_dash="dash", line_color="red", row=2, col=2)
219
- fig.add_hline(y=30, line_dash="dash", line_color="green", row=2, col=2)
220
- fig.update_layout(title='Technical Indicators Overview', height=800, showlegend=False, hovermode='x unified')
221
- return fig
 
192
  print(f"Error in prediction: {e}")
193
  return {'values': [], 'dates': [], 'high_30d': 0, 'low_30d': 0, 'mean_30d': 0, 'change_pct': 0, 'summary': f'Prediction unavailable due to model error: {e}'}
194
 
195
+ def create_prediction_chart(data, predictions):
196
+ if not len(predictions['values']):
197
+ return go.Figure()
198
+ fig = go.Figure()
199
+ fig.add_trace(go.Scatter(x=data.index[-60:], y=data['Close'].values[-60:], name='Historical Price', line=dict(color='blue', width=2)))
200
+ fig.add_trace(go.Scatter(x=predictions['dates'], y=predictions['values'], name='AI Prediction', line=dict(color='red', width=2, dash='dash')))
201
+ pred_std = np.std(predictions['values'])
202
+ upper_band = predictions['values'] + (pred_std * 1.96)
203
+ lower_band = predictions['values'] - (pred_std * 1.96)
204
+ fig.add_trace(go.Scatter(x=predictions['dates'], y=upper_band, name='Upper Band', line=dict(color='lightcoral', width=1), fill=None))
205
+ fig.add_trace(go.Scatter(x=predictions['dates'], y=lower_band, name='Lower Band', line=dict(color='lightcoral', width=1), fill='tonexty', fillcolor='rgba(255,182,193,0.2)'))
206
+ fig.update_layout(title=f'Price Prediction - Next {len(predictions["dates"])} Days', xaxis_title='Date', yaxis_title='Price (IDR)', hovermode='x unified', height=500)
207
+ return fig
208
+
209
  def create_price_chart(data, indicators):
210
  fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.05, subplot_titles=('Price & Moving Averages', 'RSI', 'MACD'), row_width=[0.2, 0.2, 0.7])
211
  fig.add_trace(go.Candlestick(x=data.index, open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], name='Price'), row=1, col=1)
 
224
  fig.add_trace(go.Scatter(x=data.index, y=data['Close'], name='Price', line=dict(color='black')), row=1, col=1)
225
  fig.add_trace(go.Scatter(x=data.index, y=indicators['bollinger']['upper_values'], name='Upper Band', line=dict(color='red', width=1)), row=1, col=1)
226
  fig.add_trace(go.Scatter(x=data.index, y=indicators['bollinger']['lower_values'], name='Lower Band', line=dict(color='green', width=1), fill='tonexty', fillcolor='rgba(0,255,0,0.1)'), row=1, col=1)
227
+ fig.add_trace(go.Bar(x=data.index,