Spaces:
Sleeping
Sleeping
Commit
·
6d4e8d7
1
Parent(s):
742aa68
replaced plotly with matplotlib
Browse files- .gitignore +1 -1
- app.py +71 -110
- requirements.txt +2 -1
.gitignore
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
__pycache__/
|
| 2 |
app_local.py
|
| 3 |
-
app_localBackup
|
|
|
|
| 1 |
__pycache__/
|
| 2 |
app_local.py
|
| 3 |
+
app_localBackup*.py
|
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import yfinance as yf
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
import os
|
| 8 |
from datetime import date, timedelta
|
| 9 |
|
|
@@ -217,8 +217,8 @@ else:
|
|
| 217 |
unsafe_allow_html=True,
|
| 218 |
)
|
| 219 |
|
| 220 |
-
price_tab, indicators_tab, ai_tab = st.tabs(["Price Action", "Technical Indicators", "AI Deep Dive"])
|
| 221 |
-
|
| 222 |
with price_tab:
|
| 223 |
st.subheader("Stock Price Chart")
|
| 224 |
st.caption("Candlestick price action with volume on a shared timeline for quick at-a-glance context.")
|
|
@@ -227,111 +227,72 @@ else:
|
|
| 227 |
st.write("Data sample:", df.head(3))
|
| 228 |
st.write("dtypes:", df.dtypes)
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
),
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
)
|
| 251 |
-
fig.
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
)
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
)
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
st.
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
avg_gain = gain.rolling(window=window_length, min_periods=1).mean()
|
| 297 |
-
avg_loss = loss.rolling(window=window_length, min_periods=1).mean()
|
| 298 |
-
|
| 299 |
-
rs = avg_gain / avg_loss
|
| 300 |
-
df['RSI'] = 100 - (100 / (1 + rs))
|
| 301 |
-
|
| 302 |
-
fig = go.Figure()
|
| 303 |
-
fig.add_trace(go.Scatter(x=df['Date'], y=df['RSI'], mode='lines', name='RSI', line=dict(color="#6dd6ff")))
|
| 304 |
-
fig.add_hline(y=70, line_dash="dash", line_color="#ff9b9b", annotation_text="Overbought")
|
| 305 |
-
fig.add_hline(y=30, line_dash="dash", line_color="#7cf0c6", annotation_text="Oversold")
|
| 306 |
-
fig.update_layout(
|
| 307 |
-
title="RSI Indicator",
|
| 308 |
-
xaxis_title="Date",
|
| 309 |
-
yaxis_title="RSI",
|
| 310 |
-
template="plotly_dark",
|
| 311 |
-
plot_bgcolor="rgba(12,19,32,0.7)",
|
| 312 |
-
paper_bgcolor="rgba(12,19,32,0.7)",
|
| 313 |
-
margin=dict(t=50, l=10, r=10, b=20),
|
| 314 |
-
)
|
| 315 |
-
fig.update_xaxes(showgrid=False)
|
| 316 |
-
fig.update_yaxes(gridcolor="rgba(255,255,255,0.08)")
|
| 317 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 318 |
-
|
| 319 |
-
st.subheader("Volume Analysis")
|
| 320 |
-
st.caption("Volume bars styled to match the rest of the dashboard.")
|
| 321 |
-
fig = go.Figure()
|
| 322 |
-
fig.add_trace(go.Bar(x=df['Date'], y=volume_series, name='Volume', marker_color="rgba(109, 214, 255, 0.55)"))
|
| 323 |
-
fig.update_layout(
|
| 324 |
-
title="Volume Analysis",
|
| 325 |
-
xaxis_title="Date",
|
| 326 |
-
yaxis_title="Volume",
|
| 327 |
-
template="plotly_dark",
|
| 328 |
-
plot_bgcolor="rgba(12,19,32,0.7)",
|
| 329 |
-
paper_bgcolor="rgba(12,19,32,0.7)",
|
| 330 |
-
margin=dict(t=50, l=10, r=10, b=20),
|
| 331 |
-
)
|
| 332 |
-
fig.update_xaxes(showgrid=False)
|
| 333 |
-
fig.update_yaxes(gridcolor="rgba(255,255,255,0.08)")
|
| 334 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 335 |
|
| 336 |
with ai_tab:
|
| 337 |
st.subheader("In-depth Analysis")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import yfinance as yf
|
| 3 |
import pandas as pd
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import mplfinance as mpf
|
| 6 |
+
import numpy as np
|
| 7 |
import os
|
| 8 |
from datetime import date, timedelta
|
| 9 |
|
|
|
|
| 217 |
unsafe_allow_html=True,
|
| 218 |
)
|
| 219 |
|
| 220 |
+
price_tab, indicators_tab, ai_tab = st.tabs(["Price Action", "Technical Indicators", "AI Deep Dive"])
|
| 221 |
+
|
| 222 |
with price_tab:
|
| 223 |
st.subheader("Stock Price Chart")
|
| 224 |
st.caption("Candlestick price action with volume on a shared timeline for quick at-a-glance context.")
|
|
|
|
| 227 |
st.write("Data sample:", df.head(3))
|
| 228 |
st.write("dtypes:", df.dtypes)
|
| 229 |
|
| 230 |
+
df_plot = df.set_index("Date")[["Open", "High", "Low", "Close", "Volume"]]
|
| 231 |
+
market_colors = mpf.make_marketcolors(up="#7cf0c6", down="#ff9b9b", edge="inherit", wick="inherit", volume="in")
|
| 232 |
+
style = mpf.make_mpf_style(base_mpf_style="nightclouds", marketcolors=market_colors, facecolor="#0c1320", edgecolor="#0c1320", gridcolor="#1b2a45")
|
| 233 |
+
fig, _ = mpf.plot(
|
| 234 |
+
df_plot,
|
| 235 |
+
type="candle",
|
| 236 |
+
volume=True,
|
| 237 |
+
style=style,
|
| 238 |
+
returnfig=True,
|
| 239 |
+
figsize=(10, 6),
|
| 240 |
+
tight_layout=True,
|
| 241 |
+
update_width_config=dict(candle_linewidth=0.8, candle_width=0.6),
|
| 242 |
+
)
|
| 243 |
+
st.pyplot(fig, clear_figure=True)
|
| 244 |
+
plt.close(fig)
|
| 245 |
+
|
| 246 |
+
with indicators_tab:
|
| 247 |
+
st.subheader("Moving Averages")
|
| 248 |
+
st.caption("Compare recent closes against short and intermediate trend lines.")
|
| 249 |
+
df['SMA_20'] = close_series.rolling(window=20).mean()
|
| 250 |
+
df['SMA_50'] = close_series.rolling(window=50).mean()
|
| 251 |
+
fig, ax = plt.subplots(figsize=(10, 4))
|
| 252 |
+
ax.plot(df['Date'], close_series, label='Close Price', color="#7cf0c6", linewidth=1.4)
|
| 253 |
+
ax.plot(df['Date'], df['SMA_20'], label='20-Day SMA', color="#6dd6ff", linewidth=1.2)
|
| 254 |
+
ax.plot(df['Date'], df['SMA_50'], label='50-Day SMA', color="#b0b8ff", linewidth=1.2)
|
| 255 |
+
ax.set_ylabel("Price (USD)")
|
| 256 |
+
ax.grid(alpha=0.2)
|
| 257 |
+
ax.legend()
|
| 258 |
+
fig.tight_layout()
|
| 259 |
+
st.pyplot(fig, clear_figure=True)
|
| 260 |
+
plt.close(fig)
|
| 261 |
+
|
| 262 |
+
st.subheader("Relative Strength Index (RSI)")
|
| 263 |
+
st.caption("Momentum oscillator highlighting overbought/oversold zones.")
|
| 264 |
+
window_length = 14
|
| 265 |
+
|
| 266 |
+
delta = close_series.diff()
|
| 267 |
+
gain = delta.where(delta > 0, 0)
|
| 268 |
+
loss = -delta.where(delta < 0, 0)
|
| 269 |
+
|
| 270 |
+
avg_gain = gain.rolling(window=window_length, min_periods=1).mean()
|
| 271 |
+
avg_loss = loss.rolling(window=window_length, min_periods=1).mean()
|
| 272 |
+
|
| 273 |
+
rs = avg_gain / avg_loss
|
| 274 |
+
df['RSI'] = 100 - (100 / (1 + rs))
|
| 275 |
+
|
| 276 |
+
fig, ax = plt.subplots(figsize=(10, 3.5))
|
| 277 |
+
ax.plot(df['Date'], df['RSI'], label='RSI', color="#6dd6ff", linewidth=1.4)
|
| 278 |
+
ax.axhline(70, color="#ff9b9b", linestyle="--", linewidth=1, label="Overbought")
|
| 279 |
+
ax.axhline(30, color="#7cf0c6", linestyle="--", linewidth=1, label="Oversold")
|
| 280 |
+
ax.set_ylabel("RSI")
|
| 281 |
+
ax.grid(alpha=0.2)
|
| 282 |
+
ax.legend()
|
| 283 |
+
fig.tight_layout()
|
| 284 |
+
st.pyplot(fig, clear_figure=True)
|
| 285 |
+
plt.close(fig)
|
| 286 |
+
|
| 287 |
+
st.subheader("Volume Analysis")
|
| 288 |
+
st.caption("Volume bars styled to match the rest of the dashboard.")
|
| 289 |
+
fig, ax = plt.subplots(figsize=(10, 3.5))
|
| 290 |
+
ax.bar(df['Date'], volume_series, color=(109/255, 214/255, 255/255, 0.55))
|
| 291 |
+
ax.set_ylabel("Volume")
|
| 292 |
+
ax.grid(alpha=0.15)
|
| 293 |
+
fig.tight_layout()
|
| 294 |
+
st.pyplot(fig, clear_figure=True)
|
| 295 |
+
plt.close(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
with ai_tab:
|
| 298 |
st.subheader("In-depth Analysis")
|
requirements.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
streamlit==1.52.1
|
| 2 |
yfinance
|
| 3 |
pandas==2.3.3
|
| 4 |
-
plotly==6.5.0
|
| 5 |
numpy==1.26.4
|
| 6 |
langchain-openai==0.2.9
|
|
|
|
|
|
|
|
|
| 1 |
streamlit==1.52.1
|
| 2 |
yfinance
|
| 3 |
pandas==2.3.3
|
|
|
|
| 4 |
numpy==1.26.4
|
| 5 |
langchain-openai==0.2.9
|
| 6 |
+
matplotlib
|
| 7 |
+
mplfinance
|