The Trading Bot System is a sophisticated algorithmic trading platform written in C++. It provides a comprehensive suite of tools for backtesting and optimizing trading strategies using various technical indicators and optimization algorithms.
-
Strategy Module
- Base strategy interface (
IStrategy) - Implemented strategies:
- Mean Reversion
- Momentum
- Bollinger Bands
- RSI (Relative Strength Index)
- Each strategy implements signal generation and state management
- Base strategy interface (
-
Optimization Module
- Parameter optimization framework
- Implemented algorithms:
- Genetic Algorithm
- Hill Climbing
- Parallel evaluation support via OpenMP
- Configurable fitness functions
-
Backtesting Engine
- Historical data processing
- Performance metrics calculation
- Trade execution simulation
-
Data Management
- Market data handling
- CSV data import/export
- JSON configuration and results storage
- Uses z-score for identifying overbought/oversold conditions
- Parameters:
z_score_threshold: Signal thresholdwindow_size: Lookback periodtake_profit: Profit targetstop_loss: Loss limit
- Tracks price momentum over a lookback period
- Parameters:
lookback_period: Momentum calculation windowthreshold: Signal thresholdtake_profit: Profit targetstop_loss: Loss limit
- Uses standard deviation bands for volatility-based signals
- Parameters:
window_size: Moving average periodnum_std_dev: Standard deviation multipliertake_profit: Profit targetstop_loss: Loss limit
- Implements Relative Strength Index indicator
- Parameters:
period: RSI calculation periodoverbought: Upper thresholdoversold: Lower thresholdtake_profit: Profit targetstop_loss: Loss limit
- Population-based optimization
- Features:
- Tournament selection
- Crossover and mutation
- Elitism
- Parallel evaluation
- Parameters:
population_size: Number of individualsgenerations: Number of iterationsmutation_rate: Probability of mutationcrossover_rate: Probability of crossover
- Local search optimization
- Features:
- Random restart
- Adaptive step size
- Parallel neighbor evaluation
- Parameters:
max_iterations: Number of iterationsstep_size: Initial step sizestep_decay: Step size reduction rate
The system calculates various performance metrics:
- Total Profit
- Sharpe Ratio
- Maximum Drawdown
- Win Rate
- Sortino Ratio
- Maximum Trade Duration
The optimization process uses a weighted fitness function:
fitness = profit_weight * total_profit +
sharpe_weight * sharpe_ratio -
drawdown_weight * max_drawdown +
win_rate_weight * win_rate +
sortino_weight * sortino_ratio -
max_trade_duration_weight * max_trade_duration# Create build directory
mkdir build && cd build
# Configure with optimization enabled
cmake -DENABLE_OPTIMIZATION=ON ..
# Build
make# Basic usage
./tradingbot_optimize data.csv
# With specific strategy and algorithm
./tradingbot_optimize --strategy=rsi --algorithm=hill_climbing data.csv
# With custom weights
./tradingbot_optimize --weights=profit:0.6,sharpe:0.3,drawdown:0.1 data.csv
# With parallel processing
./tradingbot_optimize --threads=4 data.csv--strategy=<name>: Select strategy (default: mean_reversion)--algorithm=<name>: Select optimization algorithm (genetic or hill_climbing)--weights=<config>: Configure fitness weights--threads=<n>: Number of threads for parallel processing--generations=<n>: Number of generations/iterations--population=<n>: Population size
- Create strategy header file:
#pragma once
#include "IStrategy.hpp"
class NewStrategy : public IStrategy {
public:
struct Config {
// Strategy parameters
};
// Implement required methods
virtual Signal generateSignal(const MarketData& data) override;
virtual void updateState(const MarketData& data) override;
virtual void reset() override;
};- Implement strategy:
#include "NewStrategy.hpp"
// Implement methods- Add to strategy factory in
main_optimize.cpp
- Create optimizer header:
#pragma once
#include "ParameterOptimizer.hpp"
class NewOptimizer {
public:
// Constructor and methods
Individual optimize();
};- Implement optimizer
- Add to main optimization logic
- C++17 or later
- OpenMP
- nlohmann/json
- CMake 3.10 or later
This project is licensed under the MIT License - see the LICENSE file for details.
- Mayckon Giovani
- Email: doomhammerhell@gmail.com
- GitHub: @doomhammerhell
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request