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.
Development
uv sync --all-extras
uv run pytest
uv run ruff check . && uv run ruff format .
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file malatium-0.1.0.tar.gz.
File metadata
- Download URL: malatium-0.1.0.tar.gz
- Upload date:
- Size: 89.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7e45f1e75473f42fb06bb6338647be2adb4356946c7687e3189c7b08b938abe
|
|
| MD5 |
4b189729bd9dcd58bf29fddf384b5b80
|
|
| BLAKE2b-256 |
c606d054ea64ab8f8f6e3d6d14003b52ea9d843bcbd22b17941e5bbc46b73825
|
Provenance
The following attestation bundles were made for malatium-0.1.0.tar.gz:
Publisher:
publish.yml on Atium-Research/malatium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
malatium-0.1.0.tar.gz -
Subject digest:
e7e45f1e75473f42fb06bb6338647be2adb4356946c7687e3189c7b08b938abe - Sigstore transparency entry: 2820435162
- Sigstore integration time:
-
Permalink:
Atium-Research/malatium@f3edcc2ab92d39245086fb6aaf20807b64d24627 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Atium-Research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f3edcc2ab92d39245086fb6aaf20807b64d24627 -
Trigger Event:
push
-
Statement type:
File details
Details for the file malatium-0.1.0-py3-none-any.whl.
File metadata
- Download URL: malatium-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecd36980288386a9dff27ef1fe6b17683848c86350955aed68b042323535a31c
|
|
| MD5 |
934e5e428199d16f75f91f9e74d68d96
|
|
| BLAKE2b-256 |
ccdf14e5cec570a74e534f0a94e6f23840d17633e98265b137887638fb881945
|
Provenance
The following attestation bundles were made for malatium-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Atium-Research/malatium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
malatium-0.1.0-py3-none-any.whl -
Subject digest:
ecd36980288386a9dff27ef1fe6b17683848c86350955aed68b042323535a31c - Sigstore transparency entry: 2820435209
- Sigstore integration time:
-
Permalink:
Atium-Research/malatium@f3edcc2ab92d39245086fb6aaf20807b64d24627 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Atium-Research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f3edcc2ab92d39245086fb6aaf20807b64d24627 -
Trigger Event:
push
-
Statement type: