A high-performance, modern C++20 reimplementation of the Python pyfolio portfolio analysis library
Pyfolio_cpp transforms portfolio analysis by delivering 10-100x performance improvements over the original Python pyfolio while maintaining full compatibility and adding enterprise-grade features for institutional quantitative finance.
- π Speed: 10-100x faster than Python pyfolio
- πΎ Memory: 50% less memory usage for large portfolios
- βοΈ Scalability: Handle 10,000+ securities with real-time analysis
- π Parallel: Multi-threaded processing for complex calculations
- ποΈ Type Safety: Strong typing prevents financial calculation errors
- π§ Zero-Cost Abstractions: Template-heavy design with no runtime overhead
- π¦ Header-Only: Easy integration with single include
- π§© Modular: Use only the components you need
- π Robust: Comprehensive error handling and validation
- π Scalable: Cloud-native architecture for enterprise deployment
- π Compatible: Python bindings for seamless migration
- π Modern: Web interface for interactive portfolio analysis
π§ Project Phase: Planning and Architecture
This project is currently in the planning phase. Comprehensive documentation and implementation roadmap have been created:
- β Comprehensive TODO List - Detailed 14-week implementation plan
- β Project Architecture - Technical architecture and design decisions
- β Implementation Priorities - Strategic development priorities and MVP definition
- Weeks 1-4: Foundation and core analytics (MVP)
- Weeks 5-8: Advanced risk analysis and attribution
- Weeks 9-12: Visualization and Python integration
- Weeks 13-14: Production deployment and optimization
pyfolio_cpp/
βββ include/pyfolio/
β βββ core/ # Time series, DataFrame, datetime
β βββ performance/ # Performance metrics and ratios
β βββ risk/ # VaR, factor exposure, risk attribution
β βββ positions/ # Portfolio holdings and allocation
β βββ transactions/ # Trade analysis and costs
β βββ attribution/ # Performance attribution models
β βββ visualization/ # Charts and reporting
β βββ python/ # Python bindings- π Performance Metrics: Sharpe, Sortino, Calmar ratios with confidence intervals
β οΈ Risk Analysis: VaR, factor exposures, stress testing- π° Position Analysis: Allocation, concentration, sector analysis
- π Transaction Analysis: Round trips, trading costs, turnover
- π Attribution: Multi-factor attribution, alpha/beta decomposition
- π Visualization: Interactive charts and tear sheet generation
- π Python API: Drop-in replacement for existing pyfolio workflows
# Using conda (recommended)
conda install -c conda-forge pyfolio-cpp
# Using pip for Python bindings
pip install pyfolio-cpp
# From source
git clone https://github.com/your-repo/pyfolio_cpp.git
cd pyfolio_cpp
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)#include <pyfolio/pyfolio.h>
int main() {
// Load portfolio data
auto returns = pyfolio::load_returns("returns.csv");
auto positions = pyfolio::load_positions("positions.csv");
// Calculate performance metrics
auto sharpe = pyfolio::calculate_sharpe_ratio(returns, 0.02);
auto max_dd = pyfolio::calculate_max_drawdown(returns);
// Generate comprehensive tear sheet
pyfolio::create_full_tear_sheet(returns, positions)
.save_html("portfolio_analysis.html")
.save_pdf("portfolio_analysis.pdf");
return 0;
}import pyfolio_cpp as pf
import pandas as pd
# Load data (same as original pyfolio)
returns = pd.read_csv('returns.csv', index_col=0, parse_dates=True)
positions = pd.read_csv('positions.csv', index_col=0, parse_dates=True)
# 10-100x faster analysis
pf.create_full_tear_sheet(returns, positions=positions)- Rapid Prototyping: Fast iteration on strategy development
- Backtesting: High-performance historical analysis
- Research: Advanced statistical and Bayesian analysis
- Daily Monitoring: Real-time portfolio performance tracking
- Risk Management: Comprehensive risk analysis and reporting
- Client Reporting: Professional tear sheets and presentations
- Enterprise Scale: Handle large multi-strategy portfolios
- Compliance: Automated regulatory reporting
- Integration: REST API for existing systems
- Easy Integration: Header-only library with minimal dependencies
- Extensibility: Plugin architecture for custom metrics
- Performance: Zero-copy operations and SIMD optimization
- C++20: Modern standard with concepts, ranges, and modules
- Eigen: High-performance linear algebra
- Date: Modern date/time handling
- fmt: Fast string formatting
- spdlog: High-performance logging
- Intel MKL: Optimized mathematical operations
- CUDA: GPU acceleration for large portfolios
- pybind11: Python bindings
- React: Modern web interface
| Operation | Python pyfolio | Pyfolio_cpp Target | Speedup |
|---|---|---|---|
| Sharpe Ratio | 10ms | 0.1ms | 100x |
| Full Tear Sheet | 30s | 1s | 30x |
| 10Y Daily Analysis | 5min | 5s | 60x |
| Large Portfolio (1000 assets) | 2hrs | 2min | 60x |
- Memory: 50% reduction vs Python pyfolio
- CPU: Linear scaling with core count
- Storage: Efficient columnar data formats
We welcome contributions from the quantitative finance and C++ communities!
git clone https://github.com/your-repo/pyfolio_cpp.git
cd pyfolio_cpp
./scripts/setup_dev_environment.sh- Core Analytics: Financial calculations and algorithms
- Performance: SIMD optimization and parallel processing
- Testing: Unit tests and validation against Python pyfolio
- Documentation: Examples, tutorials, and API documentation
- Integration: Python bindings and web interface
This project is licensed under the MIT License - see the LICENSE file for details.
- Quantopian Team: Original pyfolio Python implementation
- C++ Community: Modern C++ libraries and best practices
- Eigen Project: High-performance linear algebra library
- pybind11: Seamless Python integration
- GitHub Issues: Bug reports and feature requests
- Email: [Maintainer email]
- Discord: [Community chat]
Note: This project is currently in the planning phase. The documentation and architecture have been completed, and implementation will begin according to the detailed roadmap in the docs/ directory. Star this repository to follow our progress! β