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
Built Distribution
Close
Hashes for continuous_futures-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6667a90386c067625fe2ef72658d13ae83bade7a440db731b9d6986a36f3369f |
|
MD5 | 2512c5852bb0085f318c67dac45de1a7 |
|
BLAKE2b-256 | ae3e6109e7ab90ea2bc23b0fbf4b8eefc87d30da2449d83abe9a6acf2952eb34 |