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
- External Data Support: Securely incorporate external data sources in your 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
# 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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hypertrial-0.1.2.tar.gz.
File metadata
- Download URL: hypertrial-0.1.2.tar.gz
- Upload date:
- Size: 764.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54b0f6a1fc41c84c6b8819a931466aef9f0edd480393acf7d5ded7b82537f040
|
|
| MD5 |
93335014fcf1ca5c06a3becb6c05e9bf
|
|
| BLAKE2b-256 |
0f25424fea580566ce5403c48a93153b8388a017f4667af986e033e3cde2381f
|
File details
Details for the file hypertrial-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hypertrial-0.1.2-py3-none-any.whl
- Upload date:
- Size: 164.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
865df6f444c0de2bac28ea6e898bd20e7953dcbf0e5e5e3d7d3c425ad35f7e58
|
|
| MD5 |
cfa13ee5508b656b091d433ce1f387ff
|
|
| BLAKE2b-256 |
5134df081580a4597c5db29cae0203e465638a3a8e97e3c391db7b96d78e00c4
|