Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1219,6 +1219,9 @@ if len(item_df) < 2:
|
|
1219 |
else:
|
1220 |
st.success(f"μ νν νλͺ© '{selected_item}'μ λν΄ {len(item_df)}κ°μ λ°μ΄ν°κ° μμ΅λλ€.")
|
1221 |
|
|
|
|
|
|
|
1222 |
# -------------------------------------------------
|
1223 |
# MACRO FORECAST 1996β2030 ------------------------
|
1224 |
# -------------------------------------------------
|
@@ -1332,20 +1335,51 @@ else:
|
|
1332 |
# μ°¨νΈ νμ
|
1333 |
st.plotly_chart(fig, use_container_width=True)
|
1334 |
|
1335 |
-
#
|
1336 |
try:
|
1337 |
latest_price = macro_df.iloc[-1]["price"]
|
1338 |
-
# 2030λ
λ§μ§λ§ μ μ°ΎκΈ°
|
1339 |
-
target_date = pd.Timestamp("2030-12-31")
|
1340 |
-
close_dates = fc_macro.loc[(fc_macro["ds"] - target_date).abs().argsort()[:1], "ds"].values[0]
|
1341 |
-
macro_pred = fc_macro.loc[fc_macro["ds"] == close_dates, "yhat"].iloc[0]
|
1342 |
-
macro_pct = (macro_pred - latest_price) / latest_price * 100
|
1343 |
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1349 |
except Exception as e:
|
1350 |
st.error(f"μμΈ‘κ° κ³μ° μ€λ₯: {str(e)}")
|
1351 |
else:
|
@@ -1363,6 +1397,9 @@ else:
|
|
1363 |
fig.update_layout(title=f"{selected_item} κ³Όκ±° κ°κ²©")
|
1364 |
st.plotly_chart(fig, use_container_width=True)
|
1365 |
|
|
|
|
|
|
|
1366 |
# -------------------------------------------------
|
1367 |
# MICRO FORECAST 2024β2026 ------------------------
|
1368 |
# -------------------------------------------------
|
@@ -1506,27 +1543,90 @@ else:
|
|
1506 |
hide_index=True
|
1507 |
)
|
1508 |
|
1509 |
-
#
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
close_dates = monthly_forecast.loc[(monthly_forecast["ds"] - target_date).abs().argsort()[:1], "ds"].values[0]
|
1516 |
-
micro_pred = monthly_forecast.loc[monthly_forecast["ds"] == close_dates, "yhat"].iloc[0]
|
1517 |
-
micro_pct = (micro_pred - latest_price) / latest_price * 100
|
1518 |
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1526 |
else:
|
1527 |
st.warning("λ¨κΈ° μμΈ‘ λͺ¨λΈμ μμ±ν μ μμ΅λλ€.")
|
1528 |
except Exception as e:
|
1529 |
st.error(f"λ¨κΈ° μμΈ‘ μ€λ₯: {str(e)}")
|
|
|
1530 |
|
1531 |
# -------------------------------------------------
|
1532 |
# SEASONALITY & PATTERN ---------------------------
|
|
|
1219 |
else:
|
1220 |
st.success(f"μ νν νλͺ© '{selected_item}'μ λν΄ {len(item_df)}κ°μ λ°μ΄ν°κ° μμ΅λλ€.")
|
1221 |
|
1222 |
+
# -------------------------------------------------
|
1223 |
+
# MACRO FORECAST 1996β2030 ------------------------
|
1224 |
+
# -------------------------------------------------
|
1225 |
# -------------------------------------------------
|
1226 |
# MACRO FORECAST 1996β2030 ------------------------
|
1227 |
# -------------------------------------------------
|
|
|
1335 |
# μ°¨νΈ νμ
|
1336 |
st.plotly_chart(fig, use_container_width=True)
|
1337 |
|
1338 |
+
# μ°λλ³ μμΈ‘κ° νμ
|
1339 |
try:
|
1340 |
latest_price = macro_df.iloc[-1]["price"]
|
|
|
|
|
|
|
|
|
|
|
1341 |
|
1342 |
+
# μ°λλ³ μμΈ‘κ° κ³μ°μ μν ν¨μ
|
1343 |
+
def get_yearly_prediction(year_end):
|
1344 |
+
target_date = pd.Timestamp(f"{year_end}-12-31")
|
1345 |
+
# λ μ§ κΈ°λ°μΌλ‘ κ°μ₯ κ°κΉμ΄ λ μ§μ μμΈ‘κ° μ°ΎκΈ°
|
1346 |
+
date_diffs = abs(fc_macro["ds"] - target_date)
|
1347 |
+
closest_idx = date_diffs.idxmin()
|
1348 |
+
pred_value = fc_macro.loc[closest_idx, "yhat"]
|
1349 |
+
pct_change = (pred_value - latest_price) / latest_price * 100
|
1350 |
+
return pred_value, pct_change
|
1351 |
+
|
1352 |
+
# μ°λλ³ μμΈ‘κ° νμ
|
1353 |
+
col1, col2, col3 = st.columns(3)
|
1354 |
+
|
1355 |
+
# 2025λ
μμΈ‘κ°
|
1356 |
+
pred_2025, pct_2025 = get_yearly_prediction(2025)
|
1357 |
+
col1.metric("2025λ
μμΈ‘κ°", format_currency(pred_2025), f"{pct_2025:+.1f}%")
|
1358 |
+
|
1359 |
+
# 2027λ
μμΈ‘κ°
|
1360 |
+
pred_2027, pct_2027 = get_yearly_prediction(2027)
|
1361 |
+
col2.metric("2027λ
μμΈ‘κ°", format_currency(pred_2027), f"{pct_2027:+.1f}%")
|
1362 |
+
|
1363 |
+
# 2030λ
μμΈ‘κ°
|
1364 |
+
pred_2030, pct_2030 = get_yearly_prediction(2030)
|
1365 |
+
col3.metric("2030λ
μμΈ‘κ°", format_currency(pred_2030), f"{pct_2030:+.1f}%")
|
1366 |
+
|
1367 |
+
# μΆκ° μ°λ μμΈ‘κ° (νμ₯ κ°λ₯)
|
1368 |
+
with st.expander("λ λ§μ μ°λλ³ μμΈ‘κ° λ³΄κΈ°"):
|
1369 |
+
col4, col5, col6 = st.columns(3)
|
1370 |
+
|
1371 |
+
# 2026λ
μμΈ‘κ°
|
1372 |
+
pred_2026, pct_2026 = get_yearly_prediction(2026)
|
1373 |
+
col4.metric("2026λ
μμΈ‘κ°", format_currency(pred_2026), f"{pct_2026:+.1f}%")
|
1374 |
+
|
1375 |
+
# 2028λ
μμΈ‘κ°
|
1376 |
+
pred_2028, pct_2028 = get_yearly_prediction(2028)
|
1377 |
+
col5.metric("2028λ
μμΈ‘κ°", format_currency(pred_2028), f"{pct_2028:+.1f}%")
|
1378 |
+
|
1379 |
+
# 2029λ
μμΈ‘κ°
|
1380 |
+
pred_2029, pct_2029 = get_yearly_prediction(2029)
|
1381 |
+
col6.metric("2029λ
μμΈ‘κ°", format_currency(pred_2029), f"{pct_2029:+.1f}%")
|
1382 |
+
|
1383 |
except Exception as e:
|
1384 |
st.error(f"μμΈ‘κ° κ³μ° μ€λ₯: {str(e)}")
|
1385 |
else:
|
|
|
1397 |
fig.update_layout(title=f"{selected_item} κ³Όκ±° κ°κ²©")
|
1398 |
st.plotly_chart(fig, use_container_width=True)
|
1399 |
|
1400 |
+
# -------------------------------------------------
|
1401 |
+
# MICRO FORECAST 2024β2026 ------------------------
|
1402 |
+
# -------------------------------------------------
|
1403 |
# -------------------------------------------------
|
1404 |
# MICRO FORECAST 2024β2026 ------------------------
|
1405 |
# -------------------------------------------------
|
|
|
1543 |
hide_index=True
|
1544 |
)
|
1545 |
|
1546 |
+
# μλ³/οΏ½οΏ½οΏ½λλ³ μμΈ‘κ° νμ ν¨μ
|
1547 |
+
def get_monthly_prediction(year, month):
|
1548 |
+
target_date = pd.Timestamp(f"{year}-{month:02d}-01")
|
1549 |
+
# κ°μ₯ κ°κΉμ΄ λ μ§μ μμΈ‘κ° μ°ΎκΈ°
|
1550 |
+
date_diffs = abs(monthly_forecast["ds"] - target_date)
|
1551 |
+
closest_idx = date_diffs.idxmin()
|
|
|
|
|
|
|
1552 |
|
1553 |
+
if closest_idx in monthly_forecast.index:
|
1554 |
+
pred_value = monthly_forecast.loc[closest_idx, "yhat"]
|
1555 |
+
|
1556 |
+
# νμ¬ κ°κ²© κΈ°μ€ λ³νμ¨ κ³μ°
|
1557 |
+
latest_price = monthly_historical.iloc[-1]["price"] if not monthly_historical.empty else micro_df.iloc[-1]["price"]
|
1558 |
+
pct_change = (pred_value - latest_price) / latest_price * 100
|
1559 |
+
|
1560 |
+
return pred_value, pct_change
|
1561 |
+
else:
|
1562 |
+
return None, None
|
1563 |
+
|
1564 |
+
# 2025λ
κ³Ό 2026λ
μ μ£Όμ μλ³ μμΈ‘κ°
|
1565 |
+
st.subheader("μ£Όμ μλ³ μμΈ‘κ°")
|
1566 |
+
|
1567 |
+
col1, col2, col3 = st.columns(3)
|
1568 |
+
|
1569 |
+
# 2025λ
6μ μμΈ‘κ°
|
1570 |
+
pred_2025_06, pct_2025_06 = get_monthly_prediction(2025, 6)
|
1571 |
+
if pred_2025_06 is not None:
|
1572 |
+
col1.metric("2025λ
6μ", format_currency(pred_2025_06), f"{pct_2025_06:+.1f}%")
|
1573 |
+
else:
|
1574 |
+
col1.metric("2025λ
6μ", "λ°μ΄ν° μμ", "0%")
|
1575 |
+
|
1576 |
+
# 2025λ
12μ μμΈ‘κ°
|
1577 |
+
pred_2025_12, pct_2025_12 = get_monthly_prediction(2025, 12)
|
1578 |
+
if pred_2025_12 is not None:
|
1579 |
+
col2.metric("2025λ
12μ", format_currency(pred_2025_12), f"{pct_2025_12:+.1f}%")
|
1580 |
+
else:
|
1581 |
+
col2.metric("2025λ
12μ", "λ°μ΄ν° μμ", "0%")
|
1582 |
+
|
1583 |
+
# 2026λ
12μ μμΈ‘κ°
|
1584 |
+
pred_2026_12, pct_2026_12 = get_monthly_prediction(2026, 12)
|
1585 |
+
if pred_2026_12 is not None:
|
1586 |
+
col3.metric("2026λ
12μ", format_currency(pred_2026_12), f"{pct_2026_12:+.1f}%")
|
1587 |
+
else:
|
1588 |
+
col3.metric("2026λ
12μ", "λ°μ΄ν° μμ", "0%")
|
1589 |
+
|
1590 |
+
# λμ°λ¬Ό κ³μ μ±μ λ§λ μΆκ° μλ³ λ°μ΄ν° νμ
|
1591 |
+
with st.expander("λ λ§μ μλ³ μμΈ‘κ° λ³΄κΈ°"):
|
1592 |
+
# λΆκΈ°λ³λ‘ λλ μ νμ
|
1593 |
+
for year in [2025, 2026]:
|
1594 |
+
st.write(f"### {year}λ
λΆκΈ°λ³ μμΈ‘κ°")
|
1595 |
+
q1, q2, q3, q4 = st.columns(4)
|
1596 |
+
|
1597 |
+
# 1λΆκΈ° (3μ)
|
1598 |
+
pred_q1, pct_q1 = get_monthly_prediction(year, 3)
|
1599 |
+
if pred_q1 is not None:
|
1600 |
+
q1.metric(f"{year}λ
3μ", format_currency(pred_q1), f"{pct_q1:+.1f}%")
|
1601 |
+
else:
|
1602 |
+
q1.metric(f"{year}λ
3μ", "λ°μ΄ν° μμ", "0%")
|
1603 |
+
|
1604 |
+
# 2λΆκΈ° (6μ)
|
1605 |
+
pred_q2, pct_q2 = get_monthly_prediction(year, 6)
|
1606 |
+
if pred_q2 is not None:
|
1607 |
+
q2.metric(f"{year}λ
6μ", format_currency(pred_q2), f"{pct_q2:+.1f}%")
|
1608 |
+
else:
|
1609 |
+
q2.metric(f"{year}λ
6μ", "λ°μ΄ν° μμ", "0%")
|
1610 |
+
|
1611 |
+
# 3λΆκΈ° (9μ)
|
1612 |
+
pred_q3, pct_q3 = get_monthly_prediction(year, 9)
|
1613 |
+
if pred_q3 is not None:
|
1614 |
+
q3.metric(f"{year}λ
9μ", format_currency(pred_q3), f"{pct_q3:+.1f}%")
|
1615 |
+
else:
|
1616 |
+
q3.metric(f"{year}λ
9μ", "λ°μ΄ν° μμ", "0%")
|
1617 |
+
|
1618 |
+
# 4λΆκΈ° (12μ)
|
1619 |
+
pred_q4, pct_q4 = get_monthly_prediction(year, 12)
|
1620 |
+
if pred_q4 is not None:
|
1621 |
+
q4.metric(f"{year}λ
12μ", format_currency(pred_q4), f"{pct_q4:+.1f}%")
|
1622 |
+
else:
|
1623 |
+
q4.metric(f"{year}λ
12μ", "λ°μ΄ν° μμ", "0%")
|
1624 |
+
|
1625 |
else:
|
1626 |
st.warning("λ¨κΈ° μμΈ‘ λͺ¨λΈμ μμ±ν μ μμ΅λλ€.")
|
1627 |
except Exception as e:
|
1628 |
st.error(f"λ¨κΈ° μμΈ‘ μ€λ₯: {str(e)}")
|
1629 |
+
st.code(traceback.format_exc())
|
1630 |
|
1631 |
# -------------------------------------------------
|
1632 |
# SEASONALITY & PATTERN ---------------------------
|