pyvar-jupyter
%pyvar / %%pyvar IPython magics and rich HTML display for
pyvar.com's risk computation API. Built on top of
pyvar-client — this package adds
the notebook-ergonomics layer, not a second API client.
Install
pip install pyvar-jupyter
Installs pyvar-client as a dependency automatically.
Quick start
%load_ext pyvar_jupyter
%pyvar_key pyvar_... # or export PYVAR_API_KEY before starting the kernel
%pyvar market_risk.historical_simulation_var returns=[0.01,-0.02,0.015] portfolio_value=1000000
The result renders as a formatted HTML table in the cell output, and is also
returned to Out[] — result["var_abs"] works on it directly.
Line magic
Params as space-separated key=value tokens, each parsed with
ast.literal_eval (so numbers, lists, dicts, booleans, None all come
through as their real Python type, not strings). var.compute is the one
async function in the whole API (submit + poll, blocking until done) — see
pyvar_client's own VarNamespace docstring for why it's handled specially:
%pyvar var.compute returns=[0.01,-0.02,0.015] \
portfolio_value=1000000 confidence_level=0.99 n_simulations=100000
Cell magic
Same dispatch, params as a JSON object in the cell body — use this over the line form once params get large or nested (arrays of arrays, nested objects):
%%pyvar derivatives.heston_stochastic_volatility_model
{
"spot": 100.0,
"strike": 105.0,
"rate": 0.02,
"tau": 1.0,
"v0": 0.04,
"kappa": 2.0,
"theta": 0.04,
"sigma": 0.3,
"rho": -0.7,
"option_type": "call"
}
No params → discoverability
Calling either form with no parameters prints the function's docstring and
signature instead of making a doomed API call with zero fields — the same
convention pyvar's own CLI uses:
%pyvar market_risk.historical_simulation_var
historical_simulation_var(*, returns: 'list[float] | list[list[float]]', portfolio_value: 'float', confidence_level: 'float' = 0.99) -> 'dict[str, Any]'
Non-parametric Historical Simulation VaR.
Re-prices the portfolio under each observed historical return and reads the
empirical loss quantile — making no distributional assumption.
Returns:
The raw API response as a dict.
Display helper (no magics required)
pyvar_jupyter.show() wraps any pyvar_client result for the same rich
HTML rendering — useful in a loop or a script cell where you're calling
Client directly rather than through a magic:
from pyvar_client import Client
import pyvar_jupyter
client = Client(api_key="pyvar_...")
result = client.market_risk.historical_simulation_var(
returns=[0.01, -0.02, 0.015], portfolio_value=1_000_000,
)
pyvar_jupyter.show(result)
The wrapped object still behaves like the underlying dict — result["var_abs"],
.get(...), iteration — show() only changes how it renders.
Not in v1: LaTeX formula rendering (the portal's KaTeX treatment,
portal/pyvar.js's _renderFormula). That metadata lives in
portal/functions.json server-side and isn't exposed through the REST API or
pyvar_client yet — pulling it in here would mean either a new network call
per result or a second embedded copy that can drift from the real one. Left
for a follow-up once that metadata has a real client-facing source.
Session config magics
%pyvar_key pyvar_... # set/replace the API key for this kernel (in-memory only)
%pyvar_base_url http://localhost:8000 # point at a local/dev deployment instead of prod
Neither is required if PYVAR_API_KEY / PYVAR_API_BASE_URL are already set
as environment variables before the kernel starts — same variable names
pyvar-client's own CLI and the pyvar-mcp plugin use.
Examples
Worked notebooks in examples/:
01_portfolio_var.ipynb— Monte Carlo VaR/CVaR on a synthetic portfolio02_basel_backtest.ipynb— Basel traffic-light backtest (Kupiec/Christoffersen)03_derivatives_greeks.ipynb— an exotic option pricer with bump-and-reprice Greeks04_credit_risk_expected_loss.ipynb— IRB expected loss (EL = PD × LGD × EAD) for a single exposure05_liquidity_coverage_ratio.ipynb— Basel III LCR with the 75% inflow cap06_operational_var.ipynb— OpVaR/expected shortfall from a simulated annual-loss distribution07_portfolio_max_sharpe.ipynb— SLSQP-optimised maximum-Sharpe-ratio portfolio weights08_basel_cet1_ratio.ipynb— Basel III CET1 capital ratio against the 4.5% minimum09_alm_eve_sensitivity.ipynb— EVE sensitivity under IRRBB's six standard rate shocks
All nine cover a different one of pyvar's 8 risk domains (Market Risk appears twice: VaR and the Basel backtest).
Development
pip install -e ".[dev]"
pytest -v --cov=pyvar_jupyter --cov-report=term-missing
No real HTTP calls in the test suite — httpx.MockTransport intercepts every
request at the transport layer, same rule pyvar-client's own tests follow.
License
Apache-2.0. See LICENSE.
Metadata
Release files for pyvar-jupyter 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyvar_jupyter-0.1.0.tar.gz | 19.1 kB | With provenance | Details for pyvar_jupyter-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyvar_jupyter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyvar_jupyter-0.1.0-py3-none-any.whl |
Total release size: 35.0 kB
Release files / pyvar_jupyter-0.1.0.tar.gz
| Download URL | pyvar_jupyter-0.1.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0242a12fa825290f4356cd592fd20723f9e47995f34458da2189da358c811854
|
|
BLAKE2b-256 checksum How to use checksums |
d6e4b2b7c909fb999d1683882fe21ed306547805c7fbb3a319a89340cedf3689
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pyvar_jupyter-0.1.0-py3-none-any.whl
| Download URL | pyvar_jupyter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85e5466414186f5e3fc920de42bf604a5e895d174d9b616f3550bea7dc40762b
|
|
BLAKE2b-256 checksum How to use checksums |
4474dc0728bfa1df03a402559bd28db87c540693717ccc8fdffef92be0128719
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logSecurity for pyvar-jupyter 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyvar_jupyter-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.