Skip to main content

Hypertrial's Stacking Sats Library - Optimized Bitcoin DCA

Project description

Stacking Sats Pipeline

A Bitcoin DCA strategy backtesting framework for testing strategies against historical price data.

Installation

pip install stacking-sats-pipeline

Quick Start

Library Interface

from stacking_sats_pipeline import backtest, strategy

# Simple function approach
def my_strategy(df):
    """Calculate weights based on price data"""
    # Your strategy logic here
    return weights

results = backtest(my_strategy)
results.summary()
results.plot()

# Or use decorator approach
@strategy(name="My Strategy", auto_backtest=True)
def my_strategy(df):
    return weights

Note: Data is now loaded directly into memory from CoinMetrics (no CSV files needed). For legacy file-based loading, use load_data(use_memory=False).

Interactive Tutorial

pip install marimo
marimo edit tutorials/examples.py

Command Line

stacking-sats --strategy path/to/your_strategy.py

Usage Examples

Basic Strategy

def simple_ma_strategy(df):
    """Buy more when price is below 200-day moving average"""
    df = df.copy()
    past_price = df["PriceUSD"].shift(1)
    df["ma200"] = past_price.rolling(window=200, min_periods=1).mean()
    
    base_weight = 1.0 / len(df)
    weights = pd.Series(base_weight, index=df.index)
    
    # Buy 50% more when below MA
    below_ma = df["PriceUSD"] < df["ma200"]
    weights[below_ma] *= 1.5
    
    return weights / weights.sum()

results = backtest(simple_ma_strategy)

Quick Comparison

strategy1_perf = quick_backtest(strategy1)
strategy2_perf = quick_backtest(strategy2)

Custom Parameters

results = backtest(
    my_strategy,
    start_date="2021-01-01",
    end_date="2023-12-31",
    cycle_years=2
)

Strategy Requirements

Your strategy function must:

def your_strategy(df: pd.DataFrame) -> pd.Series:
    """
    Args:
        df: DataFrame with 'PriceUSD' column and datetime index
        
    Returns:
        pd.Series with weights that sum to 1.0 per cycle
    """
    # Your logic here
    return weights

Validation Rules:

  • Weights sum to 1.0 within each cycle
  • All weights positive (≥ 1e-5)
  • No forward-looking data
  • Return pandas Series indexed by date

Development

For development and testing:

# Clone the repository
git clone https://github.com/hypertrial/stacking_sats_pipeline.git
cd stacking_sats_pipeline

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Run specific test categories
pytest -m "not integration"  # Skip integration tests
pytest -m integration        # Run only integration tests

For detailed testing documentation, see TESTS.md.

Contributing Data Sources

The data loading system is designed to be modular and extensible. To add new data sources (exchanges, APIs, etc.), see the Data Loader Contribution Guide which provides step-by-step instructions for implementing new data loaders.

Command Line Options

# Basic usage
stacking-sats --strategy your_strategy.py

# Skip plots
stacking-sats --strategy your_strategy.py --no-plot

# Run simulation
stacking-sats --strategy your_strategy.py --simulate --budget 1000000

# Show help
stacking-sats --help

Project Structure

├── stacking_sats_pipeline/
│   ├── main.py          # Pipeline orchestrator
│   ├── backtest/        # Validation & simulation
│   ├── data/            # Modular data loading system
│   │   ├── coinmetrics_loader.py  # CoinMetrics data source
│   │   ├── data_loader.py         # Multi-source data loader
│   │   └── CONTRIBUTE.md          # Guide for adding data sources
│   ├── plot/            # Visualization
│   ├── strategy/        # Strategy templates
│   └── weights/         # Historical allocation calculator
├── tutorials/examples.py # Interactive notebook
└── tests/               # Comprehensive test suite

Output

The pipeline provides:

  • Validation Report: Strategy compliance
  • Performance Metrics: SPD (Sats Per Dollar) statistics
  • Comparative Analysis: vs Uniform DCA and Static DCA
  • Visualizations: Weight distribution plots

Example Output

============================================================
COMPREHENSIVE STRATEGY VALIDATION
============================================================
✅ ALL VALIDATION CHECKS PASSED

Your Strategy Performance:
Dynamic SPD: mean=4510.21, median=2804.03
Dynamic SPD Percentile: mean=39.35%, median=43.80%

Mean Excess vs Uniform DCA: -0.40%
Mean Excess vs Static DCA: 9.35%

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

stacking_sats_pipeline-0.1.0.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

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

stacking_sats_pipeline-0.1.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file stacking_sats_pipeline-0.1.0.tar.gz.

File metadata

  • Download URL: stacking_sats_pipeline-0.1.0.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for stacking_sats_pipeline-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c17ac71bee64c4acea2f650eecf38a77fbeae39a8d8b6675f4e13bc0afab818d
MD5 2b0a3d52db074675b32d9d697de6f7f1
BLAKE2b-256 652191e597ef683749c5187af5e810560d08fb63aa1d0a8f91415bfad44ff160

See more details on using hashes here.

File details

Details for the file stacking_sats_pipeline-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for stacking_sats_pipeline-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d08c40381d5d7ecd811850355bb582eb44fd8469ec2d3d5ca2ab406fe9d674a
MD5 837d0f2b1228bcef9be7c9d79adb92f1
BLAKE2b-256 7368cd0d26f252ac12c8f24319d8266ed739304c19ba5d8b2355797654f26bee

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