Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from datetime import datetime, timedelta
|
|
| 10 |
import joblib
|
| 11 |
import os
|
| 12 |
import re
|
|
|
|
| 13 |
|
| 14 |
# Define stock tickers
|
| 15 |
STOCK_TICKERS = [
|
|
@@ -228,8 +229,8 @@ def stock_prediction_app(ticker: str, start_date: str, end_date: str):
|
|
| 228 |
decision = buy_or_sell(current_price, predicted_price)
|
| 229 |
|
| 230 |
# Plotting historical prices and predicted tomorrow's price
|
| 231 |
-
plt.figure(figsize=(
|
| 232 |
-
plt.plot(data['Close'], label='Historical Close Price')
|
| 233 |
|
| 234 |
# Add predicted price for tomorrow
|
| 235 |
tomorrow_date = data.index[-1] + timedelta(days=1)
|
|
@@ -237,12 +238,21 @@ def stock_prediction_app(ticker: str, start_date: str, end_date: str):
|
|
| 237 |
while tomorrow_date.weekday() >= 5: # Saturday=5, Sunday=6
|
| 238 |
tomorrow_date += timedelta(days=1)
|
| 239 |
|
| 240 |
-
plt.scatter(tomorrow_date, predicted_price, color='red', label='Predicted Close Price (Tomorrow)')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
plt.title(f'{ticker} Price Prediction for Tomorrow')
|
| 242 |
plt.xlabel('Date')
|
| 243 |
plt.ylabel('Price ($)')
|
| 244 |
plt.legend()
|
|
|
|
| 245 |
plt.tight_layout()
|
|
|
|
|
|
|
| 246 |
fig = plt.gcf()
|
| 247 |
plt.close()
|
| 248 |
|
|
|
|
| 10 |
import joblib
|
| 11 |
import os
|
| 12 |
import re
|
| 13 |
+
import matplotlib.dates as mdates
|
| 14 |
|
| 15 |
# Define stock tickers
|
| 16 |
STOCK_TICKERS = [
|
|
|
|
| 229 |
decision = buy_or_sell(current_price, predicted_price)
|
| 230 |
|
| 231 |
# Plotting historical prices and predicted tomorrow's price
|
| 232 |
+
plt.figure(figsize=(12, 6))
|
| 233 |
+
plt.plot(data.index, data['Close'], label='Historical Close Price', color='blue')
|
| 234 |
|
| 235 |
# Add predicted price for tomorrow
|
| 236 |
tomorrow_date = data.index[-1] + timedelta(days=1)
|
|
|
|
| 238 |
while tomorrow_date.weekday() >= 5: # Saturday=5, Sunday=6
|
| 239 |
tomorrow_date += timedelta(days=1)
|
| 240 |
|
| 241 |
+
plt.scatter(tomorrow_date, predicted_price, color='red', label='Predicted Close Price (Tomorrow)', zorder=5)
|
| 242 |
+
|
| 243 |
+
# Formatting the x-axis with better date formatting
|
| 244 |
+
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
|
| 245 |
+
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
| 246 |
+
plt.xticks(rotation=45)
|
| 247 |
+
|
| 248 |
plt.title(f'{ticker} Price Prediction for Tomorrow')
|
| 249 |
plt.xlabel('Date')
|
| 250 |
plt.ylabel('Price ($)')
|
| 251 |
plt.legend()
|
| 252 |
+
plt.grid(True, linestyle='--', alpha=0.5)
|
| 253 |
plt.tight_layout()
|
| 254 |
+
|
| 255 |
+
# Create the figure
|
| 256 |
fig = plt.gcf()
|
| 257 |
plt.close()
|
| 258 |
|