pychebyshev 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. pychebyshev-0.1.0/.github/workflows/publish.yml +24 -0
  2. pychebyshev-0.1.0/.github/workflows/test.yml +30 -0
  3. pychebyshev-0.1.0/.gitignore +15 -0
  4. pychebyshev-0.1.0/.python-version +1 -0
  5. pychebyshev-0.1.0/CHANGELOG.md +21 -0
  6. pychebyshev-0.1.0/CHEBYSHEV_CONVERGENCE_RATES.md +95 -0
  7. pychebyshev-0.1.0/LICENSE +21 -0
  8. pychebyshev-0.1.0/MOCAX_5D_BLACKSCHOLES.md +422 -0
  9. pychebyshev-0.1.0/MOCAX_SETUP_GUIDE.md +942 -0
  10. pychebyshev-0.1.0/PKG-INFO +559 -0
  11. pychebyshev-0.1.0/README.md +522 -0
  12. pychebyshev-0.1.0/barycentric_2d_convergence.png +0 -0
  13. pychebyshev-0.1.0/barycentric_2d_error_n12.png +0 -0
  14. pychebyshev-0.1.0/barycentric_2d_error_n4.png +0 -0
  15. pychebyshev-0.1.0/barycentric_2d_error_n6.png +0 -0
  16. pychebyshev-0.1.0/barycentric_2d_error_n8.png +0 -0
  17. pychebyshev-0.1.0/chebyshev_barycentric.py +834 -0
  18. pychebyshev-0.1.0/chebyshev_baseline.py +416 -0
  19. pychebyshev-0.1.0/compare_2d_error_surface_barycentric.py +500 -0
  20. pychebyshev-0.1.0/compare_2d_error_surface_mocax.py +556 -0
  21. pychebyshev-0.1.0/compare_methods_time_accuracy.py +467 -0
  22. pychebyshev-0.1.0/docs/api/reference.md +13 -0
  23. pychebyshev-0.1.0/docs/benchmarks.md +36 -0
  24. pychebyshev-0.1.0/docs/getting-started.md +92 -0
  25. pychebyshev-0.1.0/docs/index.md +61 -0
  26. pychebyshev-0.1.0/docs/javascripts/katex.js +8 -0
  27. pychebyshev-0.1.0/docs/user-guide/concepts.md +43 -0
  28. pychebyshev-0.1.0/docs/user-guide/greeks.md +71 -0
  29. pychebyshev-0.1.0/docs/user-guide/usage.md +83 -0
  30. pychebyshev-0.1.0/examples/black_scholes_greeks.py +45 -0
  31. pychebyshev-0.1.0/examples/quick_start.py +36 -0
  32. pychebyshev-0.1.0/fdm_baseline.py +592 -0
  33. pychebyshev-0.1.0/install_mocax.sh +148 -0
  34. pychebyshev-0.1.0/mkdocs.yml +55 -0
  35. pychebyshev-0.1.0/mocax_2d_convergence.png +0 -0
  36. pychebyshev-0.1.0/mocax_2d_error_n12.png +0 -0
  37. pychebyshev-0.1.0/mocax_2d_error_n4.png +0 -0
  38. pychebyshev-0.1.0/mocax_2d_error_n6.png +0 -0
  39. pychebyshev-0.1.0/mocax_2d_error_n8.png +0 -0
  40. pychebyshev-0.1.0/mocax_baseline.py +523 -0
  41. pychebyshev-0.1.0/mocax_sliding.py +255 -0
  42. pychebyshev-0.1.0/mocax_tt.py +485 -0
  43. pychebyshev-0.1.0/profile_barycentric.py +68 -0
  44. pychebyshev-0.1.0/pyproject.toml +70 -0
  45. pychebyshev-0.1.0/run_comparison_2d_error_surface_barycentric.sh +4 -0
  46. pychebyshev-0.1.0/run_comparison_2d_error_surface_mocax.sh +30 -0
  47. pychebyshev-0.1.0/run_comparison_time_accuracy.sh +6 -0
  48. pychebyshev-0.1.0/run_mocax_baseline.sh +6 -0
  49. pychebyshev-0.1.0/run_mocax_sliding.sh +6 -0
  50. pychebyshev-0.1.0/run_mocax_tt.sh +6 -0
  51. pychebyshev-0.1.0/src/pychebyshev/__init__.py +22 -0
  52. pychebyshev-0.1.0/src/pychebyshev/_jit.py +54 -0
  53. pychebyshev-0.1.0/src/pychebyshev/_version.py +1 -0
  54. pychebyshev-0.1.0/src/pychebyshev/barycentric.py +511 -0
  55. pychebyshev-0.1.0/src/pychebyshev/py.typed +0 -0
  56. pychebyshev-0.1.0/tests/conftest.py +100 -0
  57. pychebyshev-0.1.0/tests/test_barycentric.py +161 -0
  58. pychebyshev-0.1.0/uv.lock +1697 -0
