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.4.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.4-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quant_drl_core-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 8f4042074b7215c2b271d35c6e22fc7aa68bea973c547ba50a6eefbe5f582772
MD5 29e26891aa50bea9af7623dc2ac7f64b
BLAKE2b-256 47fc75b7223522b8d3036ba0b66f39ff86a33fad76f6c281cf61ec84f4775835

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_drl_core-0.1.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: quant_drl_core-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba0b9c20343cf1ff1b0475fd94e0f9c34b7ddae4e0b8a78f94b92673ae4a6098
MD5 932501b6a8502ab6dc25aa0bf2b30e9f
BLAKE2b-256 08b411159789e4720c01a537776d259fa18eeba2f7f0289df115bd1d52a06911

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_drl_core-0.1.4-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