10 Commits

Author SHA1 Message Date
ThotDjehuty 24556f51d7 release(v2.0.0): finalize PyPI metadata, README rewrite, v2 benchmark + McKean-Vlasov animation
- Restore correct PyPI distribution name 'optimiz-rs' (continuity with v1.0.x).
  Rust crate stays 'optimiz-rs'; Python module is 'optimizr'.
- python/optimizr/__init__.py:
  * Bump __version__ from stale '0.2.0' to '2.0.0'.
  * Eagerly bind every v2 primitive from _core (so dir(optimizr), IDE
    auto-complete and 'from optimizr import X' all work without relying on
    the lazy __getattr__ fallback).
  * Extend __all__ with 38 new v2 entries.
- README.md: full v2 features section grouped by domain (rough volatility,
  BSDE/PDE, stochastic control, mean-field, topology/graphs/signatures,
  risk/robust inference, point processes, Kalman). Embedded
  examples/mckean_vlasov.gif at the top. Added v2 benchmark table.
- examples/benchmark_v2.py: honest benchmark vs pure-Python/NumPy
  references on intrinsically loopy workloads. Best-of-3, single-thread,
  Apple M2: HMM 67.7x, DE 13.9x, signatures 11.2x, Hawkes 3.3x, MCMC 1.7x.
- examples/animate_mckean_vlasov.py + examples/mckean_vlasov.gif (5MB):
  cinematic 800-particle mean-reverting McKean-Vlasov flow animation
  using optimizr.mean_reverting_mckean_vlasov.
- tests/test_v2_api.py already in place: 20/20 pass.
2026-05-14 21:54:49 +02:00
ThotDjehuty cce31055c1 docs(v2.0.0-alpha.3): inline plot injection across the entire doc tree
Add scripts/inject_doc_plots.py that scans every .md and .rst page under
docs/source/, executes each Python code-block in an isolated namespace
with a non-interactive matplotlib backend, captures every figure
produced, and inserts an inline image directive immediately after the
code-block.  Markers AUTO-PLOT-BEGIN/END make the injection idempotent
on re-runs.  Blocks that fail to execute or produce no figure are left
untouched.

Add a transparent __getattr__ fallback in python/optimizr/__init__.py
that forwards any unresolved top-level attribute to the compiled _core
extension.  This lets all v1.x and v2.0 doc samples that use
'from optimizr import X' (estimate_ou_params_py, linear_bsde_constant_coeffs,
mmd_gaussian, ...) execute as written.

Augment the OU Parameter Estimation example
(docs/source/algorithms/optimal_control.md) with a two-panel
visualization (simulated path plus empirical/theoretical autocorrelation).

Net effect: 14 doc pages now display matplotlib plots inline directly
under the code that produced them -- including the OU page, point
processes, Grid Search, HMM, MCMC, plus the 8 v2.0 RST pages.
2026-05-12 13:05:14 +02:00
ThotDjehuty e67b0f8376 feat(portfolio): add CARA, convex, mean-variance & ERC portfolio optimization module
New Rust portfolio_optimization module with PyO3 bindings:
- CARA/CRRA utility maximization via projected gradient descent
- General-purpose convex objective solver on simplex (ProjectedGradientSolver)
- Mean-variance optimization (max Sharpe, target return, min variance)
- Equal Risk Contribution (ERC) portfolio allocation
- Python bindings: cara_optimal_weights, mean_variance_optimal_weights,
  min_variance_weights, erc_weights
- 6/6 unit tests passing

Convergence fix: removed gradient-norm criterion on simplex boundary
(projected gradient never vanishes at constrained optimum).
Default learning rate increased from 0.005 to 0.1.
2026-04-15 03:08:08 +02:00
Melvin Alvarez c18788160a fix: update MCMC and DE tutorials for v1.0.0 API - lambda closures, parameter renames, tuple unpacking 2026-02-16 17:15:45 +01:00
Melvin Alvarez 1a866da60b feat(mean_field): Add Python bindings and comprehensive tutorial notebook
- Add python_bindings.rs with MFGConfigPy and solve_mfg_1d_rust
- Update notebook to compare Rust vs Python implementations
- Add performance benchmarking and accuracy validation
- Include convergence plots and 3D visualizations
- Update __init__.py to expose MFG functions

Note: Python bindings need maturin build due to macOS linker issues with cargo
2026-01-04 14:52:14 +01:00
Melvin Alvarez f5f6005f80 feat(parallel): add GIL-free parallel DE with Rust objectives
- Implement RustObjective trait for GIL-free parallelization
- Add 5 benchmark functions: Sphere, Rosenbrock, Rastrigin, Ackley, Griewank
  * Each implements RustObjective with evaluate(), dimension(), global_optimum()
  * Exposed to Python with __call__ method

- Add parallel_differential_evolution_rust() function:
  * Uses Rayon for parallel population evaluation
  * Works with RustObjective implementations only
  * Eliminates Python GIL overhead for 10-100× speedup
  * Supports all DE strategies and adaptive parameters

- Create comprehensive examples:
  * parallel_de_benchmark.py: Performance benchmarks showing speedup
  * polaroid_optimizr_integration.py: 4 workflows combining Polaroid + OptimizR
    - Regime detection with HMM
    - Strategy parameter optimization
    - Portfolio risk analysis
    - Pairs trading pipeline

- Module integration:
  * Export benchmark functions in Python API
  * Export parallel_differential_evolution_rust
  * Update __init__.py and core.py with new functions

- Technical implementation:
  * RustObjective trait in src/rust_objectives.rs
  * Parallel evaluation uses par_iter() from Rayon
  * Per-thread RNG seeding for reproducibility
  * Maintains same API as standard DE for easy comparison

