Skip to content

Ronit26Mehta/SmartPortfolio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

52 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿ“Š 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

About

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages