9a8032e4ee
- 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
66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
"""
|
|
OptimizR - High-Performance Optimization Algorithms
|
|
===================================================
|
|
|
|
Fast, reliable implementations of advanced optimization and statistical
|
|
inference algorithms with Rust acceleration and pure Python fallbacks.
|
|
|
|
.. moduleauthor:: OptimizR Contributors
|
|
|
|
"""
|
|
|
|
from optimizr.hmm import HMM
|
|
from optimizr.core import (
|
|
mcmc_sample,
|
|
differential_evolution,
|
|
grid_search,
|
|
mutual_information,
|
|
shannon_entropy,
|
|
sparse_pca_py,
|
|
box_tao_decomposition_py,
|
|
elastic_net_py,
|
|
hurst_exponent_py,
|
|
compute_risk_metrics_py,
|
|
estimate_half_life_py,
|
|
bootstrap_returns_py,
|
|
# Time-series utilities
|
|
prepare_for_hmm_py,
|
|
rolling_hurst_exponent_py,
|
|
rolling_half_life_py,
|
|
return_statistics_py,
|
|
create_lagged_features_py,
|
|
rolling_correlation_py,
|
|
)
|
|
|
|
# Try to import maths_toolkit from Rust backend
|
|
try:
|
|
from optimizr import _core
|
|
maths_toolkit = _core
|
|
except (ImportError, AttributeError):
|
|
maths_toolkit = None
|
|
|
|
__version__ = "0.2.0"
|
|
__all__ = [
|
|
"HMM",
|
|
"mcmc_sample",
|
|
"differential_evolution",
|
|
"grid_search",
|
|
"mutual_information",
|
|
"shannon_entropy",
|
|
"sparse_pca_py",
|
|
"box_tao_decomposition_py",
|
|
"elastic_net_py",
|
|
"hurst_exponent_py",
|
|
"compute_risk_metrics_py",
|
|
"estimate_half_life_py",
|
|
"bootstrap_returns_py",
|
|
# Time-series utilities
|
|
"prepare_for_hmm_py",
|
|
"rolling_hurst_exponent_py",
|
|
"rolling_half_life_py",
|
|
"return_statistics_py",
|
|
"create_lagged_features_py",
|
|
"rolling_correlation_py",
|
|
"maths_toolkit",
|
|
]
|