Math Verification
INTERNALEvery shared routine is checked against a value that can be worked out by hand or from a textbook.
Passed
36 / 36
Failed
0
Statistics
| Check | Expected | Actual | Result |
|---|---|---|---|
| mean([2,4,4,4,5,5,7,9]) | 5.000000 | 5.000000 | PASS |
| std (population) | 2.000000 | 2.000000 | PASS |
| std (sample) | 2.138090 | 2.138090 | PASS |
| cov(x, x) = var(x) | 4.571429 | 4.571429 | PASS |
| corr(x, 2x+1) = 1 | 1.000000 | 1.000000 | PASS |
| corr(x, -x) = -1 | -1.000000 | -1.000000 | PASS |
| skewness (symmetric set) | 0.000000 | 0.000000 | PASS |
| excess kurtosis of uniform 1..9 | -1.230000 | -1.230000 | PASS |
| quantile(0.5) of 1..5 | 3.000000 | 3.000000 | PASS |
| quantile(0.25) of 1..5 | 2.000000 | 2.000000 | PASS |
Linear algebra
| Check | Expected | Actual | Result |
|---|---|---|---|
| Cholesky L[0][0] of textbook matrix | 2.000000 | 2.000000 | PASS |
| Cholesky L[2][2] | 3.000000 | 3.000000 | PASS |
| L·Lᵀ reproduces A[1][2] | -43.000000 | -43.000000 | PASS |
| inverse([[4,7],[2,6]])[0][0] | 0.600000 | 0.600000 | PASS |
| inverse([[4,7],[2,6]])[0][1] | -0.700000 | -0.700000 | PASS |
| matVec row 1 | 39.000000 | 39.000000 | PASS |
Normal
| Check | Expected | Actual | Result |
|---|---|---|---|
| pdf(0) = 1/√(2π) | 0.398942 | 0.398942 | PASS |
| cdf(0) | 0.500000 | 0.500000 | PASS |
| cdf(1.96) | 0.975002 | 0.975002 | PASS |
| cdf(-2.33) | 0.009903 | 0.009903 | PASS |
| inverse cdf(0.975) | 1.959964 | 1.959963 | PASS |
| inverse cdf(0.01) | -2.326348 | -2.326347 | PASS |
| round trip cdf(inv(0.3)) | 0.300000 | 0.300000 | PASS |
Random
| Check | Expected | Actual | Result |
|---|---|---|---|
| MT19937 normal sample mean ≈ 0 | 0.000000 | -0.000334 | PASS |
| MT19937 normal sample std ≈ 1 | 1.000000 | 1.000534 | PASS |
| same seed reproduces the same draw | 0.000000 | 0.000000 | PASS |
| uniform sample mean ≈ 0.5 | 0.500000 | 0.499497 | PASS |
Regression
| Check | Expected | Actual | Result |
|---|---|---|---|
| OLS intercept of y = 3x + 2 | 2.000000 | 2.000000 | PASS |
| OLS slope of y = 3x + 2 | 3.000000 | 3.000000 | PASS |
| OLS R² of exact fit | 1.000000 | 1.000000 | PASS |
Time series
| Check | Expected | Actual | Result |
|---|---|---|---|
| ADF rejects a unit root for a mean-reverting OU series | statistic < -2.86 | statistic = -4.258 | PASS |
| ADF fails to reject for a random walk | statistic > -2.86 | statistic = -1.652 | PASS |
| OU half-life is short (κ = 6/yr ⇒ ≈ 29 days) | between 10 and 60 days | 30.80 days | PASS |
Generators
| Check | Expected | Actual | Result |
|---|---|---|---|
| GBM asset A annualised vol ≈ 20% | 0.200000 | 0.198179 | PASS |
| GBM asset B annualised vol ≈ 30% | 0.300000 | 0.297578 | PASS |
| GBM realised correlation ≈ 0.60 | 0.600000 | 0.610961 | PASS |