Intelligent Portfolio Optimization using Graph Neural Networks, Prophet Forecasting, and Deep Reinforcement Learning
SmartPortfolio is a terminal-based portfolio optimization system that combines cutting-edge machine learning techniques to generate intelligent asset allocations:
- ๐ Graph Neural Networks (GAT) โ Model complex asset relationships and correlations
- ๐ Prophet Forecasting โ Time series predictions with seasonality awareness
- ๐ค Deep Reinforcement Learning (PPO) โ Dynamic allocation via hierarchical agents
- ๐ป Neural Terminal TUI โ Beautiful, Bloomberg-inspired terminal interface
| Feature | Description |
|---|---|
| PyTorch GAT | Pure PyTorch Graph Attention Network for asset embeddings |
| Correlation Graphs | Dynamic asset relationship visualization |
| Live Prices | Real-time market data via yfinance |
| Portfolio Metrics | Expected return, volatility, Sharpe ratio |
| Plot Export | Save allocation charts (pie, bar, dashboard) |
| 8GB RAM Optimized | Memory-efficient for consumer hardware |
- Python 3.10 or higher
- pip package manager
# Clone the repository
git clone https://github.com/yourusername/smartportfolio.git
cd smartportfolio
# Create virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
# Install package
pip install -e .Core dependencies are automatically installed:
torchโ PyTorch for neural networksnetworkxโ Graph operationsprophetโ Time series forecastingstable-baselines3โ Reinforcement learningtextualโ Terminal user interfaceyfinanceโ Market data
# Start with default tickers
smartportfolio
# Start with custom ticker file
smartportfolio --tickers my_tickers.csv| Command | Description |
|---|---|
LOAD <file> |
Load tickers from CSV/XLSX file |
LOADWEIGHTS <file> |
Load previous portfolio weights |
RUN |
Execute optimization pipeline |
STATUS |
Show current system status |
EXPORT |
Export weights to CSV |
PLOT |
Save allocation charts |
GRAPH |
Save correlation graph visualization |
HELP |
Display help information |
CLEAR |
Reset all state |
| Key | Action |
|---|---|
q |
Quit application |
r |
Run optimization |
l |
Load tickers |
e |
Export results |
h |
Show help |
Esc |
Focus command bar |
ticker
AAPL
MSFT
GOOGL
AMZN
METAAll outputs are saved to the outputs/ directory with timestamp-UUID naming:
| File Pattern | Description |
|---|---|
*_portfolio_weights.csv |
Asset weights allocation |
*_allocation_pie.png |
Pie chart visualization |
*_allocation_bar.png |
Bar chart visualization |
*_correlation_graph.png |
Asset relationship graph |
*_dashboard.png |
Combined metrics dashboard |
smartportfolio/
โโโ __init__.py # Package initialization
โโโ __main__.py # CLI entry point
โโโ app.py # Main TUI application
โโโ config.py # Configuration management
โโโ visualization.py # Matplotlib plotting
โโโ data/ # Data handling modules
โ โโโ fetcher.py # Yahoo Finance data fetcher
โ โโโ features.py # Feature engineering
โ โโโ storage.py # Local file storage
โโโ graph/ # Graph neural network modules
โ โโโ builder.py # Dynamic graph construction
โ โโโ gat.py # NumPy GAT implementation
โ โโโ torch_gat.py # PyTorch GAT implementation
โโโ forecasting/ # Time series forecasting
โ โโโ prophet_model.py # Prophet integration
โโโ rl/ # Reinforcement learning
โ โโโ environment.py # Gymnasium environment
โ โโโ agent.py # PPO agent
โโโ components/ # TUI widgets
โโโ header.py # App header
โโโ sidebar.py # Watchlist sidebar
โโโ main_content.py # Portfolio overview
Configuration is managed via smartportfolio/config.py:
# Model parameters
gat_embedding_dim = 32
gat_num_heads = 4
gat_dropout = 0.1
# Data parameters
default_period = "2y"
correlation_threshold = 0.3
# RL parameters
rl_learning_rate = 0.0003
train_episodes = 100# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black smartportfolio/
# Lint code
ruff check smartportfolio/pytest tests/ -v --cov=smartportfolioTested on consumer hardware (8GB RAM):
| Operation | Time | Memory |
|---|---|---|
| Data fetch (10 tickers) | ~5s | ~200MB |
| Graph construction | <1s | ~50MB |
| GAT embedding | ~2s | ~300MB |
| Full pipeline | ~15s | ~500MB |
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For security concerns, please see our Security Policy.
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- Textual โ Terminal UI framework
- Prophet โ Time series forecasting
- Stable-Baselines3 โ RL algorithms
- yfinance โ Market data
Made with โค๏ธ by Anonymous