Skip to main content

Intro

Takes a DataFrames containing information for multiple future contracts and creates a corresponding continuous contract (ratio back-adjusted, on highest volume).

Installation

Use pip install continuous_futures

Example

from continuous_futures import create_continuous_contract
import pandas as pd

contract1 = pd.DataFrame([
    ['2023-01-01', 15.2, 13.8, 128, '2023F'],
    ['2023-01-02', 15.1, 13.9, 133, '2023F'],
    ['2023-01-03', 14.8, 14.1, 125, '2023F'],
], columns=['Date', 'Open', 'Close', 'Volume', 'Contract'])

contract2 = pd.DataFrame([
    ['2023-01-02', 15.0, 13.2, 129, '2023G'],
    ['2023-01-04', 14.0, 13.1, 130, '2023G'],
    ['2023-01-05', 14.2, 14.0, 140, '2023G'],
], columns=['Date', 'Open', 'Close', 'Volume', 'Contract'])

merged = pd.concat([contract1, contract2])

continuous = create_continuous_contract(merged, 'Date', 'Volume', 'Contract', ['Open', 'Close'], ['Open'])

Parameters

  • data: DataFrame Order must be chronological: first by contract, then by date. Oldest date of oldest contract first. Must contain all columns whose names are passed to this function as parameters.
  • date_column_name: str Name of the column that contains the date
  • volume_column_name: str Name of the column that contains the volume; used to determine rollovers (on highest volume)
  • contract_column_name: str Name of the column that contains the contract name; used determine where contracts change within the DataFrame
  • adjustment_factor_columns_names: list of str Names of the columns to calculate the ratio from; usually only ['close']; if multiple are passed, their mean is used.
  • adjustment_column_names: list of str Names of the columns to adjust by the ratio on rollovers.

Release files for continuous-futures 0.0.2

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

Source distribution (sdist)

Source distribution for continuous-futures 0.0.2
File Size Uploaded
continuous_futures-0.0.2.tar.gz 6.8 kB Details

Release files / continuous_futures-0.0.2.tar.gz

Download URL continuous_futures-0.0.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c4686258dc5ff615dea1e018343a9b5783b9dc63dac35588dc668bb40baeb360
BLAKE2b-256 checksum
How to use checksums
66145938240e8e44efa61219ddba087e3c63de48a14ea5f5fb0ebaae88cd6b25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

2 release 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