
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
stacking-sats-pipeline
Advanced tools
A Bitcoin DCA strategy backtesting framework for testing strategies against historical price data.
pip install stacking-sats-pipeline
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)
.
Extract all data sources to local files for offline analysis:
# Extract all data to CSV format
stacking-sats --extract-data csv
# Extract all data to Parquet format (smaller files, better compression)
stacking-sats --extract-data parquet
# Extract to specific directory
stacking-sats --extract-data csv --output-dir data/
stacking-sats --extract-data parquet -o exports/
from stacking_sats_pipeline import extract_all_data
# Extract all data to CSV in current directory
extract_all_data("csv")
# Extract all data to Parquet in specific directory
extract_all_data("parquet", "data/exports/")
What gets extracted:
btc_coinmetrics.csv/parquet
fear_greed.csv/parquet
dxy_fred.csv/parquet
**Requires FRED_API_KEY
environment variable. Get a free key at FRED API
File Format Benefits:
pip install marimo
marimo edit tutorials/examples.py
stacking-sats --strategy path/to/your_strategy.py
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)
strategy1_perf = quick_backtest(strategy1)
strategy2_perf = quick_backtest(strategy2)
results = backtest(
my_strategy,
start_date="2021-01-01",
end_date="2023-12-31",
cycle_years=2
)
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:
For development and testing:
Requirements: Python 3.11 or 3.12
# Clone the repository
git clone https://github.com/hypertrial/stacking_sats_pipeline.git
cd stacking_sats_pipeline
# Set up development environment (installs dependencies + pre-commit hooks)
make setup-dev
# OR manually:
pip install -e ".[dev]"
pre-commit install
# Run tests
make test
# OR: pytest
# Code quality (MANDATORY - CI will fail if not clean)
make lint # Fix linting issues
make format # Format code
make check # Check without fixing (CI-style)
# Run specific test categories
pytest -m "not integration" # Skip integration tests
pytest -m integration # Run only integration tests
ā ļø MANDATORY: All code must pass ruff linting and formatting checks.
Quick commands:
make help # Show all available commands
make lint # Fix ALL issues (autopep8 + ruff + format)
make autopep8 # Fix line length issues specifically
make format # Format code with ruff only
make format-all # Comprehensive formatting (autopep8 + ruff)
make check # Check code quality (what CI runs)
For detailed testing documentation, see TESTS.md.
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.
# 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
# Extract data
stacking-sats --extract-data csv --output-dir data/
stacking-sats --extract-data parquet -o exports/
# Show help
stacking-sats --help
āāā 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
The pipeline provides:
============================================================
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%
FAQs
Hypertrial's Stacking Sats Library - Optimized Bitcoin DCA
We found that stacking-sats-pipeline demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.