Skip to content

Commit 798b3da

Browse files
0xC000005claude
andcommitted
Add ChebyshevSlider for high-dimensional approximation via Sliding Technique
- New ChebyshevSlider class decomposing high-dim functions into low-dim slides - Analytical derivatives per slide with cross-group mixed partials returning 0 - 24 new tests (additive, coupled, 5D, cross-group derivatives, validation) - Documentation page with algorithm, usage examples, and limitations - README updated: repositioned as library, pip install, sliding examples - Version bump to 0.2.0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2666068 commit 798b3da

14 files changed

Lines changed: 1315 additions & 43 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ CLAUDE.md
1313
site/
1414
dist/
1515
*.egg-info/
16+
.coverage
17+
coverage.xml
18+
*.pdf

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to PyChebyshev will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.0] - 2026-02-09
9+
10+
### Added
11+
12+
- `ChebyshevSlider` class for high-dimensional approximation via the Sliding Technique (Ch. 7, Ruiz & Zeron 2021)
13+
- Additive decomposition into low-dimensional slides around a pivot point
14+
- Analytical derivatives per slide with correct cross-group mixed partial handling (returns 0)
15+
- Documentation page for the Sliding Technique with usage examples and limitations
16+
- 24 new tests for slider (additive, coupled, 5D, cross-group derivatives, validation)
17+
18+
### Changed
19+
20+
- README updated: repositioned as a library (was standalone educational script)
21+
- Getting Started section now uses `pip install pychebyshev` with code examples
22+
- Fixed repo URL in docs (`maxjingwezhang``0xC000005`)
23+
824
## [0.1.1] - 2026-02-07
925

1026
### Fixed

