Converts single future contracts to a continuous contract (ratio back-adjusted)
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file continuous_futures-0.0.2.tar.gz
.
File metadata
- Download URL: continuous_futures-0.0.2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
c4686258dc5ff615dea1e018343a9b5783b9dc63dac35588dc668bb40baeb360
|
|
MD5 |
793a68ffe48edea426a2ddb2b0c8e015
|
|
BLAKE2b-256 |
66145938240e8e44efa61219ddba087e3c63de48a14ea5f5fb0ebaae88cd6b25
|