Skip to content

wahidur028/cryptotrade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptocurrency Trading Strategies Backtesting Framework

Table of Contents

Project Overview

A comprehensive backtesting framework for evaluating cryptocurrency trading strategies using academic research methodologies. Implements four distinct strategies with configurable parameters and robust performance metrics.

Python License Backtesting

Project Structure

cryptotrade/
│
├── strategy/                         # Strategy implementations
│   ├── results/                     # Backtest results, metrics, summaries
│   │   ├── SmaCross_10runs_metrics_20250510_0007.csv
│   │   ├── SmaCross_10runs_summary_20250510_0007.csv
│   ├── SmaCrossStrategy.html
│   ├── strategy_buyandhold.py
│   ├── strategy_macd.py
│   ├── strategy_randomwalk.py
│   └── strategy_sma.py
│
├── utils/                            # Utility modules
│   └── technicals.py                 # Contains CryptoDataProcessor class
│
├── cryptotrade/processed_data/      # Saved processed datasets
│   └── CryptoDataProcessor_BTC_USD_2021-01-01_to_2024-01-01.csv
│
├── .gitignore
├── README.md
├── requirements.txt

Features

Core Functionality

  • Multiple backtest iterations for statistical significance
  • Parameter optimization with constraints
  • Transaction cost modeling (commission/slippage)
  • Walk-forward testing capability

Performance Metrics

  • Absolute Metrics:

    • Total Return (%)
    • Max Drawdown (%)
    • Win Rate (%)
    • Number of Trades
  • Risk-Adjusted Metrics:

    • Sharpe Ratio
    • Sortino Ratio
    • Calmar Ratio
    • Risk-Return Ratio

Data Handling

  • Automated OHLCV data fetching via OpenBB
  • Local caching of historical data
  • Flexible timeframes (daily/hourly)

Installation

Prerequisites

  • Python 3.8+
  • pip package manager

Setup

# Clone repository
git clone https://github.com/wahidur028/cryptotrade.git
cd cryptotrade

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate     # Windows

# Install dependencies
pip install -r requirements.txt

# Set up OpenBB credentials (if needed)
obb account login

Usage

Basic Execution

# Run SMA strategy with default parameters
python strategy_sma.py

# Run MACD strategy with optimization
python strategy_macd.py

Configuration Options

Each strategy file contains these configurable parameters:

# Backtest Parameters
NUM_ITERATIONS = 10       # Number of independent runs
OPTIMIZE = False          # Enable parameter optimization
CASH = 20000              # Initial capital (USD)
COMMISSION = 0.001        # 0.1% per trade

# Data Parameters
SYMBOL = 'BTC-USD'        # Trading pair
START_DATE = '2021-01-01' # Backtest start
END_DATE = '2024-01-01'   # Backtest end
INTERVAL = '1d'           # Timeframe ('1d', '4h', '1h')

Results Analysis

Output Files

results/
├── [Strategy]_[Iterations]runs_metrics_[timestamp].csv
├── [Strategy]_[Iterations]runs_summary_[timestamp].csv
├── [Strategy]_optimized_[params]_[timestamp].csv

Metrics Captured

Metric Description

Return [%]	Total percentage return
Sharpe Ratio	Risk-adjusted return
Max. Drawdown [%]	Largest peak-to-trough decline
Win Rate [%]	Percentage of winning trades
# Trades	Total number of trades executed
Exposure Time [%]	Percentage of time in market

Contact

Author: Wahidur Rahman
Email: sm.wahidur@gm.gist.ac.kr
GitHub: @wahidur028
Project Link: https://github.com/wahidur028/cryptotrade

About

Cryptocurrency trading strategy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors