TradeBench 1.0.0
Algorithmic Trading Backtesting Platform
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions
BacktestingEngine Class Reference

Engine responsible for executing trading strategies. More...

#include <tradebench_core.h>

Public Member Functions

std::string optimizeParameters (const MarketData &market_data)
 Finds the best strategy and parameters using an evolutionary Genetic Algorithm.
 
BacktestResult runSimulation (const MarketData &market_data, const std::string &strategy_payload)
 Routes the simulation request to the appropriate mathematical strategy.
 

Private Member Functions

std::vector< std::string > parsePayload (const std::string &payload)
 Parses the strategy payload string into separate tokens.
 
BacktestResult runMovingAverageCross (const MarketData &market_data, int fast_window, int slow_window, bool use_ema)
 Executes the Moving Average Crossover strategy (SMA or EMA).
 
BacktestResult runRSI (const MarketData &market_data, int period, double overbought, double oversold)
 Executes the Relative Strength Index (RSI) strategy.
 
BacktestResult runMACD (const MarketData &market_data, int fast_period, int slow_period, int signal_period)
 Executes the MACD strategy.
 
BacktestResult runBollingerBands (const MarketData &market_data, int period, double std_dev_multiplier)
 Executes the Bollinger Bands strategy.
 
void calculateEMA (const std::vector< double > &source, int period, int start_idx, std::vector< double > &ema_out)
 Calculates the Exponential Moving Average (EMA).
 
void calculateRSI (const std::vector< double > &prices, int period, std::vector< double > &rsi_out)
 Calculates the Relative Strength Index (RSI).
 
void finalizeMetrics (BacktestResult &res, double last_price, double initial, double current, double amount, bool in_pos, int wins)
 Calculates final profit and win rate metrics for the backtest.
 

Detailed Description

Engine responsible for executing trading strategies.

Member Function Documentation

◆ calculateEMA()

void BacktestingEngine::calculateEMA ( const std::vector< double > & source,
int period,
int start_idx,
std::vector< double > & ema_out )
private

Calculates the Exponential Moving Average (EMA).

Parameters
sourceInput data vector.
periodThe EMA window period.
start_idxThe index to start calculating from.
ema_outThe output vector to store EMA values.

◆ calculateRSI()

void BacktestingEngine::calculateRSI ( const std::vector< double > & prices,
int period,
std::vector< double > & rsi_out )
private

Calculates the Relative Strength Index (RSI).

Parameters
pricesInput price vector.
periodThe RSI calculation period.
rsi_outThe output vector to store RSI values.

◆ finalizeMetrics()

void BacktestingEngine::finalizeMetrics ( BacktestResult & res,
double last_price,
double initial,
double current,
double amount,
bool in_pos,
int wins )
private

Calculates final profit and win rate metrics for the backtest.

Parameters
resThe result structure to update.
last_priceThe final price of the asset.
initialInitial capital.
currentCurrent fiat capital.
amountCurrent crypto holdings.
in_posWhether a position is currently open.
winsTotal number of winning trades.

◆ optimizeParameters()

std::string BacktestingEngine::optimizeParameters ( const MarketData & market_data)

Finds the best strategy and parameters using an evolutionary Genetic Algorithm.

Parameters
market_dataThe dataset to backtest against.
Returns
The optimal strategy payload string.

◆ parsePayload()

std::vector< std::string > BacktestingEngine::parsePayload ( const std::string & payload)
private

Parses the strategy payload string into separate tokens.

Parameters
payloadThe strategy string (e.g., "MACD:12:26:9").
Returns
A vector of parsed string tokens.

◆ runBollingerBands()

BacktestResult BacktestingEngine::runBollingerBands ( const MarketData & market_data,
int period,
double std_dev_multiplier )
private

Executes the Bollinger Bands strategy.

◆ runMACD()

BacktestResult BacktestingEngine::runMACD ( const MarketData & market_data,
int fast_period,
int slow_period,
int signal_period )
private

Executes the MACD strategy.

◆ runMovingAverageCross()

BacktestResult BacktestingEngine::runMovingAverageCross ( const MarketData & market_data,
int fast_window,
int slow_window,
bool use_ema )
private

Executes the Moving Average Crossover strategy (SMA or EMA).

◆ runRSI()

BacktestResult BacktestingEngine::runRSI ( const MarketData & market_data,
int period,
double overbought,
double oversold )
private

Executes the Relative Strength Index (RSI) strategy.

◆ runSimulation()

BacktestResult BacktestingEngine::runSimulation ( const MarketData & market_data,
const std::string & strategy_payload )

Routes the simulation request to the appropriate mathematical strategy.

Parameters
market_dataThe dataset to test against.
strategy_payloadThe formatted string containing strategy name and parameters.
Returns
A complete BacktestResult object.

The documentation for this class was generated from the following files: