Skip to main content

Advanced Bitcoin DCA analysis with machine learning predictions and strategy optimization

Project description

Bitcoin DCA Analysis Terminal

๐Ÿš€ Advanced Bitcoin DCA Analysis and Price Prediction Tool

A comprehensive terminal application for Bitcoin analysis featuring:

  • ๐Ÿ”ฎ Advanced price prediction using deep learning and Bitcoin-specific patterns
  • ๐Ÿ“ˆ DCA optimization based on historical performance analysis
  • ๐Ÿงช Comprehensive backtesting of DCA strategies
  • ๐Ÿ“Š Beautiful terminal interface with Rich library

Features

๐Ÿ”ฎ Price Prediction

  • Advanced 3-Model Ensemble: LSTM, Random Forest, and XGBoost ensemble predictions
  • Bitcoin-Specific Features: Halving cycles, market maturity, supply analysis
  • Technical Analysis: 20+ technical indicators (RSI, MACD, Bollinger Bands, etc.)
  • Pattern Recognition: Time-based patterns and market cycle analysis
  • Performance-Based Weighting: Best-performing models get higher influence in final prediction

๐Ÿ“ˆ DCA Recommendations

  • Optimal Day Analysis: Find the best day of month for DCA investments
  • Weekly Patterns: Analyze day-of-week performance
  • Combined Strategies: Optimal combinations of timing factors
  • Success Rate Analysis: Historical win rates for different strategies
  • ๐Ÿ“… Custom Date Ranges: Analyze specific time periods (bull/bear markets, recent years)
  • โš ๏ธ Data Validation: Ensures sufficient data for reliable analysis (minimum 90 days)

๐Ÿงช DCA Backtesting

  • Monthly DCA Strategies: Fixed day of month or optimal weekday combinations
  • Performance Metrics: Returns, Sharpe ratio, volatility, max drawdown
  • Transaction Analysis: Detailed trade-by-trade breakdown
  • ๐Ÿ“… Custom Date Ranges: Backtest specific time periods
  • ๐ŸŽฏ Strategy Options:
    • day_of_month: Invest on specific day each month (e.g., 15th)
    • optimal: Invest on chosen weekday closest to chosen day of month

๐Ÿ“Š Market Overview

  • Real-time Metrics: Current price, trends, volatility
  • Historical Context: All-time highs/lows, long-term performance
  • Market Cycles: Halving cycle analysis and positioning

Installation

๐Ÿš€ PyPI Installation (Recommended)

Install from PyPI with a single command:

pip install bitcoin-dca

Then run:

btc-dca

Requirements: Python 3.8+, pip

Supported platforms: macOS, Linux, Windows

๐Ÿ“ฆ Development Installation

For development or to get the latest features:

  1. Clone the repository:

    git clone https://github.com/obokaman-com/bitcoin-dca.git
    cd bitcoin-dca
    
  2. Install in development mode:

    pip install -e .
    

๐Ÿ—‘๏ธ Uninstalling

To remove the application:

pip uninstall bitcoin-dca

๐Ÿ”„ Upgrading

To upgrade to the latest version:

pip install --upgrade bitcoin-dca

Testing

Run the comprehensive test suite to ensure everything works correctly:

python tests/test_btc_analyzer.py

The test suite includes:

  • โœ… Valid data processing - Normal Bitcoin price data handling
  • โŒ Invalid data handling - Corrupted files, missing columns, negative prices
  • ๐Ÿงช Edge cases - Empty datasets, extreme values, wrong data types
  • ๐Ÿ”„ Error recovery - Fallback mechanisms and graceful degradation
  • ๐Ÿ“Š All components - Data loading, prediction, DCA analysis, backtesting

Test Results: 30 tests covering all major functionality, new UI features, and error conditions.

Usage

Quick Start

After PyPI installation:

btc-dca

For development:

# Run as module
python -m bitcoin_dca.main

# Or if installed as package
btc-dca

Startup time: ~1-2 seconds with optimized on-demand feature loading

Note: On first run, if no Bitcoin data file is found, the application will automatically download the latest data from stooq.com.

โšก Performance Features

