|
tzutrader
A composable C++ backtesting library for trading strategies (experimental)
|
Classes | |
| struct | Signal |
| Trading signal generated by a strategy. More... | |
| struct | Ohlcv |
| Open-High-Low-Close-Volume candlestick data. More... | |
| struct | Tick |
| struct | SingleValue |
| struct | Position |
| struct | Trade |
| struct | PerformanceMetrics |
| struct | BuyAndHoldMetrics |
| class | Indicator |
| Base indicator class using CRTP for static polymorphism. More... | |
| class | SMA |
| Simple Moving Average (SMA). More... | |
| class | EMA |
| class | MVar |
| class | RSI |
| struct | MACDResult |
| class | MACD |
| class | MDD |
| class | Portfolio |
| class | BasicPortfolio |
| class | Runner |
| class | BasicRunner |
| class | PortfolioStats |
| class | Strategy |
| class | SMACrossover |
| class | RSIStrat |
| class | MACDStrat |
| struct | CsvParseTraits |
| struct | CsvParseTraits< Ohlcv > |
| struct | CsvParseTraits< Tick > |
| struct | CsvParseTraits< SingleValue > |
| class | ParseIterator |
| class | Csv |
Enumerations | |
| enum class | Side { BUY , SELL , NONE } |
| Trade direction enumeration. More... | |
| enum class | OhlcvField { OPEN , HIGH , LOW , CLOSE , VOLUME } |
| Field selector for OHLCV data. More... | |
| enum class | DataType { OHLCV , TICK , SINGLE_VALUE } |
| enum class | TimeInterval { NANOSECONDS , MICROSECONDS , MILLISECONDS , SECONDS , MINUTES , HOURS , DAYS , WEEKS , MONTHS , YEARS } |
Functions | |
| std::ostream & | operator<< (std::ostream &os, const BasicPortfolio &portfolio) |
| double | compute_max_drawdown (const std::vector< std::pair< int64_t, double > > &equity_curve) |
| double | compute_sharpe_ratio (const std::vector< double > &returns, double years) |
| std::vector< double > | compute_returns (const std::vector< std::pair< int64_t, double > > &equity_curve) |
| PerformanceMetrics | compute_performance_metrics (const std::vector< std::pair< int64_t, double > > &equity_curve) |
| BuyAndHoldMetrics | compute_buy_and_hold_metrics (double init_cash, double init_price, double final_price, double years) |
| std::string | unixTimeToString (int64_t unixTime, TimeInterval interval=TimeInterval::SECONDS, bool local_time=false) |
Variables | |
| constexpr size_t | MAX_BUFFER_SIZE = 2048 |
This header file defines various trading strategies that utilize technical indicators to generate buy and sell signals. Each strategy is implemented as a class that shares a common interface for updating with new market data and generating signals. The strategies include methods to inform the required data types and the number of items they need to process. This is designed to allow strategies that require multiple inputs, for example prices and macroeconomic indicators.
This file defines data streamers. It is designed to be extensible by having specific parser traits for each data type, iterators that read from streams and parse lines, and simple reader classes that integrate these components, like the Csv class reader.
Note: Error handling is currently minimal. If a line fails to parse, it is simply skipped and a warning is printed to standard error. It is expected that the input is well-formed, being validated by a pre-processing step, which is out of scope for this module.
(C) 2026 Jaime Lopez https://codeberg.org/jailop
|
strong |
|
strong |
Field selector for OHLCV data.
Used by indicators or strategies that need to access specific fields of OHLCV data. Use with Ohlcv::getFieldValue() to retrieve values.
| Enumerator | |
|---|---|
| OPEN | Opening price. |
| HIGH | Highest price in period. |
| LOW | Lowest price in period. |
| CLOSE | Closing price. |
| VOLUME | Trading volume. |
|
strong |
Trade direction enumeration.
Used to label trades and signals. The NONE value can be used to represent a hold signal (no action).
| Enumerator | |
|---|---|
| BUY | Buy signal or long position. |
| SELL | Sell signal or short position. |
| NONE | No action, hold current position. |
|
strong |
|
inline |
Compute buy-and-hold benchmark metrics.
|
inline |
Compute maximum drawdown from an equity curve.
|
inline |
Compute performance metrics from an equity curve.
|
inline |
Extract periodic returns from equity curve.
|
inline |
Compute Sharpe ratio from periodic returns. Assumes risk-free rate of 0. Returns annualized Sharpe ratio.
|
inline |
| std::string tzu::unixTimeToString | ( | int64_t | unixTime, |
| TimeInterval | interval = TimeInterval::SECONDS, | ||
| bool | local_time = false ) |
Convert a unix time to a string representation. Unix time is represented as an integer that can represent seconds or fractions of seconds.
|
constexpr |