Skip to main content

Deep Reinforcement Learning for Financial Portfolio Management

Project description

📈 quant-drl-core

quant-drl-core is a research-focused framework for applying Deep Reinforcement Learning (DRL) to portfolio management and financial decision-making.
It is designed to be modular, extensible, and easy to integrate into experimentation pipelines or production systems.

🎓 This project was developed as part of my Bachelor's Thesis (TFG) for the Double Degree in Mathematics and Computer Engineering at the University of Seville.


🧠 Key Features

  • ✅ Modular training pipeline for multiple DRL algorithms: PPO, SAC, DDPG, TD3
  • ✅ Custom Gymnasium-compatible environments for realistic financial simulations
  • ✅ Support for CNN, LSTM, Transformer and hybrid feature extractors
  • ✅ Integrated technical indicators and raw market data handling
  • ✅ Easy portfolio configuration (by sector and number of companies)
  • ✅ Clean logging with loguru
  • ✅ Compatible with interactive dashboards for visualization (e.g., Streamlit webapp)

🛠️ Getting Started

🔧 Installation

git clone https://github.com/your-username/quant-drl-core.git
cd quant-drl-core
python -m venv venv
source venv/bin/activate         # Windows: venv\Scripts\activate
pip install -e .

🧪 Training models

Use the train_models.py script to train models.

Basic command (default config)

python train_models.py

If you want to update the hierarchy.json automatically. Add the --update_hierarchy flag:

python train_models.py --update_hierarchy

Custom training with options:

python train_models.py \
  --algorithms PPO SAC \
  --features LSTM CNNLSTM \
  --learning_rates 0.0003 0.0001 \
  --n_companies 10 18 \
  --length_train_data 8 \
  --length_eval_data 2 \
  --end_date_year 2021 \
  --total_timesteps 1_000_000 \
  --checkpoint_freq 100_000 \
  --update_hierarchy

Models and logs will be saved in:

  • 📁 models/ – trained model files
  • 📁 logs/ – experiment logs
  • 📄 models/metadata/hierarchy.json – metadata for evaluation

Optional (Open Tensorboard)

tensorboard --logdir=logs/

Tensorboard framework will be available at http://localhost:16006


📊 Evaluating models

Use the evaluate_models.py script to evaluate trained models.

  • Option 1: Evaluate final models
python evaluate_models.py \
  --use_final_model
  • Option 2: Evaluate by specific checkpoint steps
python evaluate_models.py \
  --steps_override PPO=500000 SAC=300000
  • Option 3: Full customized evaluation
python evaluate_models.py \
  --hierarchy_path models/metadata/hierarchy.json \
  --results_path results/eval_sac_vs_ppo.csv \
  --models_dir models \
  --out_dir models/metadata/out \
  --steps_override PPO=500000 SAC=300000 \
  --no_move

📚 Notebooks

Inside notebooks/ you’ll find:

  • 📈 Data exploration
  • 📊 Testing models
  • 📝 Exporting results to LaTeX

🔮 Planned Features

  • Risk-adjusted rewards (Sharpe, Sortino, etc.)
  • Hyperparameter optimization with Optuna
  • Integration with MLFlow
  • Multi-agent extensions
  • Integration with a live dashboard (Streamlit) (quant-drl-web)

📝 License

This project is licensed under the MIT License.
See the LICENSE file for details.


🙋‍♂️ Author

Made with ❤️ by Pablo Diego Acosta


🤝 Contributing

Whether you're a researcher, developer, or enthusiast — feel free to contribute!
You're welcome to suggest improvements, propose new architectures, experiment with custom reward functions, or integrate new DRL algorithms.

✨ Open a pull request, start a discussion, or simply share your ideas.

Together, we can make this framework even more powerful for the DRL + Finance community 🚀

📚 References

This project is based on a wide range of research articles, theses, technical reports, and open-source implementations in the field of reinforcement learning and portfolio management.

Some of the most relevant references include:

  • Filos, A. (2019). Reinforcement Learning for Portfolio Management. arXiv:1909.09571
  • Jiang, Z. et al. (2017). A Deep Reinforcement Learning Framework for the Financial Portfolio Management Problem. arXiv:1706.10059
  • Sutton, R. S., & Barto, A. G. (2018). Reinforcement Learning: An Introduction. MIT Press.
  • Haarnoja, T. et al. (2018). Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning. arXiv:1801.01290
  • Raffin, A. et al. (2021). Stable-Baselines3: Reliable RL Implementations. JMLR
  • Markowitz, H. (1959). Portfolio Selection: Efficient Diversification of Investments. Yale University Press.
  • Open-source: Zenlii – Deep RL Portfolio Management

A complete list of all references (BibTeX format) used in this project is available here.

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

quant_drl_core-0.1.6.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

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

quant_drl_core-0.1.6-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file quant_drl_core-0.1.6.tar.gz.

File metadata

  • Download URL: quant_drl_core-0.1.6.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quant_drl_core-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0f850bfdb485195b89557a42d55604180602ab0642a90218402e0b10af19f15f
MD5 f22aa1b4ae6c18dd0beebf69d1bc6b53
BLAKE2b-256 ed7236abba2c7d0ad431648b7a565dce63cef806e157c906cca2d978cff96f60

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_drl_core-0.1.6.tar.gz:

Publisher: python-publish.yml on pablodieaco/quant-drl-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quant_drl_core-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: quant_drl_core-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quant_drl_core-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 df9aa4a99231a3c45be2058a8e04e916a205fd1604ab3b1fb94edf819232920e
MD5 1ff0dc7e4abad7bd8ba436378fae6227
BLAKE2b-256 39b78246b273f2c00fafdd25cde9bf7f9751f28d048cf45d191b253586e5106a

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_drl_core-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on pablodieaco/quant-drl-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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