Part of Priority 2: Enable Rust parallelization (Enhancement Strategy)
Expected speedup: 10-100× on multi-core systems for pure Rust objectives
2026-01-03 00:03:29 +01:00
Melvin Alvarez 9a8032e4ee feat(timeseries): add time-series integration helpers for financial analysis
- Implement 6 helper functions in src/timeseries_utils.rs:
  * prepare_for_hmm: Feature engineering for HMM regime detection
  * rolling_hurst_exponent: Mean-reversion detection (H < 0.5 = mean-reverting)
  * rolling_half_life: Mean-reversion speed for pairs trading
  * return_statistics: Risk metrics (mean, std, skew, kurt, sharpe)
  * create_lagged_features: ML feature matrix creation
  * rolling_correlation: Rolling correlation for pairs trading

- Add PyO3 bindings in src/timeseries_utils/python_bindings.rs:
  * All functions exposed with _py suffix
  * Proper signature decorators and error handling
  * Registered in lib.rs module system

- Update Python module exports:
  * python/optimizr/core.py: Import from _core
  * python/optimizr/__init__.py: Re-export all functions

- Create comprehensive example:
  * examples/timeseries_integration.py demonstrates all 6 functions
  * Includes integrated pairs trading workflow
  * Shows feature engineering for regime detection

- Technical details:
  * Fixed Array1<f64> type conversions for ndarray compatibility
  * Uses risk_metrics::hurst_exponent and estimate_half_life
  * Built successfully with maturin develop --release (40.93s)
  * All functions tested and working correctly

Part of Priority 3: Time-series integration helpers (Enhancement Strategy)
Addresses v0.3.0 roadmap: Bridge optimization with time-series analysis
2026-01-02 22:13:05 +01:00
Melvin Avarez 79f51e4775 Release v0.2.0: Comprehensive DE, Mathematical Toolkit, Optimal Control
Major Features:
• Comprehensive Differential Evolution with 5 strategies (rand1, best1, currenttobest1, rand2, best2)
• Adaptive jDE algorithm for self-tuning F and CR parameters
• Convergence tracking with history records and early stopping
• Mathematical toolkit module (780 lines): gradient, hessian, jacobian, statistics, linear algebra
• Optimal control framework: HJB solvers, regime switching, jump diffusion, MRSJD
• Sparse optimization: Sparse PCA, Box-Tao decomposition, ADMM, Elastic Net
• Rayon parallelization infrastructure (ready for pure Rust objectives)

Performance:
• 74-88× speedup for DE vs SciPy
• 50-100× speedup overall vs pure Python

Refactoring & Cleanup:
• Removed 5 legacy files (de_refactored.rs, hmm_legacy.rs, hmm_refactored.rs, mcmc_legacy.rs, mcmc_refactored.rs)
• Modular architecture with trait-based design
• Generic implementations (no domain-specific code)
• Updated Python bindings for new DE API
• Fixed ALL compilation warnings (0 errors, 0 warnings)

Documentation:
• Updated README with v0.2.0 features and benchmarks
• Created RELEASE_NOTES_v0.2.0.md (comprehensive changelog)
• New optimal control tutorial notebook (03_optimal_control_tutorial.ipynb)
• Updated API examples in README
• Created test_release.py for release validation

Version Bumps:
• Cargo.toml: 0.1.0 → 0.2.0
• pyproject.toml: 0.1.0 → 0.2.0
• python/__init__.py: 0.1.0 → 0.2.0

Breaking Changes:
• DE API: mutation_factor/crossover_rate → f/cr
• DE API: use_adaptive_jde → adaptive
• DE API: strategy names simplified (e.g., 'rand/1/bin' → 'rand1')
• DE returns: (x, fun) tuple instead of dict-like object

Known Items (Post-Release):
• Mathematical toolkit functions available in Rust but not yet exposed to Python
• MCMC Python wrapper needs API update to match new Rust implementation
• Tutorial notebooks need DE API updates

Tests: 34 Rust tests passing, core Python functionality validated with test_release.py
2025-12-10 18:54:32 +01:00
Melvin Avarez 81f48bf4a4 feat: Add sparse optimization and risk metrics modules
 What's New:
- Sparse PCA with L1 regularization for sparse portfolio construction
- Box & Tao decomposition (Robust PCA) for separating low-rank and sparse components
- Elastic Net regression for sparse cointegration analysis
- Hurst exponent calculation via R/S analysis for mean-reversion testing
- Comprehensive risk metrics computation (Sharpe, Sortino, Calmar, VaR, CVaR, etc.)
- Half-life estimation for mean-reverting processes
- Bootstrap returns for confidence interval estimation

🚀 Performance:
- All algorithms implemented in Rust with ndarray-linalg for optimized linear algebra
- PyO3 bindings for seamless Python integration
- 10-15x speedup compared to pure Python implementations

📦 Module Structure:
- src/sparse_optimization.rs: Sparse PCA, Box-Tao, Elastic Net
- src/risk_metrics.rs: Risk analysis and statistics
- Python wrapper: optimizr package with intuitive API

🔧 Technical Improvements:
- Fixed compilation errors in HMM and MCMC modules
- Updated to ndarray-linalg 0.16 with openblas-system
- Enhanced type safety and error handling
- Comprehensive documentation and examples
2025-12-05 13:14:44 +01:00
Melvin Avarez 923d27e87b Initial commit: OptimizR - High-performance optimization algorithms in Rust with Python bindings 2025-12-03 18:16:48 +01:00