Skip to main content

Bitcoin Dollar-Cost Averaging (DCA) Backtest Framework

Project description

Hypertrial: Bitcoin DCA Strategy Framework

A Bitcoin Dollar-Cost Averaging (DCA) framework for evaluating and comparing algorithmic trading strategies across multiple market cycles.

Installation

pip install hypertrial

Quick Start

import pandas as pd
from hypertrial import backtest_dynamic_dca, load_data, register_strategy

# Load Bitcoin data (included with the package)
btc_df = load_data()

# Create a simple custom strategy
@register_strategy("my_custom_strategy")
def custom_dca_strategy(df):
    """A simple custom strategy that allocates more weight when price is below the 50-day MA."""
    # Add features
    df = df.copy()
    df['ma_50'] = df['btc_close'].rolling(window=50).mean()
    df['below_ma'] = (df['btc_close'] < df['ma_50']).astype(int)

    # Create weights
    weights = pd.Series(index=df.index, data=0.0)
    weights[df['below_ma'] == 1] = 2.0  # Double weight when below MA
    weights[df['below_ma'] == 0] = 0.5  # Half weight when above MA

    # Normalize weights (required)
    total_weight = weights.sum()
    if total_weight > 0:
        weights = weights / total_weight

    return weights

# Run backtest with your strategy
results = backtest_dynamic_dca(btc_df, strategy_name="my_custom_strategy")

Key Features

  • Strategy Development: Create and test custom DCA strategies with a flexible API
  • Performance Metrics: Analyze strategies using Sats Per Dollar (SPD) across market cycles
  • Cross-Cycle Analysis: Test strategies under different market conditions
  • Visualization Tools: Built-in plotting for strategy weights and performance metrics
  • Security Verification: Comprehensive security system for submitted strategies
  • Tournament Platform: Submit and compare your strategies against others

Command Line Interface

Hypertrial comes with a built-in CLI:

# List available strategies
hypertrial --list

# Run backtest with a specific strategy
hypertrial --strategy dynamic_dca

# Run backtest for all strategies
hypertrial --backtest-all --output-dir results

# Backtest multiple strategy files from custom paths
hypertrial --strategy-files path/to/strategy1.py path/to/strategy2.py --output-dir results

# Backtest all Python files in a directory
hypertrial --strategy-dir path/to/strategies/dir --output-dir results

# Backtest files matching a glob pattern
hypertrial --glob-pattern "strategies/batch_*.py" --output-dir results

# Process many strategies in parallel
hypertrial --strategy-dir strategies/ --processes 4 --output-dir results

# Process large sets of strategies in batches to manage memory
hypertrial --glob-pattern "*.py" --batch-size 10 --output-dir results

# Disable plots during backtest
hypertrial --strategy my_strategy --no-plots

What is DCA?

Dollar-Cost Averaging (DCA) is an investment strategy where you invest a fixed amount at regular intervals, regardless of price. With Bitcoin, DCA helps mitigate volatility while accumulating BTC over time.

Hypertrial extends this concept by allowing for "dynamic" DCA - varying the purchase amounts strategically while maintaining the same total investment.

Resources

License

This project is available under the MIT License.

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

hypertrial-0.1.7.tar.gz (800.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypertrial-0.1.7-py3-none-any.whl (210.7 kB view details)

Uploaded Python 3

File details

Details for the file hypertrial-0.1.7.tar.gz.

File metadata

  • Download URL: hypertrial-0.1.7.tar.gz
  • Upload date:
  • Size: 800.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for hypertrial-0.1.7.tar.gz
Algorithm Hash digest
SHA256 f532ad5188c18dc482618568d97be4a1de50e2f0eb6dce4d30a1863fa09a5937
MD5 70f8a43a745e8d31445b94241af375b5
BLAKE2b-256 837917ceb9d0decfc86613f47b19c28a901a1a1071702ab55456969df2973fe5

See more details on using hashes here.

File details

Details for the file hypertrial-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: hypertrial-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 210.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for hypertrial-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c9941642bf11822011c0cca19c228283fb1cc4eb5bec31b86c3b3e61b449d2ff
MD5 fefeddf576173a32b3539469cef67f56
BLAKE2b-256 e7259f6b365c415207509764eaf43602b345449e6e3e950d36df0b5d00c8a766

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page