Skip to main content

A flexible toolkit for working with OHLC data and generating custom timeframes from minute data.

Project description

OHLC Toolkit

PyPI Python Codacy Badge Codacy Badge License

A flexible Python toolkit for working with OHLC (Open, High, Low, Close) market data.

Installation

The project is available on PyPI:

pip install ohlc-toolkit

Features

  • Read OHLC data from CSV files into pandas DataFrames, with built-in data quality checks:

      df = read_ohlc_csv(csv_file_path, timeframe="1d")
    
  • Download BTCUSD 1-minute candle data in one line (using data from ff137/bitstamp-btcusd-minute-data):

      df_1min = DatasetDownloader().download_bitstamp_btcusd_minute_data(bulk=True)
    
  • Transform your candle data into any desired timeframe and resolution:

      # Convert 1-minute data into 5-minute data, maintaining a 1-minute resolution
      df_5m = transform_ohlc(df_1min, timeframe=5, step_size_minutes=1)
    
      # Convert 1-minute data into 1-day data, with a 1-day resolution
      df_1d = transform_ohlc(df_1min, timeframe="1d", step_size_minutes=1440)  
    
      # Support for arbitrary timeframes is available!
      df_arb = transform_ohlc(df_1min, timeframe="1d3h7m")
    
  • Convert timeframe strings to the number of minutes, and vice versa:

      # From string to minutes
      parse_timeframe("1h15m") == 75
    
      # From minutes to string
      format_timeframe(minutes=75) == "1h15m"
    
  • Calculate future price changes:

      # For every minute, compute the 1-hour percentage price change
      df_future_returns = calculate_percentage_return(
          df_1min["close"],  # Use the close price column
          timestep_size=1,  # Compute returns at 1-minute resolution (same as input)
          future_return_length=60,  # Compute price changes over 60 minutes
      )
    

🚧 Coming soon™️:

  • Calculate technical indicators

All of the above features will enable you to generate extensive training data for machine learning models, whether for research or trading, to predict future price changes based on technical indicators.

Examples

See the examples directory for examples of how to use the toolkit.

Run the example script to see how the toolkit works:

# Clone the repository
git clone https://github.com/ff137/ohlc-toolkit.git
cd ohlc-toolkit

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install poetry
poetry install

# Run the example script
python examples/basic_usage.py

Support

If you need any help or have any questions, please feel free to open an issue or contact me directly.

We hope this repo makes your life easier! If it does, please give us a star! ⭐

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

ohlc_toolkit-0.4.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

ohlc_toolkit-0.4.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file ohlc_toolkit-0.4.0.tar.gz.

File metadata

  • Download URL: ohlc_toolkit-0.4.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ohlc_toolkit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 691ecebd7dfa440a2a6f3803df94581f22a7a881108126ec16a2cc286fc3768c
MD5 cf9a8452309822578daa6971f5d51c9f
BLAKE2b-256 b6e28033e12366f359d35e70c86d63711372baf251dc65a778528099b0caa07d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohlc_toolkit-0.4.0.tar.gz:

Publisher: publish-on-release.yml on ff137/ohlc-toolkit

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

File details

Details for the file ohlc_toolkit-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: ohlc_toolkit-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ohlc_toolkit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4337ad806be842e8e5a74b67a91a05fc136ebebd1f9939115ef8318022fcb758
MD5 29f57d735393f95a1cfc3935b98caee5
BLAKE2b-256 2035856aa54b9cb0d438fa2a7e3de13d57708510a0273b4c187e4fab03290f6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohlc_toolkit-0.4.0-py3-none-any.whl:

Publisher: publish-on-release.yml on ff137/ohlc-toolkit

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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page