File size: 3,953 Bytes
f7323a3 |
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 |
"""Chart creation utilities for the financial dashboard."""
import plotly.graph_objects as go
import pandas as pd
def get_dark_theme_layout():
"""Get common dark theme layout settings for all charts."""
return dict(
plot_bgcolor="#0d1117",
paper_bgcolor="#0e1117",
font=dict(color="#e6edf3", size=12, family="Arial, sans-serif"),
xaxis=dict(
gridcolor="#30363d",
showgrid=True,
zeroline=False,
color="#8b949e"
),
yaxis=dict(
gridcolor="#30363d",
showgrid=True,
zeroline=False,
color="#8b949e"
),
legend=dict(
bgcolor="rgba(13, 17, 23, 0.8)",
bordercolor="#30363d",
borderwidth=1,
font=dict(color="#e6edf3")
),
hoverlabel=dict(
bgcolor="#0d1117",
bordercolor="#30363d",
font=dict(color="#e6edf3")
)
)
def create_price_chart(df: pd.DataFrame, symbol: str, period: int) -> go.Figure:
"""Create price chart with SMA and EMA indicators."""
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df.index, y=df["close"],
name="Close Price",
line=dict(color="#0066ff", width=2.5)
))
fig.add_trace(go.Scatter(
x=df.index, y=df["SMA"],
name=f"SMA {period}",
line=dict(color="#00d084", width=2, dash="dash")
))
fig.add_trace(go.Scatter(
x=df.index, y=df["EMA"],
name=f"EMA {period}",
line=dict(color="#ffa500", width=2, dash="dot")
))
layout = get_dark_theme_layout()
fig.update_layout(
title=f"{symbol} - Price with Moving Averages",
xaxis_title="Date",
yaxis_title="Price ($)",
hovermode="x unified",
template="plotly_dark",
height=500,
margin=dict(l=0, r=0, t=40, b=0),
**layout
)
return fig
def create_rsi_chart(df: pd.DataFrame, symbol: str) -> go.Figure:
"""Create RSI (Relative Strength Index) chart."""
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df.index, y=df["RSI"],
name="RSI",
line=dict(color="#ff3838", width=2.5),
fill="tozeroy",
fillcolor="rgba(255, 56, 56, 0.15)"
))
fig.add_hline(y=70, line_dash="dash", line_color="rgba(255, 165, 0, 0.6)",
annotation_text="Overbought (70)")
fig.add_hline(y=30, line_dash="dash", line_color="rgba(0, 208, 132, 0.6)",
annotation_text="Oversold (30)")
fig.add_hline(y=50, line_dash="dot", line_color="rgba(139, 148, 158, 0.3)")
layout = get_dark_theme_layout()
layout["yaxis"]["range"] = [0, 100]
fig.update_layout(
title=f"{symbol} - Relative Strength Index (RSI)",
xaxis_title="Date",
yaxis_title="RSI",
hovermode="x unified",
template="plotly_dark",
height=500,
margin=dict(l=0, r=0, t=40, b=0),
**layout
)
return fig
def create_financial_chart(income_data: pd.DataFrame) -> go.Figure:
"""Create financial revenue and net income chart."""
fig = go.Figure()
fig.add_trace(go.Bar(
x=income_data['period_ending'],
y=income_data['total_revenue'],
name="Total Revenue",
marker=dict(color='#0066ff', opacity=0.9),
yaxis='y1'
))
fig.add_trace(go.Bar(
x=income_data['period_ending'],
y=income_data['net_income'],
name="Net Income",
marker=dict(color='#00d084', opacity=0.9),
yaxis='y1'
))
layout = get_dark_theme_layout()
fig.update_layout(
title="Revenue & Net Income (Annual)",
xaxis_title="Period",
yaxis_title="Amount ($)",
hovermode="x unified",
template="plotly_dark",
height=400,
barmode='group',
margin=dict(l=0, r=0, t=40, b=0),
**layout
)
return fig
|