Update app.py
Browse files
app.py
CHANGED
|
@@ -277,7 +277,7 @@ def create_stock_chart(ticker, period="1mo"):
|
|
| 277 |
else:
|
| 278 |
raise dl_error
|
| 279 |
|
| 280 |
-
if stock_data
|
| 281 |
logging.warning(f"No stock data found for ticker: {ticker}")
|
| 282 |
return None
|
| 283 |
|
|
@@ -288,27 +288,59 @@ def create_stock_chart(ticker, period="1mo"):
|
|
| 288 |
# ๊ทธ๋ํ ์์ฑ
|
| 289 |
fig, ax = plt.subplots(figsize=(10, 6))
|
| 290 |
|
| 291 |
-
# ์ข
๊ฐ ๊ทธ๋ํ
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
else:
|
| 310 |
-
#
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
# ์ฐจํธ ์คํ์ผ๋ง
|
| 314 |
ax.set_title(f"{ticker} Stock Price")
|
|
|
|
| 277 |
else:
|
| 278 |
raise dl_error
|
| 279 |
|
| 280 |
+
if len(stock_data) == 0:
|
| 281 |
logging.warning(f"No stock data found for ticker: {ticker}")
|
| 282 |
return None
|
| 283 |
|
|
|
|
| 288 |
# ๊ทธ๋ํ ์์ฑ
|
| 289 |
fig, ax = plt.subplots(figsize=(10, 6))
|
| 290 |
|
| 291 |
+
# ์ข
๊ฐ ๊ทธ๋ํ - ๋ฉํฐ์ธ๋ฑ์ค ์ฒ๋ฆฌ
|
| 292 |
+
if isinstance(stock_data.columns, pd.MultiIndex):
|
| 293 |
+
# ๋ฉํฐ์ธ๋ฑ์ค์ธ ๊ฒฝ์ฐ ('Close', ticker) ํํ
|
| 294 |
+
close_col = ('Close', ticker)
|
| 295 |
+
if close_col in stock_data.columns:
|
| 296 |
+
ax.plot(stock_data.index, stock_data[close_col], label='Close Price', color='blue')
|
| 297 |
+
|
| 298 |
+
# ์ด๋ํ๊ท ์ ์ถ๊ฐ (20์ผ)
|
| 299 |
+
if len(stock_data) > 20:
|
| 300 |
+
stock_data['MA20'] = stock_data[close_col].rolling(window=20).mean()
|
| 301 |
+
ax.plot(stock_data.index, stock_data['MA20'], label='20-day MA', color='orange')
|
| 302 |
+
|
| 303 |
+
# ๊ฑฐ๋๋ ์๋ธํ๋กฏ ์ถ๊ฐ (๊ฑฐ๋๋์ด ์๋ ๊ฒฝ์ฐ๋ง)
|
| 304 |
+
volume_col = ('Volume', ticker)
|
| 305 |
+
if volume_col in stock_data.columns and not stock_data[volume_col].isna().all():
|
| 306 |
+
ax2 = ax.twinx()
|
| 307 |
+
ax2.bar(stock_data.index, stock_data[volume_col], alpha=0.3, color='gray', label='Volume')
|
| 308 |
+
ax2.set_ylabel('Volume')
|
| 309 |
+
|
| 310 |
+
# ๋ฒ๋ก ์ถ๊ฐ (๊ฑฐ๋๋ ์๋ ๊ฒฝ์ฐ)
|
| 311 |
+
lines, labels = ax.get_legend_handles_labels()
|
| 312 |
+
lines2, labels2 = ax2.get_legend_handles_labels()
|
| 313 |
+
ax.legend(lines + lines2, labels + labels2, loc='upper left')
|
| 314 |
+
else:
|
| 315 |
+
# ๊ฑฐ๋๋ ์๋ ๊ฒฝ์ฐ ์ข
๊ฐ๋ง ํ์
|
| 316 |
+
ax.legend(loc='upper left')
|
| 317 |
+
else:
|
| 318 |
+
raise ValueError(f"Close column not found in data columns: {stock_data.columns}")
|
| 319 |
else:
|
| 320 |
+
# ์ผ๋ฐ ์ธ๋ฑ์ค์ธ ๊ฒฝ์ฐ
|
| 321 |
+
if 'Close' in stock_data.columns:
|
| 322 |
+
ax.plot(stock_data.index, stock_data['Close'], label='Close Price', color='blue')
|
| 323 |
+
|
| 324 |
+
# ์ด๋ํ๊ท ์ ์ถ๊ฐ (20์ผ)
|
| 325 |
+
if len(stock_data) > 20:
|
| 326 |
+
stock_data['MA20'] = stock_data['Close'].rolling(window=20).mean()
|
| 327 |
+
ax.plot(stock_data.index, stock_data['MA20'], label='20-day MA', color='orange')
|
| 328 |
+
|
| 329 |
+
# ๊ฑฐ๋๋ ์๋ธํ๋กฏ ์ถ๊ฐ (๊ฑฐ๋๋์ด ์๋ ๊ฒฝ์ฐ๋ง)
|
| 330 |
+
if 'Volume' in stock_data.columns and not stock_data['Volume'].isna().all():
|
| 331 |
+
ax2 = ax.twinx()
|
| 332 |
+
ax2.bar(stock_data.index, stock_data['Volume'], alpha=0.3, color='gray', label='Volume')
|
| 333 |
+
ax2.set_ylabel('Volume')
|
| 334 |
+
|
| 335 |
+
# ๋ฒ๋ก ์ถ๊ฐ (๊ฑฐ๋๋ ์๋ ๊ฒฝ์ฐ)
|
| 336 |
+
lines, labels = ax.get_legend_handles_labels()
|
| 337 |
+
lines2, labels2 = ax2.get_legend_handles_labels()
|
| 338 |
+
ax.legend(lines + lines2, labels + labels2, loc='upper left')
|
| 339 |
+
else:
|
| 340 |
+
# ๊ฑฐ๋๋ ์๋ ๊ฒฝ์ฐ ์ข
๊ฐ๋ง ํ์
|
| 341 |
+
ax.legend(loc='upper left')
|
| 342 |
+
else:
|
| 343 |
+
raise ValueError(f"Close column not found in data columns: {stock_data.columns}")
|
| 344 |
|
| 345 |
# ์ฐจํธ ์คํ์ผ๋ง
|
| 346 |
ax.set_title(f"{ticker} Stock Price")
|