Skip to main content

chart-data-dl

📈 Market Chart Data for ML/DL

A toolkit to handle and preprocess financial market chart data for technical analysis, with a focus on preparing input for deep learning and machine learning tasks.

A key feature of this project is its ability to present higher timeframe data (OHLCV values, indicators, etc.) alongside target timeframe data as live data, preventing future information leakage. This supports models and analysts in performing multi-timeframe analysis, enhancing the realism and context-awareness of market predictions and insights.

Output Structure

Here is an example that shows the output as a combination of different timeframes (with optional indicators). The chart demonstrates how different timeframes (e.g., 15m, 30m, 1h) can be displayed together, and how indicators can be overlaid for enriched analysis.

Sequence Length of Data

Note: Each dataset within each timeframe maintains the same sequence length, which can be modified through function arguments.

🔑 Key Features

📊 Multi-timeframe datasets
Generate synchronized multi-timeframe datasets without future data leakage, compatible with deep learning data loaders (e.g., PyTorch, TensorFlow).

🗃️ CSV tools for I/O and timeframe conversion
Easily import/export datasets in CSV format and convert between timeframes for flexible data handling.

⚙️ Indicator integration
Add technical indicators to datasets, with support for custom indicator development for research and experimentation.

🚀 Installation

📦 Option 1: Install via pip

pip install chart-data-dl

🛠 Option 2: Clone and install manually

git clone https://github.com/mehranESB/ohlcv-chart-tools.git
cd ohlcv-chart-tools
python setup.py install

📚 Usage Guide

1️⃣ Create a Multi-Timeframe Dataset

This example demonstrates how to create a multi-timeframe dataset, with added indicators like Simple Moving Average (SMA) and Exponential Moving Average (EMA):

import chartDL.indicator as indc
import chartDL.preprocess as pp
import chartDL.utils.csv as csv_utils

# Load the target timeframe data (15-minute)
target_file_path = Path("./DATA/csv/EURUSD-15m.csv")
source_df = csv_utils.import_ohlcv_from_csv(
    target_file_path, header=True, datetime_format="%Y-%m-%d %H:%M:%S"
)

# Define higher timeframes to generate multi-timeframe data (e.g., 30m, 1h)
higher_timeframes = ["30m", "1h"]

# Define the indicators to add to the dataset (e.g., SMA, EMA)
indicators = [indc.SMA(20), indc.EMA(10)]

# Generate the multi-timeframe views, including indicators+
save_path = Path("./DATA/multi_view/EURUSD-15m") # folder where the multi-timeframe data will be saved
mvt_dfs, time_frames = pp.multi_timeframe_view(
    source_df, higher_timeframes, indicators=indicators, save_to=save_path
)

2️⃣ Use with PyTorch DataLoader

This guide demonstrates how to wrap the MultiDataset with PyTorch’s DataLoader for model training.

from torch.utils.data import Dataset, DataLoader
from chartDL.dataset import MultiDataset

class CustomDataset(Dataset):
    def __init__(self, dataset: MultiDataset):
        self.dataset = dataset  # store to use it as data source

    def __len__(self):
        return len(self.dataset)

    def __getitem__(self, index):
        multi_time_frame_data = self.dataset[index]

        retrive_data = {}
        for df in multi_time_frame_data:
            name = f"x_{df.attrs['timeframe']}"
            value = df[["High", "Low"]].to_numpy()
            retrive_data[name] = value

        return retrive_data


# Initialize MultiDataset (use your own path and sequence length)
multi_dataset = MultiDataset("./DATA/multi_view/EURUSD-1h", seq_len=128)

# Create a DataLoader for batching and shuffling
data_loader = DataLoader(CustomDataset(multi_dataset), batch_size=64, shuffle=True)

# Iterate through batches during model training
for batch in data_loader:
    ...

🧪 Explore More Utilities

Check out the examples/ folder for code samples on:

  • Timeframe conversion
  • Custom indicator creation
  • CSV import/export tools
  • Data visualization

🤝 Contributing

Contributions are welcome and appreciated!

Feel free to fork the repository, submit pull requests, or open issues for bugs, feature suggestions, or improvements.

📄 License

This project is licensed under the MIT License. See the LICENSE.txt file for details.

Metadata

Release files for chart-data-dl 0.1.1

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

Source distribution (sdist)

Source distribution for chart-data-dl 0.1.1
File Size Uploaded Provenance Actions
chart_data_dl-0.1.1.tar.gz 28.8 kB Without provenance Details for chart_data_dl-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chart-data-dl 0.1.1
File Interpreter ABI Platform Actions
chart_data_dl-0.1.1-py3-none-any.whl Python 3 none any Details for chart_data_dl-0.1.1-py3-none-any.whl

Total release size: 58.4 kB

Release files / chart_data_dl-0.1.1.tar.gz

Download URL chart_data_dl-0.1.1.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4f088c136c8b0d927f95e3069454cd50c229a2ade0b32f8be58f275f84630208
BLAKE2b-256 checksum
How to use checksums
8542dcf10049cc21a3b3d7fcb8a677e17138c6f857ef3494ca4a9a8e8280af27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.6

Release files / chart_data_dl-0.1.1-py3-none-any.whl

Download URL chart_data_dl-0.1.1-py3-none-any.whl
Size 29.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3e935039f3a7c49a0e72df7c5856c2071b86fad814baabd93cd33977a777131
BLAKE2b-256 checksum
How to use checksums
fb66dd0297897f0f10b1f73a66fe048285073890d44489d85bd4eea38d6c378e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.6

Security for chart-data-dl 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1.1 This release

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