Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jialuechen/deepfolio
Transformer for Portfolio Optimization. Applicable to Mid/Low Frequency Trading
https://github.com/jialuechen/deepfolio
attention-mechanism deep-learning event-driven mid-frequency-trading neural-network portfolio-optimization quant-finance raylib reinforcement-learning statistics tensorflow time-series time2vec transformer
Last synced: 6 days ago
JSON representation
Transformer for Portfolio Optimization. Applicable to Mid/Low Frequency Trading
- Host: GitHub
- URL: https://github.com/jialuechen/deepfolio
- Owner: jialuechen
- License: bsd-2-clause
- Created: 2024-05-24T18:30:01.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-11T02:55:07.000Z (3 months ago)
- Last Synced: 2024-12-28T20:07:38.798Z (13 days ago)
- Topics: attention-mechanism, deep-learning, event-driven, mid-frequency-trading, neural-network, portfolio-optimization, quant-finance, raylib, reinforcement-learning, statistics, tensorflow, time-series, time2vec, transformer
- Language: Python
- Homepage: https://jialuechen.github.io/deepfolio/
- Size: 4.03 MB
- Stars: 110
- Watchers: 8
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![TensorFlow](https://img.shields.io/badge/TensorFlow-2.15-red)](https://tensorflow.org/)
![PyPI - Version](https://img.shields.io/pypi/v/deepfolio)
[![License](https://img.shields.io/badge/License-BSD_2--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
![Python versions](https://img.shields.io/badge/python-3.6%2B-green)
![PyPI downloads](https://img.shields.io/pypi/dm/deepfolio)**DeepFolio** is a Python library for real-time portfolio optimization built on top of Google's TensorFlow platform. Its design and development is based on the Portfolio Transformer (PT), a novel end-to-end portfolio asset allocation framework, inspired by the numerous successes of attention mechanisms in natural language processing. With PT's full encoder-decoder architecture,specialized time encoding layers, and gating components, it
has a high capacity to learn long-term dependencies among portfolio assets
and hence can adapt more quickly to changing market conditions.
Deepfolio combines optimization techniques (both convex and non-convex) with deep learning approaches to provide a powerful toolkit for investment professionals and researchers.## Features
- Portfolio Transformer: Attention-Based Asset Allocation Framework- Differentiable portfolio optimization
- Real-time optimization
- Robust and multi-period optimization
- Multi-asset class support
- Backtesting system
- Risk management tools
- Factor model integration
- Automated hyperparameter tuning (Backed by Optuna)
- Trade execution simulation
- Event-driven rebalancing
- Comprehensive reporting
- Sentiment analysis integration
- Tax-aware optimization
- Interactive visualization dashboard## Installation
```bash
pip install --upgrade deepfolio
```## Quick Start
```python
from deepfolio.models import DiffOptPortfolio
from deepfolio.optimizers import CustomOptimizer
from deepfolio import Backtester# Initialize the model
model = DiffOptPortfolio(input_dim=50, n_assets=10, hidden_dim=64)# Create an optimizer
optimizer = CustomOptimizer(model.parameters())# Load your data
features, returns = load_your_data()# Create a backtester
backtester = Backtester(model, {'features': features, 'returns': returns})# Run backtesting
backtester.run()# Get results
results = backtester.get_results()
print(f"Sharpe Ratio: {results['sharpe_ratio']}")
print(f"Max Drawdown: {results['max_drawdown']}")
```## Advanced Usage
### Portfolio Transformer : Attention-Based Asset Allocation
```python
from deepfolio.optimizers import portfolio_transformer
input_shape = (30, 10) # 30 time steps, 10 assets
d_model = 64
num_heads = 4
dff = 128
num_layers = 4model = portfolio_transformer(input_shape, d_model, num_heads, dff, num_layers)
model.compile(optimizer='adam', loss='mse') # Adjust loss as per the paper's requirements
model.summary()```
### Real-time Optimization```python
from deepfolio.models import RealtimeOptimizer
from deepfolio.data import DataSourcedata_source = DataSource(api_key="your_api_key")
optimizer = RealtimeOptimizer(model, data_source)
optimizer.start()
```### Multi-Asset Optimization
```python
from deepfolio.models import MultiAssetDiffOptPortfolioasset_classes = ['stocks', 'bonds', 'commodities']
input_dims = {'stocks': 50, 'bonds': 30, 'commodities': 20}
hidden_dims = {'stocks': 64, 'bonds': 32, 'commodities': 32}
model = MultiAssetDiffOptPortfolio(asset_classes, input_dims, hidden_dims)
```### Tax-Aware Optimization
```python
from deepfolio.optimizers import TaxOptimizertax_optimizer = TaxOptimizer()
optimal_trades = tax_optimizer.optimize(current_portfolio, target_weights, prices, cost_basis, holding_period)
```### Interactive Dashboard
```python
from deepfolio.utils import PortfolioDashboarddashboard = PortfolioDashboard(portfolio_data, benchmark_data)
dashboard.run()
```## Documentation
For detailed documentation, please visit our [documentation site](https://diffopt-portfolio.readthedocs.io).
## Contributing
We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for more details.
## License
This project is licensed under the BSD-2-Clause License- see the [LICENSE](LICENSE) file for details.
## Reference
[1]
Damian Kisiel, Denise Gorse (2022).
Portfolio Transformer for Attention-Based Asset Allocation
arXiv:2206.03246 [q-fin.PM]## Acknowledgments
- This package leverages the power of TensorFlow for efficient portfolio optimization.
- Thanks to the financial machine learning community for inspiring many of the implemented methods.