Skip to content

Add ssvi#86

Open
lsbardel wants to merge 2 commits into
mainfrom
ls-ssvi
Open

Add ssvi#86
lsbardel wants to merge 2 commits into
mainfrom
ls-ssvi

Conversation

@lsbardel

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 26, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an SSVI (Surface SVI) volatility parametrisation to the options module, along with documentation and site enhancements to support bibliographic cross-references and richer MkDocs output.

Changes:

  • Add SSVI model with calibration helpers (fit, fit_surface) and comprehensive unit tests.
  • Improve docs bibliography linking and styling (BibTeX entries + MkDocs config updates), and add an API docs page for SSVI.
  • Miscellaneous robustness/typing tweaks across app APIs and options pricing.

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
quantflow/ta/paths.py Adds typing annotation for tau list in Hurst exponent calculation.
quantflow/options/svi.py Updates SVI docstring to link to bibliography entries.
quantflow/options/surface.py Forces Black price sum to float before sigfig/Decimal conversion.
quantflow/options/ssvi.py Introduces new SSVI model, analytics, and calibration routines.
quantflow_tests/test_ssvi.py Adds tests covering SSVI shape, variance/IV, arbitrage checks, and calibration.
pyproject.toml Bumps pandas + dev tooling minimum versions.
mkdocs.yml Adds site description, nav entry for SSVI, enables md_in_html, and includes extra CSS.
docs/stylesheets/bibliography.css Adds bibliography entry highlighting/styling.
docs/references.bib Adds Gatheral SVI and Gatheral-Jacquier references.
docs/contributing.md Tightens wording around responsibility for AI-assisted contributions.
docs/bibliography.md Wrapes bibliography entries for styling and fragment targeting.
docs/bib2md.py Changes bibliography generator output to emit wrapped entries.
docs/api/options/ssvi.md Adds mkdocstrings page for quantflow.options.ssvi.SSVI.
app/utils/paths.py Injects social OpenGraph/Twitter meta tags into MkDocs pages.
app/api/volatility.py Ensures ttm_grid is JSON-friendly (float list).
app/api/cointegration.py Suppresses ComplexWarning and coerces eigenvector to real values.
.github/instructions/release.instructions.md Adds applyTo front matter.
.github/instructions/makefile.instructions.md Adds applyTo front matter.
.github/copilot-instructions.md Fixes documented test command and doc examples output path.
Comments suppressed due to low confidence (2)

quantflow/options/ssvi.py:160

  • fit() uses np.interp(0.0, k_arr, w_obs) and then runs least-squares without checking that inputs are non-empty, same-shape, and sorted by k. np.interp requires an increasing x-grid, and empty/mismatched inputs will currently produce nan initial guesses or broadcast errors.
        k_arr = np.asarray(k, dtype=float)
        iv_arr = np.asarray(iv, dtype=float)
        w_obs = iv_arr**2 * ttm

        atm_var = float(np.interp(0.0, k_arr, w_obs)) if k_arr.size else w_obs.mean()
        x0 = [0.0, 1.0, max(atm_var, 1e-4)]

quantflow/options/ssvi.py:213

  • fit_surface() collects slices without validating/sorting each (k, iv) pair. This can break the ATM interpolation (np.interp expects sorted k) and can yield nan initial thetas if a slice is empty.
        data = []
        thetas0 = []
        for k, iv, ttm in slices:
            k_arr = np.asarray(k, dtype=float)
            iv_arr = np.asarray(iv, dtype=float)
            w_obs = iv_arr**2 * ttm
            data.append((k_arr, w_obs))
            atm = float(np.interp(0.0, k_arr, w_obs)) if k_arr.size else w_obs.mean()
            thetas0.append(max(atm, 1e-4))

Comment thread quantflow/options/ssvi.py Outdated
Comment on lines +103 to +113
def iv(
self,
k: Annotated[ArrayLike, Doc("Log-moneyness log(K/F), scalar or array")],
ttm: Annotated[float, Doc("Time to maturity in years")],
) -> np.ndarray:
r"""Implied volatility $\sigma(k) = \sqrt{w(k) / \tau}$.

Returns an array of the same shape as $k$. The SSVI total variance is
strictly positive for $|\rho| < 1$, so no clipping is required.
"""
return np.sqrt(self.total_variance(k) / ttm)
Comment thread docs/bib2md.py
Comment on lines 147 to 151
if suffix:
body = f"{body}, {suffix}"

return f"#### {key}\n\n{body}\n"
return f'<div class="bib-entry" markdown>\n\n#### {key}\n\n{body}\n\n</div>\n'

Comment thread docs/bibliography.md

---

<div class="bib-entry" markdown>
@codecov-commenter

codecov-commenter commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.18405% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.86%. Comparing base (5e16f37) to head (51bc6af).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
app/utils/paths.py 18.18% 9 Missing ⚠️
quantflow/options/ssvi.py 95.17% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   88.75%   88.86%   +0.10%     
==========================================
  Files          84       85       +1     
  Lines        5142     5300     +158     
==========================================
+ Hits         4564     4710     +146     
- Misses        578      590      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 27, 2026 09:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

quantflow/options/ssvi.py:328

  • fit_surface() doesn’t validate that each slice has non-empty k/iv arrays of matching shape. Empty slices will yield nan initial thetas and mismatched shapes can broadcast, producing incorrect residual vectors.
        for k, iv, ttm in slices:
            k_arr = np.asarray(k, dtype=float)
            iv_arr = np.asarray(iv, dtype=float)
            w_obs = iv_arr**2 * ttm
            data.append((k_arr, w_obs, float(ttm)))

Comment thread app/api/cointegration.py
# discarding noise-level imaginary parts
warnings.simplefilter("ignore", np.exceptions.ComplexWarning)
johansen_result = coint_johansen(scaled, det_order=0, k_ar_diff=1)
deltas = np.real_if_close(johansen_result.evec[:, 0]).real / std.values
Comment thread quantflow/options/ssvi.py
Comment on lines +266 to +268
k_arr = np.asarray(k, dtype=float)
iv_arr = np.asarray(iv, dtype=float)
w_obs = iv_arr**2 * ttm
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.

3 participants