GNN + Prophet + DRL Portfolio Optimization TUI - A terminal-based intelligent asset allocation system
Project description
๐ SmartPortfolio
Intelligent Portfolio Optimization using Graph Neural Networks, Prophet Forecasting, and Deep Reinforcement Learning
๐ Overview
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
โจ Features
| 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 |
๐ฆ Installation
Prerequisites
- Python 3.10 or higher
- pip package manager
Quick Install
# 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 .
Dependencies
Core dependencies are automatically installed:
torchโ PyTorch for neural networksnetworkxโ Graph operationsprophetโ Time series forecastingstable-baselines3โ Reinforcement learningtextualโ Terminal user interfaceyfinanceโ Market data
๐ฎ Usage
Launch the TUI
# Start with default tickers
smartportfolio
# Start with custom ticker file
smartportfolio --tickers my_tickers.csv
TUI Commands
| 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 |
Keyboard Shortcuts
| Key | Action |
|---|---|
q |
Quit application |
r |
Run optimization |
l |
Load tickers |
e |
Export results |
h |
Show help |
Esc |
Focus command bar |
Ticker File Format
ticker
AAPL
MSFT
GOOGL
AMZN
META
๐ Output Files
All 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 |
๐๏ธ Architecture
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
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
๐งช Development
Setup Development Environment
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black smartportfolio/
# Lint code
ruff check smartportfolio/
Running Tests
pytest tests/ -v --cov=smartportfolio
๐ Performance
Tested 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 |
๐ค Contributing
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
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Security
For security concerns, please see our Security Policy.
๐ Support
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
๐ Acknowledgments
- Textual โ Terminal UI framework
- Prophet โ Time series forecasting
- Stable-Baselines3 โ RL algorithms
- yfinance โ Market data
Made with โค๏ธ by Anonymous
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartportfolio-2.1.5.tar.gz.
File metadata
- Download URL: smartportfolio-2.1.5.tar.gz
- Upload date:
- Size: 53.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46cdfafb292aa7879f8be682ad46f3036ed8fa9ba8faada5e351bda0b4b566ad
|
|
| MD5 |
9fc2baec946d9d16cbe8cbffdf46ba03
|
|
| BLAKE2b-256 |
f2f38b0eb17ad9a23d211cecca2fc9ddcdb2f6f066be2e6b36f2cadd17f3f529
|
File details
Details for the file smartportfolio-2.1.5-py3-none-any.whl.
File metadata
- Download URL: smartportfolio-2.1.5-py3-none-any.whl
- Upload date:
- Size: 60.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b745a40240d1abdbb0005d178113b48f6ce1b729643ab473d35ab01623788d88
|
|
| MD5 |
9e339a8500dd115732e9f99b668f9602
|
|
| BLAKE2b-256 |
9fcd06aa10b4cc56054a3f18f85b57d462058f3a748b7863996308450ddf4c69
|