Skip to content

Fix the VaR quick start install and var-backtest on long samples - #5

Merged
ult666666 merged 1 commit into
mainfrom
fix/review-var-quickstart
Nov 2, 2026
Merged

ult666666 merged 1 commit into
mainfrom
fix/review-var-quickstart

Conversation

@ult666666

Copy link
Copy Markdown
Owner

Independent review of the VaR model validation release (#4). The forecasts, tests, Basel table and Z2 code held up. The quick start install and one CLI path needed fixes.

What changes

# Severity Finding How it was reproduced Fix
1 High The README quick start installs the v0.1.0 release wheel (tag d0d304b, 2026-10-24). That release predates quantkit.var (merged 2026-11-01). Following the README as written, the VaR doctest block fails with ModuleNotFoundError: No module named 'quantkit.var', and quantkit var-backtest is invalid choice. Downloaded the release wheel: it has no quantkit/var/. Installed it in a fresh Python 3.12 venv and ran python -m doctest README.md and quantkit var-backtest --help. The quick start installs from GitHub (pip install "git+https://github.com/ult666666/quantkit.git") and says what the v0.1.0 wheel lacks. New CI step: build the wheel, install it in a clean venv, run the README doctests and var-backtest --help against it (about 6 s).
2 Medium quantkit var-backtest printed its table, then exited with status 1 whenever the sample was too long for null_rejection_rates to enumerate. The message was advice meant for library users. 20 years of synthetic daily prices (quantkit simulate --days 5040), then quantkit var-backtest ... --level 0.95: quantkit: error: enumerating 4789 days with up to 369 exceptions is too slow; simulate i.i.d. Bernoulli exceptions instead. The command catches that limit and only leaves out the exact-size sentence: "the exact size of the tests is not computed".
3 Low quantkit --help described the tool as "Options pricing, portfolio optimization and backtesting". quantkit --help. Adds "and VaR model validation".

CHANGELOG.md has an Unreleased "Fixed" section. The README's sentence about what CI runs mentions the wheel doctests.

Verification

  • New test_var_backtest_handles_samples_too_long_for_the_exact_size fails on main (main() returns 1) and passes here.
  • The v0.1.0 wheel fails the README doctests in the VaR block. These pass the doctests:
    • the wheel built from this branch, installed in a clean venv;
    • pip install "git+https://github.com/ult666666/quantkit.git" with pip in a fresh Python 3.13 venv, which also runs quantkit var-backtest.
  • uv run pytest --doctest-glob=README.md --cov=quantkit: 435 passed, 99.62% coverage.
  • uv run ruff check ., uv run ruff format --check . and uv run mypy pass.

Checked in the review with no change needed:

  • From source in a clean export of main:
    • uv sync, uv run quantkit --help and the README doctests pass;
    • all 8 $ commands in the README's console blocks print exactly the documented output;
    • examples/var_backtest.py and examples/var_size_power.py (36 s) print exactly the README tables.
  • Look-ahead: each forecast window ends the day before the forecast. FHS standardizes each return by the volatility forecast made before it. tests/test_var_forecasts.py tests this for all four methods.
  • LR statistics:
    • finite with zero exceptions, all exceptions and no consecutive pairs;
    • the exact-size recursion rebuilds the transition counts correctly;
    • the chi-squared cutoffs match the p-value rule.
  • The Basel zones, plus factors and cumulative probabilities match the 1996 Table 2.
  • Z2 matches the Acerbi and Székely definition. The Monte Carlo p-value is (1 + #{Z_sim <= Z_obs}) / (N + 1).

Limits

  • No new release is cut here; releases are out of scope for this review. Until one is, the release page still offers the 0.1.0 wheel without quantkit.var. The README now says so.
  • The exact size is still not available for samples above the enumeration limit. The CLI says so instead of failing.

Generated by Claude Code

Review of the VaR model validation release (#4) found three problems.

The README quick start told users to pip install the v0.1.0 release
wheel. That release predates quantkit.var. Followed as written, the
third README doctest block fails with ModuleNotFoundError: No module
named 'quantkit.var', and `quantkit var-backtest` is an invalid choice.
Cutting a release is out of scope, so the quick start now installs from
GitHub and says what the v0.1.0 wheel lacks. CI gains a step that builds
the wheel, installs it in a clean environment and runs the README
doctests against it.

`quantkit var-backtest` printed its table, then exited with status 1 when
the sample was too long for null_rejection_rates to enumerate. One case
is 20 years of daily returns at 95%: "enumerating 4789 days with up to
369 exceptions is too slow". The command now only leaves out the
exact-size note. `quantkit --help` now mentions VaR model validation.

Verification:
- New test_var_backtest_handles_samples_too_long_for_the_exact_size
  fails on main (main() returns 1) and passes with the fix.
- The v0.1.0 wheel, installed in a fresh venv: the README doctests fail
  in the VaR block and var-backtest is rejected. The wheel built from
  this branch, and pip install of git+https://github.com/ult666666/
  quantkit.git, pass the README doctests (about 6 s for the CI step).
- uv run pytest --doctest-glob=README.md --cov=quantkit: 435 passed,
  99.62% coverage. ruff check, ruff format --check and mypy pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016h2RvhZFj77hPxFn8TQUqq
@ult666666
ult666666 merged commit 6ef6c76 into main Nov 2, 2026
6 checks passed
@ult666666
ult666666 deleted the fix/review-var-quickstart branch November 4, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants