omniverse1 commited on
Commit
68974cf
·
verified ·
1 Parent(s): fc0fb8b

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +18 -3
utils.py CHANGED
@@ -136,7 +136,22 @@ def get_fundamental_data(stock):
136
  try:
137
  info = stock.info
138
  history = stock.history(period="1d")
139
- fundamental_info = {'name': info.get('longName', 'N/A'), 'current_price': history['Close'].iloc[-1] if not history.empty else 0, 'market_cap': info.get('marketCap', 0), 'pe_ratio': info.get('forwardPE', 0), 'dividend_yield': info.get('dividendYield', 0) * 100 if info.get('dividendYield') else 0, 'volume': history['Volume'].iloc[-1] if not history.empty else 0, 'info': f"Sector: {info.get('sector', 'N/A')}\nIndustry: {info.get('industry', 'N/A')}\nMarket Cap: {info.get('marketCap', 0)}\n52 Week High: {info.get('fiftyTwoWeekHigh', 'N/A')}\n52 Week Low: {info.get('fiftyTwoWeekLow', 'N/A')}\nBeta: {info.get('beta', 'N/A')}\nEPS: {info.get('forwardEps', 'N/A')}\nBook Value: {info.get('bookValue', 'N/A')}\nPrice to Book: {info.get('priceToBook', 'N/A')}"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  return fundamental_info
141
  except:
142
  return {'name': 'N/A', 'current_price': 0, 'market_cap': 0, 'pe_ratio': 0, 'dividend_yield': 0, 'volume': 0, 'info': 'Unable to fetch fundamental data'}
@@ -160,7 +175,6 @@ def predict_prices(data, model=None, tokenizer=None, prediction_days=30):
160
  from chronos import BaseChronosPipeline
161
  pipeline = BaseChronosPipeline.from_pretrained("amazon/chronos-bolt-base", device_map="auto")
162
  with torch.no_grad():
163
- # Fix: Use context_tensor instead of context
164
  forecast = pipeline.predict(context_tensor=torch.tensor(prices), prediction_length=prediction_days)
165
  forecast_np = forecast.squeeze().cpu().numpy() if isinstance(forecast, torch.Tensor) else np.array(forecast)
166
  if forecast_np.ndim > 1:
@@ -215,4 +229,5 @@ def create_technical_chart(data, indicators):
215
  fig.add_hline(y=70, line_dash="dash", line_color="red", row=2, col=2)
216
  fig.add_hline(y=30, line_dash="dash", line_color="green", row=2, col=2)
217
  fig.update_layout(title='Technical Indicators Overview', height=800, showlegend=False, hovermode='x unified')
218
- return fig
 
 
136
  try:
137
  info = stock.info
138
  history = stock.history(period="1d")
139
+
140
+ raw_price = history['Close'].iloc[-1] if not history.empty else 0
141
+ raw_market_cap = info.get('marketCap', 0)
142
+ raw_pe = info.get('forwardPE', 0)
143
+ raw_div_yield = info.get('dividendYield', 0) * 100 if info.get('dividendYield') else 0
144
+ raw_volume = history['Volume'].iloc[-1] if not history.empty else 0
145
+
146
+ fundamental_info = {
147
+ 'name': info.get('longName', 'N/A'),
148
+ 'current_price': float(raw_price),
149
+ 'market_cap': int(raw_market_cap),
150
+ 'pe_ratio': float(raw_pe),
151
+ 'dividend_yield': float(raw_div_yield),
152
+ 'volume': int(raw_volume),
153
+ 'info': f"Sector: {info.get('sector', 'N/A')}\nIndustry: {info.get('industry', 'N/A')}\nMarket Cap: {int(raw_market_cap):,}\n52 Week High: {info.get('fiftyTwoWeekHigh', 'N/A')}\n52 Week Low: {info.get('fiftyTwoWeekLow', 'N/A')}\nBeta: {info.get('beta', 'N/A')}\nEPS: {info.get('forwardEps', 'N/A')}\nBook Value: {info.get('bookValue', 'N/A')}\nPrice to Book: {info.get('priceToBook', 'N/A')}"
154
+ }
155
  return fundamental_info
156
  except:
157
  return {'name': 'N/A', 'current_price': 0, 'market_cap': 0, 'pe_ratio': 0, 'dividend_yield': 0, 'volume': 0, 'info': 'Unable to fetch fundamental data'}
 
175
  from chronos import BaseChronosPipeline
176
  pipeline = BaseChronosPipeline.from_pretrained("amazon/chronos-bolt-base", device_map="auto")
177
  with torch.no_grad():
 
178
  forecast = pipeline.predict(context_tensor=torch.tensor(prices), prediction_length=prediction_days)
179
  forecast_np = forecast.squeeze().cpu().numpy() if isinstance(forecast, torch.Tensor) else np.array(forecast)
180
  if forecast_np.ndim > 1:
 
229
  fig.add_hline(y=70, line_dash="dash", line_color="red", row=2, col=2)
230
  fig.add_hline(y=30, line_dash="dash", line_color="green", row=2, col=2)
231
  fig.update_layout(title='Technical Indicators Overview', height=800, showlegend=False, hovermode='x unified')
232
+ return fig
233
+