Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,21 +46,24 @@ if symbols_input:
|
|
| 46 |
stock_data = yf.download(symbol, period=period)['Close']
|
| 47 |
etf_data = yf.download(etf, period=period)['Close']
|
| 48 |
|
| 49 |
-
if
|
| 50 |
-
results.append({"Symbol": symbol, "Sector ETF": etf, "Kết luận": "
|
| 51 |
continue
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
df = pd.DataFrame(results)
|
| 66 |
st.dataframe(df)
|
|
|
|
| 46 |
stock_data = yf.download(symbol, period=period)['Close']
|
| 47 |
etf_data = yf.download(etf, period=period)['Close']
|
| 48 |
|
| 49 |
+
if stock_data is None or stock_data.empty or etf_data is None or etf_data.empty:
|
| 50 |
+
results.append({"Symbol": symbol, "Sector ETF": etf, "Kết luận": "Không có dữ liệu"})
|
| 51 |
continue
|
| 52 |
|
| 53 |
+
if len(stock_data) >= 2 and len(etf_data) >= 2:
|
| 54 |
+
pct_stock = (stock_data.iloc[-1] - stock_data.iloc[0]) / stock_data.iloc[0] * 100
|
| 55 |
+
pct_sector = (etf_data.iloc[-1] - etf_data.iloc[0]) / etf_data.iloc[0] * 100
|
| 56 |
+
verdict = "Outperform" if pct_stock > pct_sector else "Underperform"
|
| 57 |
|
| 58 |
+
results.append({
|
| 59 |
+
"Symbol": symbol,
|
| 60 |
+
"Sector ETF": etf,
|
| 61 |
+
"% Stock": f"{pct_stock:.2f}%",
|
| 62 |
+
"% Sector": f"{pct_sector:.2f}%",
|
| 63 |
+
"Kết luận": verdict
|
| 64 |
+
})
|
| 65 |
+
else:
|
| 66 |
+
results.append({"Symbol": symbol, "Sector ETF": etf, "Kết luận": "Dữ liệu không đủ"})
|
| 67 |
|
| 68 |
df = pd.DataFrame(results)
|
| 69 |
st.dataframe(df)
|