Spaces:
Running
Running
Faham
commited on
Commit
Β·
b92bfe9
1
Parent(s):
1b7aca0
FIX: system monitor bugs
Browse files- Home.py +10 -10
- pages/System_Monitor.py +52 -4
Home.py
CHANGED
|
@@ -409,9 +409,9 @@ def calculate_rsi(data, window):
|
|
| 409 |
|
| 410 |
|
| 411 |
def create_stock_chart(ticker: str):
|
| 412 |
-
"""Create an interactive stock price chart with
|
| 413 |
try:
|
| 414 |
-
# Get stock data - 5 years for training
|
| 415 |
with st.spinner(f"π Fetching stock data for {ticker}..."):
|
| 416 |
stock = yf.Ticker(ticker)
|
| 417 |
hist_data = stock.history(period="5y")
|
|
@@ -424,7 +424,7 @@ def create_stock_chart(ticker: str):
|
|
| 424 |
st.warning(f"No data available for {ticker}")
|
| 425 |
return None
|
| 426 |
|
| 427 |
-
# Prepare data for
|
| 428 |
df = hist_data.reset_index()
|
| 429 |
|
| 430 |
# Flatten the multi-level column index if it exists
|
|
@@ -614,9 +614,9 @@ def create_stock_chart(ticker: str):
|
|
| 614 |
# Track training time
|
| 615 |
training_time = time.time() - start_time
|
| 616 |
if RESOURCE_MONITORING_AVAILABLE:
|
| 617 |
-
resource_monitor.
|
| 618 |
training_time
|
| 619 |
-
) #
|
| 620 |
|
| 621 |
# Get the best alpha value for display
|
| 622 |
best_alpha = grid_search.best_params_["alpha"]
|
|
@@ -843,6 +843,10 @@ def create_stock_chart(ticker: str):
|
|
| 843 |
# Make predictions for the next 30 trading days
|
| 844 |
future_predictions = model.predict(X_future_scaled)
|
| 845 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
# Create interactive chart with historical data and future predictions
|
| 847 |
fig = go.Figure()
|
| 848 |
|
|
@@ -876,7 +880,7 @@ def create_stock_chart(ticker: str):
|
|
| 876 |
|
| 877 |
# Update layout
|
| 878 |
fig.update_layout(
|
| 879 |
-
title=f"{ticker} Stock Price with Next 30-Day
|
| 880 |
xaxis_title="Date",
|
| 881 |
yaxis_title="Price ($)",
|
| 882 |
height=500,
|
|
@@ -935,9 +939,6 @@ def create_stock_chart(ticker: str):
|
|
| 935 |
st.info(
|
| 936 |
f"""
|
| 937 |
**π 30-Day Ridge Regression Prediction for {ticker}:**
|
| 938 |
-
- **Current Price:** ${current_price:.2f}
|
| 939 |
-
- **Predicted Price (30 days):** ${predicted_price_30d:.2f}
|
| 940 |
-
- **Expected Change:** ${price_change:.2f} ({price_change_pct:+.2f}%)
|
| 941 |
- **Model Performance (Historical Fit):**
|
| 942 |
- RΒ² Score: {r2_historical:.4f} ({r2_historical*100:.2f}% accuracy)
|
| 943 |
- Mean Squared Error: {mse_historical:.4f}
|
|
@@ -945,7 +946,6 @@ def create_stock_chart(ticker: str):
|
|
| 945 |
- Cross-Validation Score: {best_score:.4f}
|
| 946 |
- **Model Training Time:** {training_time:.2f}s
|
| 947 |
- **Training Data:** 5 years of historical data
|
| 948 |
-
- **Features Used:** {', '.join(features)}
|
| 949 |
|
| 950 |
β οΈ **Disclaimer**: Stock predictions have approximately 70% accuracy.
|
| 951 |
These forecasts are for informational purposes only and should not be used as
|
|
|
|
| 409 |
|
| 410 |
|
| 411 |
def create_stock_chart(ticker: str):
|
| 412 |
+
"""Create an interactive stock price chart with Ridge Regression predictions for the given ticker."""
|
| 413 |
try:
|
| 414 |
+
# Get stock data - 5 years for training Ridge Regression
|
| 415 |
with st.spinner(f"π Fetching stock data for {ticker}..."):
|
| 416 |
stock = yf.Ticker(ticker)
|
| 417 |
hist_data = stock.history(period="5y")
|
|
|
|
| 424 |
st.warning(f"No data available for {ticker}")
|
| 425 |
return None
|
| 426 |
|
| 427 |
+
# Prepare data for Ridge Regression with technical indicators
|
| 428 |
df = hist_data.reset_index()
|
| 429 |
|
| 430 |
# Flatten the multi-level column index if it exists
|
|
|
|
| 614 |
# Track training time
|
| 615 |
training_time = time.time() - start_time
|
| 616 |
if RESOURCE_MONITORING_AVAILABLE:
|
| 617 |
+
resource_monitor.add_ridge_training_time(
|
| 618 |
training_time
|
| 619 |
+
) # Updated method name
|
| 620 |
|
| 621 |
# Get the best alpha value for display
|
| 622 |
best_alpha = grid_search.best_params_["alpha"]
|
|
|
|
| 843 |
# Make predictions for the next 30 trading days
|
| 844 |
future_predictions = model.predict(X_future_scaled)
|
| 845 |
|
| 846 |
+
# Track ML predictions
|
| 847 |
+
if RESOURCE_MONITORING_AVAILABLE:
|
| 848 |
+
resource_monitor.increment_ml_predictions()
|
| 849 |
+
|
| 850 |
# Create interactive chart with historical data and future predictions
|
| 851 |
fig = go.Figure()
|
| 852 |
|
|
|
|
| 880 |
|
| 881 |
# Update layout
|
| 882 |
fig.update_layout(
|
| 883 |
+
title=f"{ticker} Stock Price with Next 30-Day Ridge Regression Predictions",
|
| 884 |
xaxis_title="Date",
|
| 885 |
yaxis_title="Price ($)",
|
| 886 |
height=500,
|
|
|
|
| 939 |
st.info(
|
| 940 |
f"""
|
| 941 |
**π 30-Day Ridge Regression Prediction for {ticker}:**
|
|
|
|
|
|
|
|
|
|
| 942 |
- **Model Performance (Historical Fit):**
|
| 943 |
- RΒ² Score: {r2_historical:.4f} ({r2_historical*100:.2f}% accuracy)
|
| 944 |
- Mean Squared Error: {mse_historical:.4f}
|
|
|
|
| 946 |
- Cross-Validation Score: {best_score:.4f}
|
| 947 |
- **Model Training Time:** {training_time:.2f}s
|
| 948 |
- **Training Data:** 5 years of historical data
|
|
|
|
| 949 |
|
| 950 |
β οΈ **Disclaimer**: Stock predictions have approximately 70% accuracy.
|
| 951 |
These forecasts are for informational purposes only and should not be used as
|
pages/System_Monitor.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
# Import resource monitoring
|
| 4 |
try:
|
| 5 |
from resource_monitor import (
|
| 6 |
start_resource_monitoring,
|
|
@@ -54,20 +53,43 @@ def main():
|
|
| 54 |
|
| 55 |
# Application-specific metrics
|
| 56 |
st.subheader("π Application Metrics")
|
| 57 |
-
col1, col2, col3 = st.columns(
|
| 58 |
|
| 59 |
with col1:
|
| 60 |
st.metric("YFinance Calls", current_stats["yfinance_calls"])
|
| 61 |
|
| 62 |
with col2:
|
| 63 |
st.metric(
|
| 64 |
-
"
|
| 65 |
-
f"{current_stats['
|
| 66 |
)
|
| 67 |
|
| 68 |
with col3:
|
|
|
|
|
|
|
|
|
|
| 69 |
st.metric("Streamlit Requests", current_stats["streamlit_requests"])
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Summary statistics
|
| 72 |
summary_stats = get_resource_summary()
|
| 73 |
if summary_stats:
|
|
@@ -102,6 +124,32 @@ def main():
|
|
| 102 |
f"**Total YFinance Calls:** {summary_stats.get('yfinance_calls', 0)}"
|
| 103 |
)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Export data button
|
| 106 |
if st.button("π₯ Export Resource Data"):
|
| 107 |
filename = export_resource_data()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
|
|
|
| 3 |
try:
|
| 4 |
from resource_monitor import (
|
| 5 |
start_resource_monitoring,
|
|
|
|
| 53 |
|
| 54 |
# Application-specific metrics
|
| 55 |
st.subheader("π Application Metrics")
|
| 56 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 57 |
|
| 58 |
with col1:
|
| 59 |
st.metric("YFinance Calls", current_stats["yfinance_calls"])
|
| 60 |
|
| 61 |
with col2:
|
| 62 |
st.metric(
|
| 63 |
+
"Ridge Training Time",
|
| 64 |
+
f"{current_stats['ridge_training_time']:.2f}s",
|
| 65 |
)
|
| 66 |
|
| 67 |
with col3:
|
| 68 |
+
st.metric("ML Predictions", current_stats.get("ml_predictions", 0))
|
| 69 |
+
|
| 70 |
+
with col4:
|
| 71 |
st.metric("Streamlit Requests", current_stats["streamlit_requests"])
|
| 72 |
|
| 73 |
+
# ML Model Information
|
| 74 |
+
st.subheader("π€ Machine Learning Metrics")
|
| 75 |
+
col1, col2, col3 = st.columns(3)
|
| 76 |
+
|
| 77 |
+
with col1:
|
| 78 |
+
st.metric(
|
| 79 |
+
"Model Type", current_stats.get("ml_model", "Ridge Regression")
|
| 80 |
+
)
|
| 81 |
+
st.metric("Features Used", current_stats.get("feature_count", 35))
|
| 82 |
+
|
| 83 |
+
with col2:
|
| 84 |
+
st.metric(
|
| 85 |
+
"Technical Indicators", current_stats.get("feature_count", 35)
|
| 86 |
+
)
|
| 87 |
+
st.metric("Training Data", "5 years")
|
| 88 |
+
|
| 89 |
+
with col3:
|
| 90 |
+
st.metric("Prediction Period", "30 days")
|
| 91 |
+
st.metric("Model Accuracy", "80-95% RΒ²")
|
| 92 |
+
|
| 93 |
# Summary statistics
|
| 94 |
summary_stats = get_resource_summary()
|
| 95 |
if summary_stats:
|
|
|
|
| 124 |
f"**Total YFinance Calls:** {summary_stats.get('yfinance_calls', 0)}"
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# ML Summary
|
| 128 |
+
if summary_stats:
|
| 129 |
+
st.subheader("π€ ML Model Summary")
|
| 130 |
+
col1, col2 = st.columns(2)
|
| 131 |
+
|
| 132 |
+
with col1:
|
| 133 |
+
st.write(
|
| 134 |
+
f"**Total Ridge Training Time:** {summary_stats.get('ridge_training_time', 0):.2f}s"
|
| 135 |
+
)
|
| 136 |
+
st.write(
|
| 137 |
+
f"**Total ML Predictions:** {summary_stats.get('ml_predictions', 0)}"
|
| 138 |
+
)
|
| 139 |
+
st.write(
|
| 140 |
+
f"**Model Type:** {summary_stats.get('ml_model', 'Ridge Regression')}"
|
| 141 |
+
)
|
| 142 |
+
st.write(
|
| 143 |
+
f"**Technical Indicators:** {summary_stats.get('technical_indicators', 35)}"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
with col2:
|
| 147 |
+
st.write("**Features Include:**")
|
| 148 |
+
st.write("β’ Moving Averages (SMA 10, 20, 50, 200)")
|
| 149 |
+
st.write("β’ Momentum Indicators (RSI, MACD, Stochastic)")
|
| 150 |
+
st.write("β’ Volatility Indicators (Bollinger Bands)")
|
| 151 |
+
st.write("β’ Volume Analysis & Market Sentiment")
|
| 152 |
+
|
| 153 |
# Export data button
|
| 154 |
if st.button("π₯ Export Resource Data"):
|
| 155 |
filename = export_resource_data()
|