API reference
skepsis.evaluate.evaluate(returns, trials=None, params=None, freq='daily', chosen=None, pbo_blocks=16, n_resamples=5000, seed=0, thresholds=None)
Run every overfitting diagnostic the provided inputs allow. See README.
Source code in skepsis/evaluate.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
skepsis.evaluate.Result
dataclass
Everything skepsis concluded, plus the data the HTML report needs.
Source code in skepsis/evaluate.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
save_html(path)
Render the self-contained HTML report (report module lands in Task 10).
Source code in skepsis/evaluate.py
155 156 157 158 159 160 161 | |
to_dict()
JSON-serializable summary (scalars only, no arrays).
Source code in skepsis/evaluate.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
skepsis.verdict.Thresholds
dataclass
Default rule thresholds. fail => LIKELY_OVERFIT; warn counts toward WEAK/MODERATE.
Source code in skepsis/verdict.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
skepsis.core.psr
Probabilistic and Deflated Sharpe Ratio.
References: - Bailey & Lopez de Prado (2012), "The Sharpe Ratio Efficient Frontier", Journal of Risk 15(2). [PSR] - Bailey & Lopez de Prado (2014), "The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting and Non-Normality", Journal of Portfolio Management 40(5). [DSR]
Conventions: sr and sr_benchmark are PERIODIC (non-annualized) Sharpe
ratios; kurt is NON-excess kurtosis (normal = 3.0).
deflated_sharpe_ratio(sr, n_obs, skew, kurt, var_trial_sr, n_trials)
PSR evaluated against the expected max Sharpe of n_trials null strategies.
Source code in skepsis/core/psr.py
64 65 66 67 68 69 | |
expected_max_sharpe(var_trial_sr, n_trials)
E[max periodic SR] across n_trials strategies under the no-skill null.
E[max SR] ~= sqrt(V) * ((1-gamma) * z(1 - 1/N) + gamma * z(1 - 1/(N*e))) where gamma is the Euler-Mascheroni constant. Returns 0.0 for n_trials == 1 (a single trial has no selection bias; the formula diverges at N=1).
Source code in skepsis/core/psr.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
probabilistic_sharpe_ratio(sr, sr_benchmark, n_obs, skew, kurt)
P[true SR > sr_benchmark], correcting for sample length, skew and kurtosis.
PSR = Phi( (sr - sr) * sqrt(T - 1) / sqrt(1 - skewsr + (kurt - 1)/4 * sr^2) )
Source code in skepsis/core/psr.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
skepsis.core.pbo
Probability of Backtest Overfitting via CSCV.
Reference: Bailey, Borwein, Lopez de Prado & Zhu (2015), "The Probability of Backtest Overfitting", Journal of Computational Finance.
CSCV: split the (T, N) trial-returns matrix into S equal time blocks. For every combination of S/2 blocks used as in-sample (IS): rank trials IS, take the IS winner, find its relative rank omega among out-of-sample (OOS) scores, and compute the logit lambda = ln(omega / (1 - omega)). PBO is the fraction of combinations with lambda <= 0 (the IS winner lands in the bottom half OOS).
The default metric (periodic column Sharpe) runs on a fast path that combines
per-block sums and sums-of-squares instead of materializing submatrices.
Columns with zero variance score -inf so they rank last. A custom metric
callback forces the materializing path.
PboResult
dataclass
CSCV output. value is the PBO in [0, 1]; logits has one entry per combination.
Source code in skepsis/core/pbo.py
50 51 52 53 54 55 56 57 58 59 | |
cscv(trials, n_blocks=16, metric=None)
Run CSCV on a (T, N) matrix of per-period trial returns (columns = trials).
Source code in skepsis/core/pbo.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
validate_n_blocks(n_blocks)
Raise InvalidInputError unless n_blocks is an integer, even, and within [4, 24].
Source code in skepsis/core/pbo.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
skepsis.core.bootstrap
Stationary block bootstrap for Sharpe and drawdown confidence intervals.
References: - Politis & Romano (1994), "The Stationary Bootstrap", JASA 89(428). - Politis & White (2004), "Automatic Block-Length Selection for the Dependent Bootstrap", Econometric Reviews 23(1), with the Patton-Politis-White (2009) correction.
The no-skill p-value resamples the DEMEANED series with the same index matrix and reports (1 + #{SR_null >= SR_obs}) / (n_resamples + 1). Degenerate (exactly-constant) resamples score a signed-infinite Sharpe -- except an exactly-zero-mean constant draw, which scores exactly 0.0 and so correctly TIES a zero observed Sharpe -- and count toward that exceedance total; they are excluded from the CI/report distributions via the exact constancy mask (not finiteness, since a zero-mean constant draw is finite). A bootstrap whose resamples are ALL degenerate raises rather than attempting to form a CI. See BootstrapResult for the exact convention.
BootstrapResult
dataclass
Bootstrap distributions and the no-skill p-value. Sharpe values are annualized.
Degenerate (exactly constant) resamples score a signed-infinite Sharpe
(sign(mean) * inf), EXCEPT an exactly-zero-mean constant resample
(zero return, zero risk), which scores exactly 0.0 so it correctly
TIES a zero observed Sharpe (0.0 >= 0.0 is True) instead of vanishing
as sign(0) * inf == nan. Those rows count toward p_value_no_skill on
the null side (+inf and an exact-tying 0.0 are exceedances; -inf
is not), keeping the (1 + #exceedances) / (n_resamples + 1)
denominator exact. They are excluded from sharpe_ci and
sharpe_distribution via the exact constancy mask -- not finiteness,
since a zero-mean constant row is finite (0.0) but still degenerate;
n_degenerate_resamples reports how many raw-side resamples were
degenerate. If every raw-side resample is degenerate, bootstrap()
raises InvalidInputError instead of returning a result with no CI.
Source code in skepsis/core/bootstrap.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
bootstrap(returns, periods, n_resamples=5000, mean_block_length=None, seed=0, ci=0.95)
Stationary-bootstrap CIs for annualized Sharpe and max drawdown, plus a p-value against the no-skill (demeaned) null.
Source code in skepsis/core/bootstrap.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
politis_white_block_length(x)
Automatic mean block length for the stationary bootstrap (Politis-White 2004).
Source code in skepsis/core/bootstrap.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
stationary_bootstrap_indices(n_obs, mean_block_length, n_resamples, rng)
(n_resamples, n_obs) index matrix: geometric block lengths, circular wrap.
Stationary-bootstrap formulation: each position independently starts a new block with probability p = 1/mean_block_length (this IS the stationary bootstrap of Politis & Romano — geometric block lengths emerge from the per-position Bernoulli trials); block starts are uniform on [0, n_obs); within a block, indices continue circularly from the block's start.
Generated in row chunks of _CHUNK_ROWS to bound peak memory instead of
materializing several full (n_resamples, n_obs) temporaries at once; the
resulting seeded stream is otherwise identical in distribution but differs
bit-for-bit from earlier, fully-vectorized development builds.
Source code in skepsis/core/bootstrap.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
skepsis.core.sensitivity
Parameter-neighborhood stability: is the chosen configuration a plateau or a spike?
Method: k = min(2*d, n-1) nearest neighbors of the chosen configuration in z-scored parameter space (for interior points of a regular grid these are the orthogonal grid neighbors). stability_score = chosen_metric / median(neighbor metrics): ~1.0 on a plateau, >> 1.0 on an isolated spike (fitted to noise).
Edge conventions: - chosen metric <= 0 -> score = nan, SkepsisWarning (a non-positive chosen metric is its own problem; the ratio is meaningless) - neighbor median <= 0 < chosen -> score = inf, flagged, SkepsisWarning
SensitivityResult
dataclass
Neighborhood stability of the chosen parameter configuration.
Source code in skepsis/core/sensitivity.py
24 25 26 27 28 29 30 31 32 33 34 | |
sensitivity(params, metrics, chosen_index, spike_threshold=1.5)
Score the chosen configuration against its k nearest parameter neighbors.
Source code in skepsis/core/sensitivity.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |