Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -312,8 +312,8 @@ def plot_price_chart(ticker: str):
|
|
| 312 |
|
| 313 |
predicted_price = last_known_price * (1 + predicted_return)
|
| 314 |
|
| 315 |
-
|
| 316 |
-
plt.figure(figsize=(
|
| 317 |
plt.plot(historical_dates, historical_prices, label='Historical Prices', marker='o')
|
| 318 |
plt.axvline(x=last_known_date, color='gray', linestyle='--', label='Last Known Date')
|
| 319 |
plt.plot([last_known_date, predicted_date], [last_known_price, predicted_price], 'r--', label='Predicted Price')
|
|
@@ -326,18 +326,24 @@ def plot_price_chart(ticker: str):
|
|
| 326 |
plt.annotate(f'Last Known Price: {last_known_price:.2f}',
|
| 327 |
xy=(last_known_date, last_known_price),
|
| 328 |
xytext=(last_known_date, last_known_price * 1.05),
|
| 329 |
-
arrowprops=dict(facecolor='black', arrowstyle='->')
|
|
|
|
| 330 |
|
| 331 |
plt.annotate(f'Predicted Price: {predicted_price:.2f}\nPredicted Return: {predicted_return:.2%}',
|
| 332 |
xy=(predicted_date, predicted_price),
|
| 333 |
xytext=(predicted_date, predicted_price * 1.05),
|
| 334 |
-
arrowprops=dict(facecolor='red', arrowstyle='->')
|
|
|
|
| 335 |
|
| 336 |
plt.xlabel('Date')
|
| 337 |
plt.ylabel('Price')
|
| 338 |
plt.title(f'{ticker} Price Chart with Predicted Price')
|
| 339 |
plt.legend()
|
| 340 |
plt.grid(True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
# Save plot to a bytes buffer
|
| 343 |
buf = BytesIO()
|
|
|
|
| 312 |
|
| 313 |
predicted_price = last_known_price * (1 + predicted_return)
|
| 314 |
|
| 315 |
+
# Plot the data
|
| 316 |
+
plt.figure(figsize=(12, 6)) # Increase figure size to give more space for annotations
|
| 317 |
plt.plot(historical_dates, historical_prices, label='Historical Prices', marker='o')
|
| 318 |
plt.axvline(x=last_known_date, color='gray', linestyle='--', label='Last Known Date')
|
| 319 |
plt.plot([last_known_date, predicted_date], [last_known_price, predicted_price], 'r--', label='Predicted Price')
|
|
|
|
| 326 |
plt.annotate(f'Last Known Price: {last_known_price:.2f}',
|
| 327 |
xy=(last_known_date, last_known_price),
|
| 328 |
xytext=(last_known_date, last_known_price * 1.05),
|
| 329 |
+
arrowprops=dict(facecolor='black', arrowstyle='->'),
|
| 330 |
+
bbox=dict(boxstyle='round,pad=0.5', edgecolor='black', facecolor='white'))
|
| 331 |
|
| 332 |
plt.annotate(f'Predicted Price: {predicted_price:.2f}\nPredicted Return: {predicted_return:.2%}',
|
| 333 |
xy=(predicted_date, predicted_price),
|
| 334 |
xytext=(predicted_date, predicted_price * 1.05),
|
| 335 |
+
arrowprops=dict(facecolor='red', arrowstyle='->'),
|
| 336 |
+
bbox=dict(boxstyle='round,pad=0.5', edgecolor='red', facecolor='white'))
|
| 337 |
|
| 338 |
plt.xlabel('Date')
|
| 339 |
plt.ylabel('Price')
|
| 340 |
plt.title(f'{ticker} Price Chart with Predicted Price')
|
| 341 |
plt.legend()
|
| 342 |
plt.grid(True)
|
| 343 |
+
|
| 344 |
+
# Adjust limits to ensure annotations fit
|
| 345 |
+
plt.ylim(bottom=min(historical_prices) * 0.95, top=max(historical_prices) * 1.1)
|
| 346 |
+
plt.xlim(left=min(historical_dates), right=predicted_date + pd.Timedelta(days=10))
|
| 347 |
|
| 348 |
# Save plot to a bytes buffer
|
| 349 |
buf = BytesIO()
|