The application is optimized for fast startup and efficient resource usage:

Key optimizations:

  • ๐Ÿš€ Lazy loading - Heavy libraries load only when needed
  • ๐Ÿ’พ Smart caching - Features cached to disk for instant reuse
  • ๐ŸŽฏ On-demand computation - Only compute features for selected analysis
  • โšก Minimal startup - Load basic data first, enhance progressively
  • ๐Ÿ“‰ Memory efficient - Optimized memory usage (15-25 MB at startup)

Performance analysis tools:

python scripts/startup_info.py           # View detailed startup analysis

With Custom Data File

btc-dca --csv your_bitcoin_data.csv

Automatic Data Download

  • ๐ŸŒ Auto-download: Downloads latest Bitcoin price data if CSV doesn't exist
  • ๐Ÿ“Š Data validation: Verifies downloaded data integrity
  • ๐Ÿ”„ Retry mechanism: Re-downloads if data loading fails
  • ๐Ÿ’พ Local caching: Saves data locally for future use

Data Format

The application expects a CSV file with the following structure:

Date,Open,High,Low,Close
2010-07-19,0.08584,0.09307,0.07723,0.0808
2010-07-20,0.0808,0.08181,0.07426,0.07474
...

Application Flow

Main Menu Options

  1. ๐Ÿ”ฎ Price Prediction

    • Enter target date (YYYY-MM-DD)
    • Get AI-powered price prediction with confidence score
    • Includes market analysis and technical context
  2. ๐Ÿ“ˆ DCA Recommendations

    • Analyze optimal investment timing
    • View best days of month and week
    • Get personalized strategy recommendations
  3. ๐Ÿงช DCA Backtesting

    • Test different DCA strategies
    • Choose from predefined or custom strategies
    • Get detailed performance analysis
  4. ๐Ÿ“Š Market Overview

    • Current market snapshot
    • Historical performance metrics
    • Volatility and trend analysis
  5. ๐Ÿ“ฅ Update Dataset

    • Download fresh Bitcoin price data from stooq.com
    • Automatically clears cache and reloads data
    • Shows before/after data range comparison
    • Keep analysis current with latest market movements
  6. ๐Ÿงน Clear Cache

    • Remove all cached features and computed data
    • Free up disk space (.cache directory)
    • Force recomputation of all features
    • Useful after manual data updates or troubleshooting

Advanced Features

Prediction Models

  • 3-Model Ensemble: Combines LSTM, Random Forest, and XGBoost predictions
  • Performance-Based Weighting: Models weighted by validation accuracy (lower MAE = higher weight)
  • Feature Engineering: 40+ engineered features including:
    • Technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands)
    • Bitcoin halving cycle analysis
    • Market maturity metrics
    • Seasonal and cyclical patterns

DCA Analysis

  • Historical Optimization: Analyzes 10+ years of data
  • Multiple Time Frames: 30, 90, 180, and 365-day return analysis
  • Statistical Significance: Success rates and confidence intervals

Backtesting Engine

  • Realistic Simulation: Includes transaction fees and market gaps
  • Comprehensive Metrics:
    • Total and annualized returns
    • Sharpe ratio and volatility
    • Maximum drawdown
    • Win rate analysis

Technical Implementation

Architecture

bitcoin_dca/
โ”œโ”€โ”€ main.py          # Main application and UI
โ”œโ”€โ”€ data_loader.py   # Data preprocessing and feature engineering
โ”œโ”€โ”€ predictor.py     # ML models for price prediction
โ”œโ”€โ”€ dca_analyzer.py  # DCA optimization algorithms
โ””โ”€โ”€ backtester.py    # Strategy backtesting engine

Key Technologies

  • pandas/numpy: Data manipulation and analysis
  • scikit-learn: Random Forest machine learning
  • XGBoost: Gradient boosting algorithms
  • TensorFlow: Deep learning (LSTM) models
  • Rich: Beautiful terminal interface
  • TA-Lib: Technical analysis indicators

