Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,35 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
-
from playwright.sync_api import sync_playwright
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
with sync_playwright() as p:
|
| 12 |
-
browser = p.chromium.launch(headless=True)
|
| 13 |
-
page = browser.new_page()
|
| 14 |
-
page.goto("https://www.barchart.com/options/unusual-activity/stocks", timeout=60000)
|
| 15 |
-
page.wait_for_selector("table")
|
| 16 |
-
html = page.content()
|
| 17 |
-
browser.close()
|
| 18 |
-
return html
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
table = soup.find("table")
|
| 24 |
-
rows = table.find_all("tr")
|
| 25 |
-
data = []
|
| 26 |
-
for row in rows[1:]:
|
| 27 |
-
cols = [col.text.strip() for col in row.find_all("td")]
|
| 28 |
-
if cols:
|
| 29 |
-
data.append(cols)
|
| 30 |
-
df = pd.DataFrame(data)
|
| 31 |
-
st.dataframe(df)
|
| 32 |
-
except Exception as e:
|
| 33 |
-
st.error(f"Lỗi: {e}")
|
|
|
|
| 1 |
+
import yfinance as yf
|
| 2 |
import streamlit as st
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
# Hàm phân tích VSA và xác suất tăng, giảm ngày hôm sau (kết hợp)
|
| 6 |
+
def combined_vsa_probability(ticker):
|
| 7 |
+
data = yf.download(ticker, period='5d', interval='1d')
|
| 8 |
+
|
| 9 |
+
latest_day = data.iloc[-1]
|
| 10 |
+
open_price = latest_day['Open'].item()
|
| 11 |
+
current_price = latest_day['Close'].item() if latest_day.name.time().strftime('%H:%M') >= '16:00' else yf.Ticker(ticker).history(period="1d", interval="1m").iloc[-1]['Close'].item()
|
| 12 |
+
volume = latest_day['Volume'].item()
|
| 13 |
+
avg_volume = data['Volume'].iloc[-4:-1].mean().item()
|
| 14 |
+
|
| 15 |
+
spread = latest_day['High'].item() - latest_day['Low'].item()
|
| 16 |
+
close_position = (current_price - latest_day['Low'].item()) / spread
|
| 17 |
+
|
| 18 |
+
# Điều kiện kết hợp VSA & xác suất
|
| 19 |
+
if (current_price > open_price) and (volume > avg_volume) and close_position > 0.7:
|
| 20 |
+
probability = "Bullish (Strength): Xác suất ~75-80% tăng tiếp"
|
| 21 |
+
elif (current_price >= open_price) and close_position > 0.5 and volume >= avg_volume:
|
| 22 |
+
probability = "Bullish (Possible Strength): Xác suất ~60-65% tăng tiếp"
|
| 23 |
+
elif (current_price < open_price) and close_position < 0.3 and volume >= avg_volume:
|
| 24 |
+
probability = "Bearish (Weakness): Xác suất cao giảm hôm sau"
|
| 25 |
+
else:
|
| 26 |
+
probability = "Sideway hoặc chưa rõ tín hiệu: Quan sát thêm"
|
| 27 |
+
|
| 28 |
+
return probability
|
| 29 |
|
| 30 |
+
# Streamlit app
|
| 31 |
+
st.title("Dự đoán xác suất tăng/giảm hôm sau (Kết hợp VSA) cho SPY & QQQ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
for ticker in ["QQQ", "SPY"]:
|
| 34 |
+
probability = combined_vsa_probability(ticker)
|
| 35 |
+
st.subheader(f"{ticker}: {probability}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|