@@ -0,0 +1,24 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - uses: astral-sh/setup-uv@v3
17
+ with:
18
+ version: "latest"
19
+
20
+ - name: Build package
21
+ run: uv build
22
+
23
+ - name: Publish to PyPI
24
+ run: uv publish
@@ -0,0 +1,30 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: astral-sh/setup-uv@v3
20
+ with:
21
+ version: "latest"
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ run: uv python install ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: uv sync --python ${{ matrix.python-version }}
28
+
29
+ - name: Run tests
30
+ run: uv run pytest tests/ -v
@@ -0,0 +1,15 @@
1
+ MoCaXSuite-1.2.0/
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ .venv/
6
+ mocax_lib/
7
+ mocaxextend_lib/
8
+ .claude/
9
+ simple-example-py.py
10
+ *.zip
11
+ .DS_Store
12
+ CLAUDE.md
13
+ site/
14
+ dist/
15
+ *.egg-info/
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to PyChebyshev will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2026-02-07
9
+
10
+ ### Added
11
+
12
+ - `ChebyshevApproximation` class for multi-dimensional Chebyshev tensor interpolation
13
+ - Barycentric interpolation with full weight pre-computation
14
+ - Analytical derivatives via spectral differentiation matrices (1st and 2nd order)
15
+ - `vectorized_eval()` using BLAS matrix-vector products (~0.065 ms/query)
16
+ - `vectorized_eval_multi()` with shared barycentric weights (~0.29 ms for price + 5 Greeks)
17
+ - `fast_eval()` with Numba JIT compilation (optional)
18
+ - Node coincidence handling for all evaluation methods
19
+ - MkDocs + Material documentation with KaTeX math rendering
20
+ - pytest test suite (22 tests covering 3D/5D accuracy and method consistency)
21
+ - GitHub Actions CI/CD for testing and PyPI publishing
@@ -0,0 +1,95 @@
1
+ # Chebyshev Convergence Rates: Analytic vs Non-Analytic Functions
2
+
3
+ ## Summary
4
+
5
+ Chebyshev interpolation convergence rates depend critically on function smoothness. While analytic functions achieve exponential convergence (spectral accuracy), non-analytic functions exhibit algebraic convergence rates proportional to their differentiability.
6
+
7
+ ## Convergence Hierarchy
8
+
9
+ ### 1. Analytic Functions: Exponential Convergence
10
+
11
+ **Rate**: O(ρ^(-N)) where ρ > 1 is the Bernstein ellipse parameter
12
+
13
+ If function f is analytic and bounded in a Bernstein ellipse, Chebyshev interpolants converge geometrically [1]:
14
+
15
+ $$|f(x) - p_N(x)| = O(\rho^{-N})$$
16
+
17
+ **Example**: Black-Scholes pricing achieves machine precision (~10^-16) with 10-15 nodes per dimension.
18
+
19
+ ### 2. Smooth Non-Analytic Functions: Algebraic Convergence
20
+
21
+ **Rate**: O(N^(-k)) where k = number of continuous derivatives
22
+
23
+ For functions with k continuous derivatives (and k-th derivative of bounded variation), convergence follows algebraic rate [2, 3]:
24
+
25
+ $$|f(x) - p_N(x)| = O(N^{-k})$$
26
+
27
+ This result is attributed to Mastroianni & Szabados (1995) and established through integration by parts, showing Chebyshev coefficients decay at rate O(n^(-k-1)) [3].
28
+
29
+ **Examples** [4]:
30
+ - |x|^5 (C^5 continuous): convergence rate O(N^-5)
31
+ - |x|^π (C^π continuous): convergence rate O(N^-π)
32
+ - sin(|x|^5.5) (C^5.5 continuous): convergence rate O(N^-5.5)
33
+
34
+ **Practical implication**: Reducing error by 10× requires ~10× more nodes (algebraic) versus ~3 more nodes for analytic functions (exponential).
35
+
36
+ ### 3. Piecewise Smooth Functions: Degraded Convergence
37
+
38
+ For functions continuous on [-1,1] with finite interior discontinuities in derivatives:
39
+ - Pointwise convergence at continuous points [5]
40
+ - Convergence severely slowed by discontinuities [4]
41
+ - Coefficients decay slowly; spectral convergence lost
42
+
43
+ **Solution**: Domain splitting at discontinuities, using separate Chebyshev interpolants on each smooth piece [6].
44
+
45
+ ### 4. Discontinuous Functions: Gibbs Phenomenon
46
+
47
+ **Rate**: No uniform convergence
48
+
49
+ For functions with jump discontinuities (e.g., sign(x), step functions):
50
+ - No convergence in maximum norm [5]
51
+ - Persistent overshoot near discontinuities (~9% overshoot, converging to 1.2823 for unit jump) [4]
52
+ - Pointwise convergence to f(x) where continuous, and to ½(f(x⁻) + f(x⁺)) at jumps [5]
53
+
54
+ ## Comparison Table
55
+
56
+ | Function Class | Example | Convergence Rate | Nodes for 0.01% Error |
57
+ |----------------|---------|------------------|----------------------|
58
+ | Analytic | e^x, Black-Scholes | O(ρ^-N) | ~10-15 |
59
+ | C^5 smooth | \|x\|^5 | O(N^-5) | ~100 |
60
+ | C^2 smooth | \|x\|^2 | O(N^-2) | ~1,000 |
61
+ | C^0 continuous | \|x\| | O(N^-1) | ~10,000 |
62
+ | Discontinuous | sign(x) | None (Gibbs) | ∞ |
63
+
64
+ ## Implications for Option Pricing
65
+
66
+ **European options** (Black-Scholes): Analytic everywhere → spectral convergence achieved with modest node counts (11^5 = 161,051 nodes achieves 0.000% error in this work).
67
+
68
+ **American options**: Early exercise boundary creates non-smoothness → algebraic convergence at best. Consider:
69
+ - Domain splitting at exercise boundary
70
+ - Regularization techniques
71
+ - Alternative methods (FDM, adaptive mesh refinement)
72
+
73
+ **Barrier/Digital options**: Discontinuous payoffs → Gibbs phenomenon. Require special treatment (Gegenbauer reconstruction, domain splitting, or non-polynomial methods).
74
+
75
+ ## Key Insight
76
+
77
+ Chebyshev interpolation is **ideally suited for analytic functions** like European option pricing, where it achieves near-machine precision with reasonable computational cost. For non-analytic functions, convergence degrades gracefully but predictably according to smoothness class.
78
+
79
+ ## References
80
+
81
+ [1] Trefethen, L. N. (2019). *Approximation Theory and Approximation Practice, Extended Edition*. SIAM. Chapter 8: Convergence for Analytic Functions.
82
+
83
+ [2] Trefethen, L. N. (2019). *Approximation Theory and Approximation Practice, Extended Edition*. SIAM. Chapter 7: Convergence for Differentiable Functions.
84
+
85
+ [3] Trefethen, L. N. (2017). "Lecture 3: Chebyshev Series." Oxford University. Available: https://people.maths.ox.ac.uk/trefethen/outline3_2017.pdf
86
+
87
+ [4] "4. Chebfun and Approximation Theory." *Chebfun Guide*. Available: https://www.chebfun.org/docs/guide/guide04.html
88
+
89
+ [5] "Convergence Rates for Interpolating Functions." *Chebfun Examples*. Available: https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/23972/versions/22/previews/chebfun/examples/approx/html/Convergence.html
90
+
91
+ [6] Driscoll, T. A. & Hale, N. (2014). "Optimal Domain Splitting for Interpolation by Chebyshev Polynomials." Available: https://tobydriscoll.net/_docs/driscoll-optimal-domain-splitting-2014.pdf
92
+
93
+ ---
94
+
95
+ *Last updated: 2025-10-27*
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Max Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,422 @@
1
+ # MoCaX 5D Black-Scholes Approximation
2
+
3
+ This document demonstrates that MoCaX achieves spectral accuracy when approximating the Black-Scholes pricing function across the full 5-dimensional parameter space.
4
+
5
+ ## Executive Summary
6
+
7
+ | Metric | Result |
8
+ |--------|--------|
9
+ | **Price Error** | 0.000% (all 11 scenarios) |
10
+ | **Max Greek Error** | 2.885% (Vomma at very short maturity) |
11
+ | **Build Time** | 1.064 seconds |
12
+ | **Function Evaluations** | 161,051 |
13
+ | **Query Time** | ~0.43 ms per evaluation |
14
+
15
+ **Key Finding**: MoCaX maintains consistent accuracy across the entire 5D parameter space, not just at cherry-picked test points.
16
+
17
+ ---
18
+
19
+ ## 1. Problem Setup
20
+
21
+ ### 1.1 Baseline: Analytical Black-Scholes
22
+
23
+ We use the `blackscholes>=0.2.0` Python library as ground truth. This provides closed-form analytical formulas for:
24
+
25
+ - **Price**: `C(S, K, T, sigma, r, q)` - European call option value
26
+ - **1st-order Greeks**: Delta, Vega, Rho
27
+ - **2nd-order Greeks**: Gamma, Vanna, Charm, Vomma, Veta
28
+
29
+ All sensitivities are computed analytically (no finite differences).
30
+
31
+ **Fixed parameter**: Dividend yield `q = 0.02`
32
+
33
+ ### 1.2 Input Space: 5 Dimensions
34
+
35
+ | Dim | Parameter | Symbol | Description | Domain |
36
+ |-----|-----------|--------|-------------|--------|
37
+ | 1 | Spot Price | S | Current asset price | [80, 120] |
38
+ | 2 | Strike Price | K | Option strike | [90, 110] |
39
+ | 3 | Time to Maturity | T | Years until expiry | [0.25, 1.0] |
40
+ | 4 | Volatility | sigma | Annualized volatility | [0.15, 0.35] |
41
+ | 5 | Risk-free Rate | r | Annual interest rate | [0.01, 0.08] |
42
+
43
+ ### 1.3 MoCaX Configuration
44
+
45
+ | Parameter | Value | Notes |
46
+ |-----------|-------|-------|
47
+ | Nodes per dimension | 11 | Chebyshev nodes (optimal for polynomial interpolation) |
48
+ | Total grid points | 161,051 | 11^5 function evaluations |
49
+ | Max derivative order | 2 | Enables 2nd-order Greeks (Gamma, Vanna, Vomma, etc.) |
50
+ | Error threshold | Default | Controls price accuracy only, not derivative accuracy |
51
+ | Build time | 1.064 s | One-time offline cost |
52
+ | Evaluations/sec | 151,308 | During build phase |
53
+
54
+ ### 1.4 Greeks Computed (9 Sensitivities)
55
+
56
+ **1st-Order Greeks**:
57
+ - **Delta** (dV/dS): Sensitivity to spot price
58
+ - **Vega** (dV/dsigma): Sensitivity to volatility
59
+ - **Rho** (dV/dr): Sensitivity to interest rate
60
+
61
+ **2nd-Order Greeks**:
62
+ - **Gamma** (d2V/dS2): Rate of change of Delta
63
+ - **Vanna** (d2V/dS dsigma): Delta sensitivity to volatility
64
+ - **Charm** (d2V/dS dT): Delta decay over time
65
+ - **Vomma** (d2V/dsigma2): Vega sensitivity to volatility
66
+ - **Veta** (d2V/dT dsigma): Vega decay over time
67
+
68
+ **Derivative Indexing**: MoCaX uses `[S, K, T, sigma, r]` ordering.
69
+ - Example: Vanna = `[1, 0, 0, 1, 0]` = d2V/dS dsigma
70
+
71
+ ---
72
+
73
+ ## 2. Experiment 1: Scenario Testing
74
+
75
+ ### 2.1 Purpose
76
+
77
+ Verify accuracy at specific market conditions spanning the full 5D space, including:
78
+ - Moneyness variations (ATM, ITM, OTM)
79
+ - Maturity variations (short, very short, standard)
80
+ - Volatility variations (low, high)
81
+ - Interest rate variations (low, high)
82
+ - Corner cases (multiple parameters at extremes)
83
+
84
+ ### 2.2 Test Scenarios
85
+
86
+ | # | Scenario | S | K | T | sigma | r | Description |
87
+ |---|----------|---|---|---|-------|---|-------------|
88
+ | 1 | ATM | 100 | 100 | 1.0 | 0.25 | 0.05 | At-the-money baseline |
89
+ | 2 | ITM | 110 | 100 | 1.0 | 0.25 | 0.05 | In-the-money |
90
+ | 3 | OTM | 90 | 100 | 1.0 | 0.25 | 0.05 | Out-of-the-money |
91
+ | 4 | Short T | 100 | 100 | 0.5 | 0.25 | 0.05 | 6-month maturity |
92
+ | 5 | Very Short T | 100 | 100 | 0.25 | 0.25 | 0.05 | 3-month maturity |
93
+ | 6 | Low vol | 100 | 100 | 1.0 | 0.15 | 0.05 | Low volatility regime |
94
+ | 7 | High vol | 100 | 100 | 1.0 | 0.35 | 0.05 | High volatility regime |
95
+ | 8 | Low r | 100 | 100 | 1.0 | 0.25 | 0.01 | Low interest rate |
96
+ | 9 | High r | 100 | 100 | 1.0 | 0.25 | 0.08 | High interest rate |
97
+ | 10 | Corner1 | 85 | 105 | 0.5 | 0.20 | 0.03 | OTM + short T + low vol + low r |
98
+ | 11 | Corner2 | 115 | 95 | 0.75 | 0.30 | 0.07 | ITM + med T + high vol + high r |
99
+
100
+ ### 2.3 Results: All 11 Scenarios
101
+
102
+ ---
103
+
104
+ #### Scenario 1: ATM (S=100, K=100, T=1.00, sigma=0.25, r=0.05)
105
+ At-the-money baseline
106
+
107
+ | Metric | Exact | MoCaX | Error% |
108
+ |--------|-------|-------|--------|
109
+ | Price | 11.123762 | 11.123762 | 0.000% |
110
+ | Delta | 0.584955 | 0.584955 | 0.000% |
111
+ | Gamma | 0.015179 | 0.015179 | 0.000% |
112
+ | Vega | 38.714691 | 37.948089 | 1.980% |
113
+ | Rho | 47.371729 | 47.371729 | 0.000% |
114
+ | Vanna | 0.007743 | 0.007590 | 1.980% |
115
+ | Charm | 0.034787 | 0.034787 | 0.000% |
116
+ | Vomma | -0.189702 | -0.185928 | 1.989% |
117
+ | Veta | 17.076166 | 17.076219 | 0.000% |
118
+
119
+ ---
120
+
121
+ #### Scenario 2: ITM (S=110, K=100, T=1.00, sigma=0.25, r=0.05)
122
+ In-the-money
123
+
124
+ | Metric | Exact | MoCaX | Error% |
125
+ |--------|-------|-------|--------|
126
+ | Price | 17.677238 | 17.677238 | 0.000% |
127
+ | Delta | 0.719879 | 0.719879 | 0.000% |
128
+ | Gamma | 0.011688 | 0.011688 | 0.000% |
129
+ | Vega | 36.069698 | 35.355470 | 1.980% |
130
+ | Rho | 61.509446 | 61.509446 | 0.000% |
131
+ | Vanna | -0.493487 | -0.483715 | 1.980% |
132
+ | Charm | -0.036292 | -0.036294 | 0.005% |
133
+ | Vomma | 33.994573 | 33.321338 | 1.980% |
134
+ | Veta | 18.478881 | 18.478910 | 0.000% |
135
+
136
+ ---
137
+
138
+ #### Scenario 3: OTM (S=90, K=100, T=1.00, sigma=0.25, r=0.05)
139
+ Out-of-the-money
140
+
141
+ | Metric | Exact | MoCaX | Error% |
142
+ |--------|-------|-------|--------|
143
+ | Price | 6.075340 | 6.075340 | 0.000% |
144
+ | Delta | 0.421459 | 0.421459 | 0.000% |
145
+ | Gamma | 0.017111 | 0.017111 | 0.000% |
146
+ | Vega | 35.350242 | 34.650260 | 1.980% |
147
+ | Rho | 31.855996 | 31.855996 | 0.000% |
148
+ | Vanna | 0.669992 | 0.656726 | 1.980% |
149
+ | Charm | 0.119862 | 0.119863 | 0.001% |
150
+ | Vomma | 10.639336 | 10.428710 | 1.980% |
151
+ | Veta | 18.669359 | 18.669357 | 0.000% |
152
+
153
+ ---
154
+
155
+ #### Scenario 4: Short T (S=100, K=100, T=0.50, sigma=0.25, r=0.05)
156
+ 6-month maturity
157
+
158
+ | Metric | Exact | MoCaX | Error% |
159
+ |--------|-------|-------|--------|
160
+ | Price | 7.683041 | 7.683040 | 0.000% |
161
+ | Delta | 0.563110 | 0.563110 | 0.000% |
162
+ | Gamma | 0.022010 | 0.022010 | 0.000% |
163
+ | Vega | 27.789321 | 27.512815 | 0.995% |
164
+ | Rho | 24.313965 | 24.313966 | 0.000% |
165
+ | Vanna | 0.005558 | 0.005503 | 0.995% |
166
+ | Charm | 0.056144 | 0.056144 | 0.000% |
167
+ | Vomma | -0.068084 | -0.067527 | 0.818% |
168
+ | Veta | 26.136828 | 26.136771 | 0.000% |
169
+
170
+ ---
171
+
172
+ #### Scenario 5: Very Short T (S=100, K=100, T=0.25, sigma=0.25, r=0.05)
173
+ 3-month maturity
174
+
175
+ | Metric | Exact | MoCaX | Error% |
176
+ |--------|-------|-------|--------|
177
+ | Price | 5.320765 | 5.320763 | 0.000% |
178
+ | Delta | 0.546012 | 0.546012 | 0.000% |
179
+ | Gamma | 0.031519 | 0.031519 | 0.001% |
180
+ | Vega | 19.798008 | 19.699304 | 0.499% |
181
+ | Rho | 12.320098 | 12.320087 | 0.000% |
182
+ | Vanna | 0.003960 | 0.003941 | 0.462% |
183
+ | Charm | 0.085606 | 0.085606 | 0.000% |
184
+ | Vomma | -0.024253 | -0.024952 | 2.885% |
185
+ | Veta | 38.413321 | 38.412825 | 0.001% |
186
+
187
+ ---
188
+
189
+ #### Scenario 6: Low vol (S=100, K=100, T=1.00, sigma=0.15, r=0.05)
190
+ Low volatility regime
191
+
192
+ | Metric | Exact | MoCaX | Error% |
193
+ |--------|-------|-------|--------|
194
+ | Price | 7.336873 | 7.336873 | 0.000% |
195
+ | Delta | 0.596296 | 0.596296 | 0.000% |
196
+ | Gamma | 0.025102 | 0.025102 | 0.000% |
197
+ | Vega | 38.413892 | 37.653272 | 1.980% |
198
+ | Rho | 52.292718 | 52.292717 | 0.000% |
199
+ | Vanna | -0.320116 | -0.313777 | 1.980% |
200
+ | Charm | 0.039847 | 0.039847 | 0.001% |
201
+ | Vomma | 8.803183 | 8.626593 | 2.006% |
202
+ | Veta | 16.649795 | 16.649799 | 0.000% |
203
+
204
+ ---
205
+
206
+ #### Scenario 7: High vol (S=100, K=100, T=1.00, sigma=0.35, r=0.05)
207
+ High volatility regime
208
+
209
+ | Metric | Exact | MoCaX | Error% |
210
+ |--------|-------|-------|--------|
211
+ | Price | 14.912944 | 14.912944 | 0.000% |
212
+ | Delta | 0.590906 | 0.590906 | 0.000% |
213
+ | Gamma | 0.010799 | 0.010799 | 0.000% |
214
+ | Vega | 38.561165 | 37.797603 | 1.980% |
215
+ | Rho | 44.177703 | 44.177703 | 0.000% |
216
+ | Vanna | 0.098370 | 0.096422 | 1.980% |
217
+ | Charm | 0.037454 | 0.037454 | 0.000% |
218
+ | Vomma | -2.564655 | -2.514087 | 1.972% |
219
+ | Veta | 16.858261 | 16.858314 | 0.000% |
220
+
221
+ ---
222
+
223
+ #### Scenario 8: Low r (S=100, K=100, T=1.00, sigma=0.25, r=0.01)
224
+ Low interest rate environment
225
+
226
+ | Metric | Exact | MoCaX | Error% |
227
+ |--------|-------|-------|--------|
228
+ | Price | 9.314906 | 9.314906 | 0.000% |
229
+ | Delta | 0.523298 | 0.523298 | 0.000% |
230
+ | Gamma | 0.015585 | 0.015585 | 0.000% |
231
+ | Vega | 39.750370 | 38.963260 | 1.980% |
232
+ | Rho | 43.014892 | 43.014892 | 0.000% |
233
+ | Vanna | 0.262352 | 0.257158 | 1.980% |
234
+ | Charm | 0.006093 | 0.006093 | 0.001% |
235
+ | Vomma | -2.229996 | -2.185840 | 1.980% |
236
+ | Veta | 18.561610 | 18.561663 | 0.000% |
237
+
238
+ ---
239
+
240
+ #### Scenario 9: High r (S=100, K=100, T=1.00, sigma=0.25, r=0.08)
241
+ High interest rate environment
242
+
243
+ | Metric | Exact | MoCaX | Error% |
244
+ |--------|-------|-------|--------|
245
+ | Price | 12.590697 | 12.590697 | 0.000% |
246
+ | Delta | 0.629723 | 0.629723 | 0.000% |
247
+ | Gamma | 0.014634 | 0.014634 | 0.000% |
248
+ | Vega | 37.323351 | 36.584299 | 1.980% |
249
+ | Rho | 50.381608 | 50.381608 | 0.000% |
250
+ | Vanna | -0.171687 | -0.168288 | 1.980% |
251
+ | Charm | 0.054172 | 0.054172 | 0.000% |
252
+ | Vomma | 6.266591 | 6.142554 | 1.979% |
253
+ | Veta | 15.123492 | 15.123545 | 0.000% |
254
+
255
+ ---
256
+
257
+ #### Scenario 10: Corner1 (S=85, K=105, T=0.50, sigma=0.20, r=0.03)
258
+ OTM + short T + low vol + low r
259
+
260
+ | Metric | Exact | MoCaX | Error% |
261
+ |--------|-------|-------|--------|
262
+ | Price | 0.423699 | 0.423699 | 0.000% |
263
+ | Delta | 0.081730 | 0.081730 | 0.000% |
264
+ | Gamma | 0.012538 | 0.012538 | 0.001% |
265
+ | Vega | 9.149577 | 9.058549 | 0.995% |
266
+ | Rho | 3.261660 | 3.261663 | 0.000% |
267
+ | Vanna | 1.164198 | 1.152615 | 0.995% |
268
+ | Charm | 0.239545 | 0.239545 | 0.000% |
269
+ | Vomma | 97.130631 | 96.163720 | 0.995% |
270
+ | Veta | 28.999336 | 28.999058 | 0.001% |
271
+
272
+ ---
273
+
274
+ #### Scenario 11: Corner2 (S=115, K=95, T=0.75, sigma=0.30, r=0.07)
275
+ ITM + med T + high vol + high r
276
+
277
+ | Metric | Exact | MoCaX | Error% |
278
+ |--------|-------|-------|--------|
279
+ | Price | 25.868981 | 25.868981 | 0.000% |
280
+ | Delta | 0.831099 | 0.831099 | 0.000% |
281
+ | Gamma | 0.007901 | 0.007901 | 0.000% |
282
+ | Vega | 23.866911 | 23.511581 | 1.489% |
283
+ | Rho | 52.280575 | 52.280575 | 0.000% |
284
+ | Vanna | -0.598956 | -0.590039 | 1.489% |
285
+ | Charm | -0.089197 | -0.089196 | 0.001% |
286
+ | Vomma | 60.225273 | 59.328933 | 1.488% |
287
+ | Veta | 22.501578 | 22.501512 | 0.000% |
288
+
289
+ ---
290
+
291
+ ### 2.4 Summary: All Scenarios
292
+
293
+ | Scenario | S | K | T | sigma | r | Price Error | Max Greek Error |
294
+ |----------|---|---|---|-------|---|-------------|-----------------|
295
+ | ATM | 100 | 100 | 1.00 | 0.25 | 0.05 | 0.000% | 1.989% (Vomma) |
296
+ | ITM | 110 | 100 | 1.00 | 0.25 | 0.05 | 0.000% | 1.980% (Vega) |
297
+ | OTM | 90 | 100 | 1.00 | 0.25 | 0.05 | 0.000% | 1.980% (Vega) |
298
+ | Short T | 100 | 100 | 0.50 | 0.25 | 0.05 | 0.000% | 0.995% (Vega) |
299
+ | Very Short T | 100 | 100 | 0.25 | 0.25 | 0.05 | 0.000% | 2.885% (Vomma) |
300
+ | Low vol | 100 | 100 | 1.00 | 0.15 | 0.05 | 0.000% | 2.006% (Vomma) |
301
+ | High vol | 100 | 100 | 1.00 | 0.35 | 0.05 | 0.000% | 1.980% (Vega) |
302
+ | Low r | 100 | 100 | 1.00 | 0.25 | 0.01 | 0.000% | 1.980% (Vega) |
303
+ | High r | 100 | 100 | 1.00 | 0.25 | 0.08 | 0.000% | 1.980% (Vega) |
304
+ | Corner1 | 85 | 105 | 0.50 | 0.20 | 0.03 | 0.000% | 0.995% (Vomma) |
305
+ | Corner2 | 115 | 95 | 0.75 | 0.30 | 0.07 | 0.000% | 1.489% (Vega) |
306
+
307
+ **Result**: All 11 scenarios achieve 0.000% price error and <3% Greek error.
308
+
309
+ ---
310
+
311
+ ## 3. Experiment 2: Uniform Grid Evaluation
312
+
313
+ ### 3.1 Purpose
314
+
315
+ Verify accuracy across the **entire** 5D domain, not just selected scenarios. This demonstrates that MoCaX maintains spectral accuracy everywhere in the parameter space.
316
+
317
+ ### 3.2 Configuration
318
+
319
+ | Parameter | Value |
320
+ |-----------|-------|
321
+ | Points per dimension | 10 |
322
+ | Total evaluation points | 100,000 (10^5) |
323
+ | Grid type | Uniform spacing |
324
+ | Coverage | Full domain in all 5 dimensions |
325
+
326
+ ### 3.3 Results
327
+
328
+ ```
329
+ GRID EVALUATION RESULTS
330
+ ======================================================================
331
+ Points evaluated: 100,000
332
+ Total MoCaX time: 43.263 s
333
+ Time per evaluation: 0.4326 ms
334
+ Evals per second: 2,311
335
+
336
+ Mean error: 0.002265%
337
+ Max error: 17.564287%
338
+ Std deviation: 0.131467%
339
+ Median error: 0.000002%
340
+ 95th percentile: 0.000180%
341
+ ======================================================================
342
+ ```
343
+
344
+ ### 3.4 Error Distribution
345
+
346
+ | Percentile | Error |
347
+ |------------|-------|
348
+ | Median (50th) | 0.000002% |
349
+ | 95th | 0.000180% |
350
+ | 99th | ~0.01% |
351
+ | Max | 17.56% |
352
+
353
+ **Key Observation**: 99.97% of points have error < 1%
354
+
355
+ ### 3.5 High-Error Point Analysis
356
+
357
+ Points with error > 1%: **27 out of 100,000 (0.03%)**
358
+
359
+ All high-error points share these characteristics:
360
+ - **Deep OTM**: S ~ 84-89, K = 107-110 (option ~20% out of the money)
361
+ - **Very short maturity**: T = 0.25 years
362
+ - **Low volatility**: sigma = 0.15
363
+ - **Tiny option values**: $0.0003 to $0.008
364
+
365
+ Example high-error point:
366
+ ```
367
+ S=84.44, K=110, T=0.25, sigma=0.15, r=0.01
368
+ Exact price: $0.000333
369
+ MoCaX price: $0.000391
370
+ Error: 17.56%
371
+ ```
372
+
373
+ **Explanation**: These are edge cases where the option is nearly worthless (sub-penny prices). The absolute error is ~$0.00006, but the tiny denominator inflates the percentage error. In practice, such options are not traded.
374
+
375
+ ---
376
+
377
+ ## 4. Conclusions
378
+
379
+ ### 4.1 Accuracy
380
+
381
+ - **Price**: Spectral accuracy (0.000% error) across all 11 scenarios
382
+ - **1st-order Greeks**: Delta, Rho accurate to 0.000%-0.005%
383
+ - **2nd-order Greeks**: Vega, Gamma, Vanna, Charm, Vomma, Veta accurate to <3%
384
+ - **Grid coverage**: 99.97% of 100,000 points have <1% error
385
+
386
+ ### 4.2 Performance
387
+
388
+ - **Build phase**: 161,051 evaluations in 1.064 seconds (151k evals/sec)
389
+ - **Query phase**: ~0.43 ms per evaluation (2,311 evals/sec)
390
+ - **Break-even**: After ~3 queries, pre-computation is worthwhile
391
+
392
+ ### 4.3 Key Insights
393
+
394
+ 1. **Error threshold controls price only**: Derivative accuracy is a consequence of polynomial smoothness, not a directly controlled parameter.
395
+
396
+ 2. **Vega consistently ~2% error**: This is inherent to Chebyshev approximation of the volatility sensitivity. The underlying function V(sigma) has steep curvature that requires more nodes to capture perfectly.
397
+
398
+ 3. **High errors at boundaries are acceptable**: The 0.03% of points with >1% error all have option values under $0.01 - these are not practically tradeable options.
399
+
400
+ 4. **No parameter dimension is special**: Accuracy is consistent whether varying S, K, T, sigma, or r - the 5D tensor captures all interactions correctly.
401
+
402
+ ### 4.4 Recommendation
403
+
404
+ MoCaX is suitable for production 5D Black-Scholes pricing where:
405
+ - Price accuracy is critical (achieved: 0.000%)
406
+ - Greeks are needed for hedging (achieved: <3% error)
407
+ - Many queries amortize the 1-second build cost
408
+ - Parameters vary across the full 5D space (not just 2D slices)
409
+
410
+ ---
411
+
412
+ ## Appendix: How to Reproduce
413
+
414
+ ```bash
415
+ # Run the full test suite
416
+ ./run_mocax_baseline.sh
417
+
418
+ # Or with custom grid density (default: 10)
419
+ N_GRID_POINTS=15 ./run_mocax_baseline.sh
420
+ ```
421
+
422
+ Test file: `/home/max/Documents/PyChebyshev/mocax_baseline.py`