Data Processing Pipeline

  1. Raw Data Loading: CSV parsing and validation
  2. Feature Engineering: Technical indicators and Bitcoin-specific features
  3. Model Training: Real-time model training on historical data
  4. Analysis Execution: Strategy analysis and backtesting
  5. Results Visualization: Rich terminal output with charts and tables

Performance Considerations

  • Efficient Processing: Vectorized operations for large datasets
  • Memory Management: Optimized for datasets with 10+ years of daily data
  • Model Caching: Smart caching to avoid retraining
  • Parallel Processing: Multi-threaded backtesting for strategy comparison

Example Output

Price Prediction

๐Ÿ”ฎ Price Prediction for 2025-01-15
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Predicted Price โ”‚ $67,234.50   โ”‚
โ”‚ Confidence      โ”‚ 78.5%        โ”‚
โ”‚ Model           โ”‚ Ensemble     โ”‚
โ”‚ Features Used   โ”‚ 42           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

DCA Recommendations

๐Ÿ“… Best Days of Month for DCA
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Rank โ”‚ Day โ”‚ Avg Return โ”‚ Success Rateโ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1    โ”‚ 21  โ”‚ 8.24%      โ”‚ 73.2%       โ”‚
โ”‚ 2    โ”‚ 15  โ”‚ 7.89%      โ”‚ 71.8%       โ”‚
โ”‚ 3    โ”‚ 28  โ”‚ 7.45%      โ”‚ 69.4%       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Disclaimer

This tool is for educational and research purposes only. Cryptocurrency investments are highly volatile and risky. Past performance does not guarantee future results. Always do your own research and consider consulting with financial advisors before making investment decisions.

Troubleshooting

Installation Issues

Python version errors:

# Check your Python version (requires 3.8+)
python3 --version

# Update Python (macOS)
brew install python3

# Update Python (Ubuntu/Debian)
sudo apt install python3.8 python3.8-pip

Installation failures:

# Try with pip3 explicitly
pip3 install bitcoin-dca

# Or with user install
pip install --user bitcoin-dca

# Force reinstall if corrupted
pip install --force-reinstall bitcoin-dca

TensorFlow installation issues on Apple Silicon:

# If TensorFlow fails, install manually first
pip install tensorflow-macos
pip install bitcoin-dca

Missing system dependencies (for compilation):

# macOS
xcode-select --install

# Ubuntu/Debian
sudo apt install build-essential python3-dev

# CentOS/RHEL
sudo yum groupinstall "Development Tools"

Runtime Issues

Command not found after installation:

# Check if pip installed correctly
pip show bitcoin-dca

# Try running directly
python -m bitcoin_dca.main

# Reinstall if needed
pip install --force-reinstall bitcoin-dca

Dependency conflicts:

# Update all dependencies
pip install --upgrade bitcoin-dca

# Clean reinstall
pip uninstall bitcoin-dca
pip install bitcoin-dca

Contributing

Feel free to submit issues, feature requests, or pull requests to improve the application.

License

This project is open source and 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

bitcoin_dca-1.3.0.tar.gz (43.4 kB view details)

Uploaded Source

Built Distribution

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

bitcoin_dca-1.3.0-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file bitcoin_dca-1.3.0.tar.gz.

File metadata

  • Download URL: bitcoin_dca-1.3.0.tar.gz
  • Upload date:
  • Size: 43.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bitcoin_dca-1.3.0.tar.gz
Algorithm Hash digest
SHA256 809cf1efb44c250d032852f013f8d5e78cce115d0b7a9fd8de05f0e095997fdc
MD5 44a9d9a351e3930ab12eb01fe997a577
BLAKE2b-256 76991bd0cc80228cb6d8a1bbd1a00bf24b901c6aa087624db0d72fde53ba7843

See more details on using hashes here.

File details

Details for the file bitcoin_dca-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: bitcoin_dca-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bitcoin_dca-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5b64bfdfa8fdb53610ffcca918df5c40ec80d30ed99a3d6e7b5978fede6b0f6
MD5 742fd1161bdcc03f9d2774969b2b1bed
BLAKE2b-256 a0e746eb4cf5b5b31aad20b3bff4554c60843e18315ed0e3b0470d4499dea685

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