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
- GitHub Repository: github.com/mattfaltyn/hypertrial
- PyPI Package: pypi.org/project/hypertrial
- Documentation: Available in the repository's tutorials directory
- Issue Tracker: Submit issues on GitHub
License
This project is available under the MIT License.
Metadata
Release files for hypertrial 0.1.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hypertrial-0.1.14.tar.gz | 831.2 kB | Without provenance | Details for hypertrial-0.1.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hypertrial-0.1.14-py3-none-any.whl | Python 3 | none | any | Details for hypertrial-0.1.14-py3-none-any.whl |
Total release size: 1.1 MB
Release files / hypertrial-0.1.14.tar.gz
| Download URL | hypertrial-0.1.14.tar.gz |
|---|---|
| Size | 831.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80aca43d2b0f4d3c92c1a17e0932a2b205f6b117074f99a64b57f7a6e644943a
|
|
BLAKE2b-256 checksum How to use checksums |
a7aa2fe5b6881067b452ac503ecb04f5a688f72a83ecfbdb01e33e53cc8e91a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / hypertrial-0.1.14-py3-none-any.whl
| Download URL | hypertrial-0.1.14-py3-none-any.whl |
|---|---|
| Size | 246.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af0836fe606dce27c475ce59281ee7307f6f17eadff938d2438edd9379f12a86
|
|
BLAKE2b-256 checksum How to use checksums |
aeecbd06f3bebf1b3f72cb3a7e9400c8f5544947e07146a4d9adc37adcff9755
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for hypertrial 0.1.14
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.