Skip to main content

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

Python 3.10+ License: MIT Code style: black

Terminal UI Preview


๐Ÿš€ 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 networks
  • networkx โ€” Graph operations
  • prophet โ€” Time series forecasting
  • stable-baselines3 โ€” Reinforcement learning
  • textual โ€” Terminal user interface
  • yfinance โ€” 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.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

๐Ÿ™ Acknowledgments


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

smartportfolio-2.1.5.tar.gz (53.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartportfolio-2.1.5-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

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

Hashes for smartportfolio-2.1.5.tar.gz
Algorithm Hash digest
SHA256 46cdfafb292aa7879f8be682ad46f3036ed8fa9ba8faada5e351bda0b4b566ad
MD5 9fc2baec946d9d16cbe8cbffdf46ba03
BLAKE2b-256 f2f38b0eb17ad9a23d211cecca2fc9ddcdb2f6f066be2e6b36f2cadd17f3f529

See more details on using hashes here.

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

Hashes for smartportfolio-2.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b745a40240d1abdbb0005d178113b48f6ce1b729643ab473d35ab01623788d88
MD5 9e339a8500dd115732e9f99b668f9602
BLAKE2b-256 9fcd06aa10b4cc56054a3f18f85b57d462058f3a748b7863996308450ddf4c69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page