Authors: Hongzhou Du
The Financial Risk Assessment and Early Warning System is a sophisticated analysis tool built on machine learning and deep learning technologies. It provides comprehensive capabilities for stock market data analysis, future price prediction, and risk assessment through an interactive Streamlit interface. This system is designed for investors, financial analysts, and quantitative researchers who need advanced tools for market analysis and decision support.
This system addresses the challenge of financial risk prediction by:
- Analyzing historical stock data using multiple technical indicators
- Employing advanced machine learning models to predict future price movements
- Assessing potential risk levels through multi-dimensional analysis
- Providing interactive visualizations for better decision-making
- Supporting risk quantification through VaR and other metrics
- Historical Data Retrieval: Downloads stock data via Alpha Vantage API
- Technical Indicator Calculation:
- Multiple timeframe RSI (7, 14, 21 days)
- MACD with signal and histogram
- Bollinger Bands (multiple periods)
- Stochastic Oscillator
- ADX (Average Directional Index)
- ATR (Average True Range)
- Volume indicators (OBV, VWAP, Chaikin Money Flow)
- Ichimoku Cloud
- CCI (Commodity Channel Index)
- Many more trend, momentum and volatility indicators
- Advanced Data Preprocessing:
- Missing value handling
- Feature scaling
- Feature engineering
- Time series stationarity testing
- Deep Learning Models:
- LSTM (Long Short-Term Memory)
- Bidirectional LSTM
- GRU (Gated Recurrent Units)
- CNN-LSTM hybrid
- Traditional Machine Learning Models:
- Random Forest Regressor
- Gradient Boosting Regressor
- Support Vector Regression
- XGBoost
- AdaBoost
- Voting Regressor (ensemble)
- Hyperparameter Tuning: Automated optimization via GridSearchCV with time series cross-validation
- Multi-dimensional Risk Quantification:
- Volatility-based risk assessment
- Drawdown analysis
- Error-based risk evaluation
- Value at Risk (VaR) calculation
- Comprehensive Risk Levels: Low, Medium, High, Very High classifications
- Advanced Metrics:
- VaR at multiple confidence levels (95%, 99%)
- Conditional Value at Risk (CVaR/Expected Shortfall)
- Risk heatmaps and time series
- Price path simulation (customizable number of simulations)
- Future price distribution analysis
- Probability of profit/loss calculation
- Daily VaR calculation through simulation
- Feature Importance Analysis:
- F-test
- Mutual Information
- Random Forest importance
- XGBoost importance
- SHAP (SHapley Additive exPlanations):
- Summary plots
- Dependence plots
- Waterfall plots
- Feature correlation analysis
- Interactive Charts:
- Candlestick charts with technical indicators
- Prediction results with confidence intervals
- Risk heatmaps
- Monte Carlo simulation paths
- Feature importance visualization
- SHAP value plots
- Technical indicator dashboards
- Python 3.7+
- pip (Python package manager)
- Git (for cloning the repository)
git clone https://github.com/DwHz/Financial_Risk_Assessment-Early_Warning_System.git
cd Financial_Risk_Assessment-Early_Warning_System# For Windows
python -m venv venv
venv\Scripts\activate
# For macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txt- Obtain an Alpha Vantage API key from https://www.alphavantage.co/support/#api-key
- Register for a free account
- After registration, you'll receive a free API key
- The system includes a default API key, but consider replacing it with your own key for better performance
streamlit run app.pyThe application will automatically open in your default web browser at http://localhost:8501.
In the sidebar:
- Enter a stock symbol (e.g., "AAPL" for Apple)
- Select start and end dates for analysis
- Choose an analysis mode:
- Basic Analysis
- Advanced Analysis
- Risk Assessment
- Monte Carlo Simulation
- Feature Importance
- Model Interpretation
- Adjust model parameters based on your selected mode
- Click the "Run Analysis" button to start processing
- The system will download data, calculate indicators, train models, and display results
Each analysis mode provides different insights:
- Data overview with basic statistics
- Technical indicator visualization
- Feature importance analysis
- Machine learning model evaluation
- Prediction results with confidence intervals
- Deep learning model training and evaluation
- Visualization of model training history
- Prediction results with comprehensive metrics
- Model performance comparison
- Advanced risk evaluation across multiple dimensions
- Risk level distribution
- Risk heatmap visualization
- VaR and CVaR calculation
- Risk time series analysis
- Price path simulation visualization
- Final price distribution analysis
- Return probabilities and statistics
- Daily VaR through simulation
- Feature importance comparison across multiple methods
- Correlation analysis
- Feature-to-target relationship visualization
- SHAP value analysis for model interpretability
- Feature impact visualization
- Model interpretation conclusions
The system calculates and visualizes multiple technical indicators, including:
- Moving averages (multiple periods)
- RSI, MACD, and Stochastic oscillators
- Bollinger Bands
- Ichimoku Cloud
- ADX, ATR, and more
Models are trained on historical data and used to predict future prices. Results are visualized with:
- Actual vs. predicted price charts
- Confidence intervals
- Performance metrics (MSE, RMSE, MAE, MAPE, RΒ²)
The system provides comprehensive risk analysis with:
- Multi-dimensional risk level classification
- Risk heatmap visualization
- VaR and CVaR calculations
- Time series risk indicators
The system is designed to be extensible. To add new features:
- Create a function in
app.pyto calculate the indicator - Add the indicator calculation to the
preprocess_datafunction - Update visualization functions to display the new indicator
- Create a function for your model architecture
- Add your model to the relevant model selection section
- Update training and evaluation code to support the new model
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Hongzhou Du - duhz2929@gmail.com