Skip to main content

kolmo

Energy market analytics for Python — statistics, curves, spreads, risk, and project economics.

pip install kolmo-stats
from kolmo import crack_spread, curve_shape, historical_var, npv, breakeven_price

What is kolmo?

kolmo provides simple, well-documented, mathematically sound tools for energy traders, analysts, and risk teams — focused on oil, gas, LNG, power, and energy derivatives.

It works with data you already have: pandas Series, DataFrames, NumPy arrays, lists, and dicts. No API keys. No data downloads. No dependencies beyond the standard scientific Python stack.


Installation

pip install kolmo-stats

Requires Python >= 3.10. Dependencies: numpy, pandas, scipy, networkx.


Quickstart

import numpy as np
from kolmo import (
    crack_spread, curve_shape, curve_slope,
    historical_var, npv, breakeven_price, lng_arbitrage,
)

# Brent forward curve
brent = {"M1": 84.5, "M2": 83.2, "M3": 82.1, "M6": 80.5, "M12": 78.0}
print(curve_shape(brent))        # 'backwardation'
print(curve_slope(brent))        # -1.52  (negative = backwardation)

# Refinery margin
crack = crack_spread(crude=80, gasoline=103, distillate=110, ratio="3-2-1")
print(f"3-2-1 crack: ${crack:.2f}/bbl")

# LNG arbitrage
arb = lng_arbitrage(14.0, 3.5, freight_cost=2.0, liquefaction_cost=2.5,
                    regas_cost=0.3, boil_off_cost=0.2)
print(f"LNG arb: ${arb:.2f}/MMBtu")    # positive = arb is open

# Historical VaR
returns = np.random.randn(500) * 2
print(f"VaR 95%: ${historical_var(returns):,.0f}")

# Project NPV
cashflows = [80, 120, 140, 130, 110, 90, 70, 50, 30]
print(f"NPV: ${npv(cashflows, discount_rate=0.12, initial_investment=400):.1f}M")

# Breakeven oil price
price = breakeven_price(
    capex=500_000_000,
    fixed_opex=[30_000_000] * 15,
    variable_opex_per_unit=12.0,
    production=[5_000_000] * 15,
    discount_rate=0.10,
)
print(f"Breakeven: ${price:.2f}/bbl")

The 20 public functions

Statistics

Function Description
mean(values) Arithmetic mean with NaN handling
weighted_mean(values, weights) Weighted average (VWAP, exposure-weighted)
rolling_zscore(series, window) How extreme is the current value vs recent history
seasonal_zscore(series, period) Z-score vs seasonal group (month, quarter, week)
rolling_correlation(x, y, window) Dynamic correlation between two series
lead_lag_correlation(x, y, max_lag) Which market moves first

Curves

Function Description
curve_shape(curve) Classify as backwardation, contango, flat, or mixed
calendar_spread(curve, near, far) Near minus far contract price
butterfly_spread(curve, front, middle, back) Front - 2*middle + back
roll_yield(near, far, days_between) Annualised yield from rolling a futures position
curve_slope(curve) Average first derivative (steepness of the curve)

Spreads

Function Description
crack_spread(crude, gasoline, distillate, ratio) Refinery margin: 3-2-1, 2-1-1, or simple
spark_spread(power, gas, heat_rate) Gas-fired generation margin
lng_arbitrage(destination, source, freight, ...) LNG netback arbitrage value

Risk

Function Description
historical_var(returns, confidence) Value at Risk from historical distribution
expected_shortfall(returns, confidence) Average loss beyond VaR (CVaR)
scenario_pnl(positions, shocks) Portfolio P&L under price shocks
hedge_ratio(asset_returns, hedge_returns) Minimum variance hedge ratio

Project Economics

Function Description
npv(cashflows, discount_rate) Net Present Value
breakeven_price(capex, opex, production, rate) Minimum price for NPV = 0

explain=True

Every function accepts explain=True and returns a dict with the result, a plain-English explanation, the formula, and the key inputs.

from kolmo import crack_spread
print(crack_spread(80, 103, 110, ratio="3-2-1", explain=True))
# {
#   'result': 12.67,
#   'explanation': 'Refinery crack spread using the 3-2-1 ratio.',
#   'formula': '((2 * gasoline) + distillate - (3 * crude)) / 3',
#   'inputs': {'crude': 80.0, 'gasoline': 103.0, 'ratio': '3-2-1'}
# }

Internal engine layer

kolmo uses an internal kolmo.engine layer for numerical routines:

kolmo.curve_slope(brent_curve)
    └── kolmo.engine.numerical.average_slope(prices)
            └── numpy.gradient(prices)    # default Python backend
            └── kolmo._ext.gradient(...)  # future C++ backend

This layer is not part of the public API. It exists so that future versions can add high-performance backends for simulation-heavy models while keeping the same public API.

Strategic note: kolmo starts with pure Python for simplicity and transparency. The architecture includes an internal engine layer so that future versions can add high-performance C++ backends for simulation-heavy and optimisation-heavy energy models, while preserving the same simple Python API. See cpp/DESIGN.md.


Running tests

pip install -e ".[dev]"
pytest tests/ -v

107 tests, all green.


Contributing

See CONTRIBUTING.md. Four levels: market knowledge, formulas, analytical models, and numerical engine improvements.

License

MIT

Metadata

Release files for kolmo-stats 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kolmo-stats 0.2.0
File Size Uploaded Provenance Actions
kolmo_stats-0.2.0.tar.gz 29.0 kB With provenance Details for kolmo_stats-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kolmo-stats 0.2.0
File Interpreter ABI Platform Actions
kolmo_stats-0.2.0-py3-none-any.whl Python 3 none any Details for kolmo_stats-0.2.0-py3-none-any.whl

Total release size: 63.6 kB

Release files / kolmo_stats-0.2.0.tar.gz

Download URL kolmo_stats-0.2.0.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
758ea1a18735e4f70d984ec1c6cae032d047e8e0a4ede9ecf238c9ad0a2d060d
BLAKE2b-256 checksum
How to use checksums
dda1f7c3893f4a71cb04c0b3d229dea273e5a1a78c4798998722916556ff7d9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 7, 2026.

Transparency log

Release files / kolmo_stats-0.2.0-py3-none-any.whl

Download URL kolmo_stats-0.2.0-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a409a11341f440149f970f58dfe34c0023ad9d17db505584d7574a279d5963ac
BLAKE2b-256 checksum
How to use checksums
d8f31470e8852656bdf069e98acfdffde3204fcd94dfe4e848f7e4e66a5f0d32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 7, 2026.

Transparency log

Security for kolmo-stats 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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kolmo_stats-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 May 7, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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