Skip to main content

Utilities for crude-oil futures data analysis: MultiIndex CSV loading, dynamic butterfly spreads, roll-period splitting, and normalized plotting.

Project description

data-energy-ff

CI PyPI version Python versions License: MIT

A small toolkit of helpers for crude-oil futures data analysis — loading pipeline CSVs into tidy pandas MultiIndex frames, building butterfly spreads from sequential outrights, splitting a series into roll-period windows, and quick normalized plots.

Installation

From PyPI (once published):

pip install data-energy-ff

Latest from source:

pip install "git+https://github.com/shubhquant1125ff-commits/pythonlib.git"

Quick start

import data_energy_ff as de

# 1. Load a futures CSV saved by the pipeline (restores the MultiIndex columns)
df = de.read_futures_csv_shubh("cl_outrights_1min.csv")

# 2. Build butterfly spreads from the sequential outrights (c1, c2, c3, ...)
flies = de.calculate_dynamic_butterflies(df)

# 3. Split a time series into pre / during / post roll windows
pre, during, post = de.split_by_roll_period(df, product="BRENT")

# 4. Compare two columns on a z-score normalized axis
de.plot_two_cols_normalized(df, ("c1", "weighted_mid"), ("c2", "weighted_mid"))

API

read_futures_csv_shubh(path, SEP="||")

Read a CSV saved by the futures pipeline and rebuild the clean MultiIndex DataFrame it was saved from. The first line is expected to be a metadata comment (#meta:<freq>||<level0_name>||<level1_name>), and column headers are SEP-joined tuples such as c1||weighted_mid. The datetime index is parsed as UTC and returned tz-naive.

calculate_dynamic_butterflies(df)

Build dynamic butterfly spreads from a MultiIndex frame of outrights. Level 0 holds the sequential outrights (c1, c2, ...) and level 1 holds contract and weighted_mid. For N outrights it returns N-2 butterflies priced as leg1 - 2*leg2 + leg3, with concatenated contract names. Raises ValueError if fewer than three outrights are present.

split_by_roll_period(df, product="BRENT")

Split a DatetimeIndex frame into (pre, during, post) roll-period windows using business-day-of-month thresholds. Windows adjust by product (BRENT/LCO, WTCL/CL/WTI, with a default fallback). Raises ValueError if the index is not a DatetimeIndex.

plot_two_cols_normalized(df, col1, col2)

Z-score normalize two columns and plot them together with a zero reference line, so you can see when each is above or below its own average.

Dependencies

Runtime: numpy, pandas, matplotlib, seaborn, plotly.

Development

git clone https://github.com/shubhquant1125ff-commits/pythonlib.git
cd pythonlib
python -m pip install -e ".[dev]"
pytest

See CONTRIBUTING.md for the full workflow and release steps.

License

MIT © Deepanshu Goyal and Shubh

Project details


Download files

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

Source Distribution

data_energy_ff-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

data_energy_ff-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file data_energy_ff-0.1.0.tar.gz.

File metadata

  • Download URL: data_energy_ff-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for data_energy_ff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c4fef06c163658a9a6a6a793c957384094f261dd0fa72fb36e0779c15c02841
MD5 01b5a123826cd4eb06f0c3bb85e621ad
BLAKE2b-256 d3c33ac3872e08cd5a5b3139abdfcd469b8d8b01c048a0b0d25f25bf40305f4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for data_energy_ff-0.1.0.tar.gz:

Publisher: publish.yml on DeepanshuTIET/pythonlib

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

File details

Details for the file data_energy_ff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: data_energy_ff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for data_energy_ff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba675e3ef50c35c05423f0ee156eed8259280bb73a3ac4a25c70f88f5937623d
MD5 47c88029b174f36ac128af46d147129e
BLAKE2b-256 132553262561f33622b40913a2341d0f4d5c32c5b61ca12a1107796bc063c48f

See more details on using hashes here.

Provenance

The following attestation bundles were made for data_energy_ff-0.1.0-py3-none-any.whl:

Publisher: publish.yml on DeepanshuTIET/pythonlib

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page