Spaces:
Sleeping
Sleeping
File size: 4,490 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
def create_technical_chart(price_data):
"""
Tạo biểu đồ phân tích kỹ thuật với giá, khối lượng và RSI
Args:
price_data: DataFrame chứa dữ liệu giá và các chỉ báo
Returns:
Đối tượng biểu đồ Plotly
"""
# Tạo subplot
fig = make_subplots(
rows=3, cols=1,
shared_xaxes=True,
vertical_spacing=0.05,
subplot_titles=('Giá cổ phiếu', 'Khối lượng', 'RSI'),
row_heights=[0.6, 0.2, 0.2]
)
# Biểu đồ nến
fig.add_trace(
go.Candlestick(
x=price_data['time'],
open=price_data['open'],
high=price_data['high'],
low=price_data['low'],
close=price_data['close'],
name="Giá"
), row=1, col=1
)
# Thêm SMA
fig.add_trace(
go.Scatter(
x=price_data['time'],
y=price_data['SMA_20'],
mode='lines',
name='SMA 20',
line=dict(color='#4CAF50', width=2)
), row=1, col=1
)
fig.add_trace(
go.Scatter(
x=price_data['time'],
y=price_data['SMA_50'],
mode='lines',
name='SMA 50',
line=dict(color='#8C52FF', width=2)
), row=1, col=1
)
# Biểu đồ khối lượng
colors = ['#4CAF50' if close >= open else '#FF5252'
for close, open in zip(price_data['close'], price_data['open'])]
fig.add_trace(
go.Bar(
x=price_data['time'],
y=price_data['volume'],
name='Khối lượng',
marker_color=colors
), row=2, col=1
)
# RSI
fig.add_trace(
go.Scatter(
x=price_data['time'],
y=price_data['RSI'],
mode='lines',
name='RSI',
line=dict(color='#8C52FF', width=2)
), row=3, col=1
)
# Thêm đường RSI 30 và 70
fig.add_hline(y=30, line_dash="dash", line_color="red", row=3, col=1)
fig.add_hline(y=70, line_dash="dash", line_color="red", row=3, col=1)
fig.update_layout(
height=800,
xaxis_rangeslider_visible=False,
template="plotly_white"
)
return fig
def create_revenue_profit_chart(income, year_col, revenue_col, profit_col):
"""
Tạo biểu đồ doanh thu và lợi nhuận
Args:
income: DataFrame chứa dữ liệu báo cáo kết quả kinh doanh
year_col: Tên cột chứa năm
revenue_col: Tên cột chứa doanh thu
profit_col: Tên cột chứa lợi nhuận
Returns:
Đối tượng biểu đồ Plotly
"""
fig = go.Figure()
fig.add_trace(go.Scatter(
x=income[year_col],
y=income[revenue_col],
mode='lines+markers',
name='Doanh thu',
line=dict(color='#4CAF50', width=3)
))
fig.add_trace(go.Scatter(
x=income[year_col],
y=income[profit_col],
mode='lines+markers',
name='Lợi nhuận',
line=dict(color='#8C52FF', width=3)
))
fig.update_layout(
title="Doanh thu và Lợi nhuận (Tỷ đồng)",
xaxis_title="Năm",
yaxis_title="Tỷ đồng",
template="plotly_white"
)
return fig
def create_return_chart(ratio, year_col, roe_col, roa_col):
"""
Tạo biểu đồ ROE và ROA
Args:
ratio: DataFrame chứa dữ liệu chỉ số tài chính
year_col: Tên cột chứa năm
roe_col: Tên cột chứa ROE
roa_col: Tên cột chứa ROA
Returns:
Đối tượng biểu đồ Plotly
"""
fig = go.Figure()
fig.add_trace(go.Scatter(
x=ratio[year_col],
y=ratio[roe_col],
mode='lines+markers',
name='ROE (%)',
line=dict(color='#4CAF50', width=3)
))
fig.add_trace(go.Scatter(
x=ratio[year_col],
y=ratio[roa_col],
mode='lines+markers',
name='ROA (%)',
line=dict(color='#8C52FF', width=3)
))
fig.update_layout(
title="Tỷ suất Sinh lời (%)",
xaxis_title="Năm",
yaxis_title="Phần trăm (%)",
template="plotly_white"
)
return fig |