File size: 3,076 Bytes
021d91d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import streamlit as st
import numpy as np
from src.utils.visualization import create_technical_chart

def display_technical_analysis(price_data, symbol):
    """
    Hiển thị tab phân tích kỹ thuật
    
    Args:
        price_data: DataFrame chứa dữ liệu giá và các chỉ báo
        symbol: Mã cổ phiếu
    """
    st.markdown('<div class="tab-content">', unsafe_allow_html=True)
    
    # Metrics hiện tại
    latest_data = price_data.iloc[-1]
    prev_data = price_data.iloc[-2] if len(price_data) > 1 else latest_data
    
    col1, col2, col3, col4 = st.columns(4)
    
    with col1:
        price_change = latest_data['close'] - prev_data['close']
        price_change_pct = (price_change / prev_data['close']) * 100
        st.metric(
            "Giá hiện tại", 
            f"{latest_data['close']:,.0f} VND",
            f"{price_change:+,.0f} ({price_change_pct:+.2f}%)"
        )
    
    with col2:
        st.metric("Khối lượng", f"{latest_data['volume']:,.0f}")
    
    with col3:
        high_52w = price_data['high'].max()
        low_52w = price_data['low'].min()
        st.metric("Cao nhất 52W", f"{high_52w:,.0f}")
    
    with col4:
        st.metric("Thấp nhất 52W", f"{low_52w:,.0f}")
    
    # Biểu đồ giá
    st.subheader("📈 Biểu đồ Giá và Khối lượng")
    
    # Tạo biểu đồ kỹ thuật
    fig = create_technical_chart(price_data)
    fig.update_layout(title=f"Phân tích kỹ thuật {symbol}")
    
    st.plotly_chart(fig, use_container_width=True)
    
    # Phân tích kỹ thuật
    col1, col2 = st.columns(2)
    
    with col1:
        st.subheader("📊 Chỉ báo Kỹ thuật")
        
        latest_rsi = price_data['RSI'].iloc[-1]
        rsi_signal = "Quá mua" if latest_rsi > 70 else "Quá bán" if latest_rsi < 30 else "Trung tính"
        
        st.write(f"**RSI (14):** {latest_rsi:.2f} - {rsi_signal}")
        
        # So sánh SMA
        current_price = latest_data['close']
        sma_20 = price_data['SMA_20'].iloc[-1]
        sma_50 = price_data['SMA_50'].iloc[-1]
        
        sma_trend = "Tăng" if current_price > sma_20 > sma_50 else "Giảm" if current_price < sma_20 < sma_50 else "Sideway"
        st.write(f"**Xu hướng SMA:** {sma_trend}")
        st.write(f"**SMA 20:** {sma_20:.0f}")
        st.write(f"**SMA 50:** {sma_50:.0f}")
    
    with col2:
        st.subheader("📈 Thống kê Giá")
        
        volatility = (price_data['close'].pct_change().std() * np.sqrt(252) * 100)
        st.write(f"**Độ biến động (năm):** {volatility:.2f}%")
        
        avg_volume = price_data['volume'].mean()
        st.write(f"**KL trung bình:** {avg_volume:,.0f}")
        
        price_range = ((high_52w - low_52w) / low_52w) * 100
        st.write(f"**Biên độ 52W:** {price_range:.2f}%")
        
        current_vs_high = ((current_price - high_52w) / high_52w) * 100
        st.write(f"**So với đỉnh 52W:** {current_vs_high:.2f}%")
    
    st.markdown('</div>', unsafe_allow_html=True)