2025-05-23 17:06:35 +08:00
# Cycles - Advanced Trading Strategy Backtesting Framework
2025-05-23 12:47:59 +00:00
A sophisticated Python framework for backtesting cryptocurrency trading strategies with multi-timeframe analysis, strategy combination, and advanced signal processing.
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
## Features
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
- **Multi-Strategy Architecture**: Combine multiple trading strategies with configurable weights and rules
- **Multi-Timeframe Analysis**: Strategies can operate on different timeframes (1min, 5min, 15min, 1h, etc.)
- **Advanced Strategies**:
2025-05-23 17:06:35 +08:00
- **Default Strategy**: Meta-trend analysis using multiple Supertrend indicators
- **BBRS Strategy**: Bollinger Bands + RSI with market regime detection
2025-05-23 12:47:59 +00:00
- **Flexible Signal Combination**: Weighted consensus, majority voting, any/all combinations
- **Precise Stop-Loss**: 1-minute precision for accurate risk management
- **Comprehensive Backtesting**: Detailed performance metrics and trade analysis
- **Data Visualization**: Interactive charts and performance plots
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
## Quick Start
2025-05-23 17:06:35 +08:00
### Prerequisites
- Python 3.8+
2025-05-23 12:47:59 +00:00
- [uv ](https://github.com/astral-sh/uv ) package manager (recommended)
2025-05-23 17:06:35 +08:00
### Installation
```bash
# Clone the repository
git clone < repository-url >
cd Cycles
2025-05-23 12:47:59 +00:00
# Install dependencies with uv
2025-05-23 17:06:35 +08:00
uv sync
# Or install with pip
pip install -r requirements.txt
```
### Running Backtests
2025-05-23 12:47:59 +00:00
Use the `uv run` command to execute backtests with different configurations:
2025-05-23 17:06:35 +08:00
```bash
2025-05-23 12:47:59 +00:00
# Run default strategy on 5-minute timeframe
uv run .\main.py .\configs\config_default_5min.json
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
# Run default strategy on 15-minute timeframe
uv run .\main.py .\configs\config_default.json
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
# Run BBRS strategy with market regime detection
uv run .\main.py .\configs\config_bbrs.json
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
# Run combined strategies
uv run .\main.py .\configs\config_combined.json
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
### Configuration Examples
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
#### Default Strategy (5-minute timeframe)
```bash
uv run .\main.py .\configs\config_default_5min.json
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
#### BBRS Strategy with Multi-timeframe Analysis
2025-05-23 17:06:35 +08:00
```bash
2025-05-23 12:47:59 +00:00
uv run .\main.py .\configs\config_bbrs_multi_timeframe.json
```
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
#### Combined Strategies with Weighted Consensus
```bash
uv run .\main.py .\configs\config_combined.json
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
## Configuration
2025-05-23 17:06:35 +08:00
Strategies are configured using JSON files in the `configs/` directory:
```json
{
"start_date": "2024-01-01",
"stop_date": "2024-01-31",
"initial_usd": 10000,
"timeframes": ["15min"],
2025-05-23 12:47:59 +00:00
"stop_loss_pcts": [0.03, 0.05],
2025-05-23 17:06:35 +08:00
"strategies": [
{
"name": "default",
"weight": 1.0,
"params": {
2025-05-23 12:47:59 +00:00
"timeframe": "15min"
2025-05-23 17:06:35 +08:00
}
}
],
"combination_rules": {
2025-05-23 12:47:59 +00:00
"entry": "any",
2025-05-23 17:06:35 +08:00
"exit": "any",
2025-05-23 12:47:59 +00:00
"min_confidence": 0.5
2025-05-23 17:06:35 +08:00
}
}
```
2025-05-23 12:47:59 +00:00
### Available Strategies
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
1. **Default Strategy** : Meta-trend analysis using Supertrend indicators
2. **BBRS Strategy** : Bollinger Bands + RSI with market regime detection
2025-05-23 17:06:35 +08:00
### Combination Rules
2025-05-23 12:47:59 +00:00
- **Entry**: `any` , `all` , `majority` , `weighted_consensus`
- **Exit**: `any` , `all` , `priority` (prioritizes stop-loss signals)
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
## Project Structure
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
Cycles/
├── configs/ # Configuration files
├── cycles/ # Core framework
│ ├── strategies/ # Strategy implementation
│ │ ├── base.py # Base strategy classes
│ │ ├── default_strategy.py
│ │ ├── bbrs_strategy.py
│ │ └── manager.py # Strategy manager
│ ├── Analysis/ # Technical analysis
│ ├── utils/ # Utilities
│ └── charts.py # Visualization
├── docs/ # Documentation
├── data/ # Market data
├── results/ # Backtest results
└── main.py # Main entry point
2025-05-23 20:37:14 +08:00
```
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
## Documentation
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
Detailed documentation is available in the `docs/` directory:
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
- **[Strategy Manager ](./docs/strategy_manager.md )** - Multi-strategy orchestration and signal combination
- **[Strategies ](./docs/strategies.md )** - Individual strategy implementations and usage
- **[Timeframe System ](./docs/timeframe_system.md )** - Advanced timeframe management and multi-timeframe strategies
- **[Analysis ](./docs/analysis.md )** - Technical analysis components
- **[Storage Utils ](./docs/utils_storage.md )** - Data storage and retrieval
- **[System Utils ](./docs/utils_system.md )** - System utilities
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
## Examples
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
### Single Strategy Backtest
```bash
# Test default strategy on different timeframes
uv run .\main.py .\configs\config_default.json # 15min
uv run .\main.py .\configs\config_default_5min.json # 5min
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
### Multi-Strategy Backtest
```bash
# Combine multiple strategies with different weights
uv run .\main.py .\configs\config_combined.json
2025-05-23 17:06:35 +08:00
```
2025-05-23 12:47:59 +00:00
### Custom Configuration
Create your own configuration file and run:
```bash
uv run .\main.py .\configs\your_config.json
```
2025-05-23 20:37:14 +08:00
2025-05-23 12:47:59 +00:00
## Output
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
Backtests generate:
- **CSV Results**: Detailed performance metrics per timeframe/strategy
- **Trade Log**: Individual trade records with entry/exit details
- **Performance Charts**: Visual analysis of strategy performance (in debug mode)
- **Log Files**: Detailed execution logs
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
## License
2025-05-23 17:06:35 +08:00
[Add your license information here]
2025-05-23 12:47:59 +00:00
## Contributing
2025-05-23 17:06:35 +08:00
2025-05-23 12:47:59 +00:00
[Add contributing guidelines here]