README.md

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[![codecov](https://codecov.io/gh/0xC000005/PyChebyshev/graph/badge.svg)](https://codecov.io/gh/0xC000005/PyChebyshev)
77
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
88

9-
**A standalone Python implementation of multi-dimensional Chebyshev tensor interpolation**
9+
**A fast Python library for multi-dimensional Chebyshev tensor interpolation with analytical derivatives**
1010

11-
This project provides an **extremely short, standalone Python implementation** (although not fully optimized, without getting tedious) of the Chebyshev tensor method, **for educational purposes only**, demonstrating that it achieves **comparable accuracy to the state-of-the-art MoCaX library** for European option pricing via Black-Scholes.
11+
PyChebyshev provides a **fully optimized Python implementation** of the Chebyshev tensor method, demonstrating that it achieves **comparable speed and accuracy to the state-of-the-art MoCaX C++ library** for European option pricing via Black-Scholes — with pure Python and NumPy only.
1212

1313
## Performance Comparison
1414

@@ -61,17 +61,13 @@ Both methods achieve **spectral accuracy** (exponential error decay) with identi
6161

6262
The convergence plots demonstrate exponential error decay as node count increases, confirming the spectral accuracy predicted by the Bernstein Ellipse Theorem. Errors drop rapidly from 4×4 to 12×12 nodes, reaching near-machine precision for this analytic function.
6363

64-
## Project Purpose
64+
## Features
6565

66-
PyChebyshev provides a **proof-of-concept environment for conducting time and error analysis** of several popular methods for evaluating European options via Black-Scholes:
67-
68-
| Method | Description | Characteristics |
69-
|--------|-------------|-----------------|
70-
| **Analytical** | Closed-form Black-Scholes formulas | Instant (~10μs), machine precision |
71-
| **FDM** | Finite Difference Method for PDE | Accurate, slow (~0.5s/case), flexible for exotics |
72-
| **Chebyshev Baseline** | NumPy's `Chebyshev.interpolate()` | Dimensional decomposition, partial pre-computation |
73-
| **Chebyshev Barycentric** | Vectorized barycentric with BLAS | **Fast pure Python** (~0.065ms price, ~0.29ms price+Greeks) |
74-
| **MoCaX Standard** | Proprietary C++ library | Production-grade, spectral accuracy, ~0.47ms/query (Python ctypes) |
66+
- **Full tensor interpolation** via `ChebyshevApproximation` — spectral accuracy for up to ~5-6 dimensions
67+
- **Sliding technique** via `ChebyshevSlider` — additive decomposition for high-dimensional functions (10+ dims)
68+
- **Analytical derivatives** via spectral differentiation matrices (no finite differences)
69+
- **Vectorized evaluation** using BLAS matrix-vector products (~0.065ms/query)
70+
- **Pure Python** — NumPy + SciPy only; optional Numba JIT acceleration
7571

7672
## Acknowledgments
7773

@@ -83,44 +79,67 @@ PyChebyshev provides a **proof-of-concept environment for conducting time and er
8379

8480
### Installation
8581

86-
This project uses [uv](https://github.com/astral-sh/uv) for dependency management:
87-
8882
```bash
89-
# Install dependencies
90-
uv sync
91-
92-
# Activate virtual environment (optional, uv handles this automatically)
93-
source .venv/bin/activate
83+
pip install pychebyshev
9484
```
9585

96-
### Quick Demo
86+
With optional Numba JIT acceleration:
9787

98-
**Run comprehensive method comparison**:
9988
```bash
100-
uv run python compare_methods_time_accuracy.py
89+
pip install pychebyshev[jit]
10190
```
10291

103-
**Visualize 2D error surfaces** (varying K and T):
104-
```bash
105-
# Chebyshev Barycentric (30×30 grid, optimized for speed)
106-
./run_comparison_2d_error_surface_barycentric.sh
92+
### Quick Example
10793

108-
# MoCaX Standard (50×50 grid, reference implementation)
109-
./run_comparison_2d_error_surface_mocax.sh
94+
```python
95+
import math
96+
from pychebyshev import ChebyshevApproximation
97+
98+
# Approximate any smooth function
99+
def my_func(x, _):
100+
return math.sin(x[0]) * math.exp(-x[1])
101+
102+
cheb = ChebyshevApproximation(
103+
my_func,
104+
num_dimensions=2,
105+
domain=[[-1, 1], [0, 2]],
106+
n_nodes=[15, 15],
107+
)
108+
cheb.build()
109+
110+
# Evaluate function value
111+
value = cheb.vectorized_eval([0.5, 1.0], [0, 0])
112+
113+
# Analytical first derivative w.r.t. x[0]
114+
dfdx = cheb.vectorized_eval([0.5, 1.0], [1, 0])
115+
116+
# Price + all derivatives at once (shared weights, ~25% faster)
117+
results = cheb.vectorized_eval_multi(
118+
[0.5, 1.0],
119+
[[0, 0], [1, 0], [0, 1], [2, 0]],
120+
)
110121
```
111122

112-
**Test individual methods**:
113-
```bash
114-
# Finite Difference Method convergence study
115-
uv run python fdm_baseline.py
123+
### High-Dimensional Functions (Sliding Technique)
116124

117-
# Chebyshev Baseline (NumPy implementation)
118-
uv run python chebyshev_baseline.py
125+
For functions with more than ~6 dimensions, use `ChebyshevSlider` to decompose into low-dimensional slides:
119126

120-
# Chebyshev Barycentric (JIT-optimized)
121-
uv run python chebyshev_barycentric.py
127+
```python
128+
from pychebyshev import ChebyshevSlider
129+
130+
slider = ChebyshevSlider(
131+
my_func, num_dimensions=10,
132+
domain=[[-1, 1]] * 10,
133+
n_nodes=[11] * 10,
134+
partition=[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]],
135+
pivot_point=[0.0] * 10,
136+
)
137+
slider.build()
138+
val = slider.eval([0.5] * 10, [0] * 10)
122139
```
123140

141+
See the [documentation](https://0xc000005.github.io/PyChebyshev/) for full API reference and usage guides.
142+
124143
---
125144

126145
## Technicals
@@ -250,7 +269,7 @@ With the theoretical foundation established, Chebyshev interpolation can be impl
250269

251270
### Method 1: Chebyshev Baseline (Polynomial Coefficients)
252271

253-
**Implementation**: `chebyshev_baseline.py`
272+
**Benchmark script**: `chebyshev_baseline.py`
254273

255274
#### Dimensional Decomposition Strategy
256275

@@ -367,7 +386,7 @@ The bottleneck: most query time is spent refitting polynomials for outer dimensi
367386

368387
### Method 2: Chebyshev Barycentric (Barycentric Weights)
369388

370-
**Implementation**: `chebyshev_barycentric.py`
389+
**Library implementation**: `src/pychebyshev/barycentric.py` | **Benchmark script**: `chebyshev_barycentric.py`
371390

372391
#### The Speedup: Separating Nodes from Values
373392

0 commit comments

Comments
 (0)