Malatium
Volatility portfolio backtesting and optimization in dollar vega, built on Polars and CVXPY. Sibling of atium with vega in place of capital.
Malatium is data-agnostic. It takes frames in through providers and never reads a store: the reference-return panel it prices a book off, the risk model tables and the scores or alphas all come from the caller (in the Atium stack, from ml-data-pipelines through ml-data-access).
Installation
pip install malatium
Units
Every position is a number of units of a reference instrument per name (in the Atium stack, one delta-hedged ATM straddle rolled on a fixed rule). A unit is marked by its dollar vega, the dollars of P&L per one-point move in implied vol. The return of a unit is its daily P&L divided by its dollar vega at inception, pnl_per_vega. Strategy weights are fractions of a gross vega budget; the backtester turns a weight into units by multiplying by the budget and dividing by the unit's dollar vega at today's close.
Quick start
import datetime as dt
from malatium.backtester import Backtester
from malatium.optimizer import MVO, GrossCap, MaxUtility, NetVegaNeutral, TurnoverPenalty
from malatium.providers import PanelProvider, TradingCalendar
from malatium.results import BacktestResults
from malatium.risk_model import FactorRiskModelConstructor
from malatium.strategy import OptimizationStrategy, QuantileSpreadStrategy
# Frames in the schemas of `malatium.schemas`, loaded however you like.
calendar = TradingCalendar(sessions)
reference = PanelProvider(reference_returns_df)
# A rank book: long the cheapest decile of scores, short the richest.
rank_book = QuantileSpreadStrategy(
PanelProvider(scores_df), universe=PanelProvider(universe_df), quantile=0.1
)
# A mean-variance book: alphas against a factor risk model.
risk_model = FactorRiskModelConstructor(
PanelProvider(factor_loadings_df),
PanelProvider(factor_covariances_df),
PanelProvider(idio_vol_df),
)
optimizer = MVO(
objectives=[MaxUtility(risk_aversion=0.2), TurnoverPenalty(cost=0.1)],
constraints=[NetVegaNeutral(0.025), GrossCap(1.0)],
)
mvo_book = OptimizationStrategy(PanelProvider(alphas_df), risk_model, optimizer)
records_df = Backtester().run(
calendar,
reference,
mvo_book,
start=dt.date(2018, 7, 2),
end=dt.date(2025, 6, 30),
gross_vega=20_000.0,
rebalance_frequency="weekly",
)
results = BacktestResults(records_df)
results.summary()
results.factor_regression(factor_returns_df)
BacktestResults.decile_table(scores_df, reference_returns_df, horizon_days=60)
What is here
| module | holds |
|---|---|
schemas.py, types.py |
dataframely schemas for every frame in and out |
data.py |
provider protocols: get(date_) for scores, alphas, universe, reference returns, risk model tables |
providers.py |
TradingCalendar, PanelProvider over frames in memory |
strategy.py |
Strategy, QuantileSpreadStrategy, OptimizationStrategy |
optimizer/ |
MVO; objectives MaxUtility, TurnoverPenalty; constraints NetVegaNeutral, FactorNeutral, PerNameCap, GrossShortCap, GrossCap |
risk_model/ |
RiskModel, FactorRiskModel (Sigma = B F B' + D²), FactorRiskModelConstructor |
backtester.py |
the daily loop over the reference-return panel |
results.py |
BacktestResults: summary, factor regression, decile table, plots (pip install 'malatium[plot]') |
Reference returns
ReferenceReturnsSchema is the contract between the data and the engine. Per (date, symbol):
| column | meaning |
|---|---|
pnl_per_vega |
the unit's P&L today per dollar of its inception vega |
cost_per_vega |
rolling and hedging cost today, same scale |
exit_cost_per_vega |
half-spread to close the unit today, same scale |
dollar_vega |
the unit's dollar vega at today's close |
entry_vega |
inception dollar vega of the unit held into today |
event |
open, roll, forced_close or empty |
Between rebalances the backtester holds a constant number of units, so its P&L is units × entry_vega × pnl_per_vega and its cost |units| × entry_vega × cost_per_vega; a rebalance trades |Δunits| × half-spread. Costs are charged at cost_fraction of those amounts, zero by default.
A strategy never sees the close it trades at. On a rebalance session the backtester asks for weights as of the previous session and executes them at today's close, and the decile table's forward window starts after that executable close. The lag is structural and has no switch: a score built from the same quotes as the marks would otherwise collect bid-ask bounce that no trader can.
Development
uv sync --all-extras
uv run pytest
uv run ruff check . && uv run ruff format .
Metadata
Release files for malatium 0.2.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 |
|---|---|---|---|---|
| malatium-0.2.0.tar.gz | 89.7 kB | With provenance | Details for malatium-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| malatium-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for malatium-0.2.0-py3-none-any.whl |
Total release size: 109.8 kB
Release files / malatium-0.2.0.tar.gz
| Download URL | malatium-0.2.0.tar.gz |
|---|---|
| Size | 89.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d736bfc1a448dc2c747544370cf8b9746d5ee1aca6a8848edb48b7a58154783
|
|
BLAKE2b-256 checksum How to use checksums |
a4b2222919e34f6abdfb02a551bbe02b032ba971368ed8136909545b4cad16e1
|
| 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 Sep 13, 2026.
Transparency logRelease files / malatium-0.2.0-py3-none-any.whl
| Download URL | malatium-0.2.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
951087e1a6f05625a241ef3ff0fc7ce9b20d96ec79069cbacde7899749e4adaf
|
|
BLAKE2b-256 checksum How to use checksums |
9b7c9ee43135f9004d25256a42f1c7a8af3426fa14ed70d02e4d729d95bea17d
|
| 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 Sep 13, 2026.
Transparency logSecurity for malatium 0.2.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for malatium-0.2.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 Sep 13, 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.