Skip to main content

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 .

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

malatium-0.2.0.tar.gz (89.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

malatium-0.2.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file malatium-0.2.0.tar.gz.

File metadata

  • Download URL: malatium-0.2.0.tar.gz
  • Upload date:
  • Size: 89.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for malatium-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d736bfc1a448dc2c747544370cf8b9746d5ee1aca6a8848edb48b7a58154783
MD5 d03fb55c82e21d2099de5f0bba070806
BLAKE2b-256 a4b2222919e34f6abdfb02a551bbe02b032ba971368ed8136909545b4cad16e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for malatium-0.2.0.tar.gz:

Publisher: publish.yml on Atium-Research/malatium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malatium-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: malatium-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for malatium-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 951087e1a6f05625a241ef3ff0fc7ce9b20d96ec79069cbacde7899749e4adaf
MD5 b3980a4b07ab374dfd36d8ab7bff8b42
BLAKE2b-256 9b7c9ee43135f9004d25256a42f1c7a8af3426fa14ed70d02e4d729d95bea17d

See more details on using hashes here.

Provenance

The following attestation bundles were made for malatium-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Atium-Research/malatium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page