Engine responsible for executing trading strategies.
More...
#include <tradebench_core.h>
|
| 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.
|
| |
Engine responsible for executing trading strategies.
◆ 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
-
| source | Input data vector. |
| period | The EMA window period. |
| start_idx | The index to start calculating from. |
| ema_out | The 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
-
| prices | Input price vector. |
| period | The RSI calculation period. |
| rsi_out | The 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
-
| res | The result structure to update. |
| last_price | The final price of the asset. |
| initial | Initial capital. |
| current | Current fiat capital. |
| amount | Current crypto holdings. |
| in_pos | Whether a position is currently open. |
| wins | Total 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_data | The 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
-
| payload | The 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_data | The dataset to test against. |
| strategy_payload | The formatted string containing strategy name and parameters. |
- Returns
- A complete BacktestResult object.
The documentation for this class was generated from the following files: