Appearance

Personalize your experience

Mode
Accent Color
Direction
C++ SDK Reference

C++ SDK Reference

C++ SDK

Header-only C++20 (packages/quatick-backtest-cpp): the position simulator, an event-driven engine with the same order rules as Python, analytics, a parallel optimizer, walk-forward, Monte Carlo and portfolios.

Headers

HeaderContents
bars.hppBars, Params (name= arguments, QUATICK_PARAMS), read_csv, load_engine_bars
ta.hppsma, , rma, , highest, lowest, change, roc, , rsi, tr, atr, macd, bbands, crossover, crossunder
backtest.hppExecution (all cost and slippage models), simulate, compute_stats, backtest
engine.hpp, Context, orders (market, limit, stop, stop-limit, trailing, brackets, OCO), run<S>()
.hpprisk_metrics, trade_metrics, drawdown_periods, monthly_returns
.hppgrid_search / search on a pool, walk_forward, deflated_sharpe
montecarlo.hpptrade_monte_carlo ( / shuffle), stationary_bootstrap
portfolio.hppportfolio_backtest (target weights, shared capital, attribution, turnover)
event_main.hppQUATICK_EVENT_STRATEGY(S): the main that runs S on the Quatick engine

An event-driven strategy

breakout.cpp
#include <quatick/quatick.hpp>struct Breakout : quatick::Strategy {  quatick::Series hi, atr;  void init(quatick::Context& c) override {    hi = quatick::highest(c.bars.high, p.geti("n", 20));    atr = quatick::atr(c.bars, 14);  }  void on_bar(quatick::Context& c) override {    const size_t i = c.i;    if (c.position() != 0 || !c.open_orders().empty() || i == 0 || quatick::is_na(hi[i - 1])) return;    if (c.close() > hi[i - 1]) {      const double stop = c.close() - 2 * atr[i];      c.buy(c.size_by_risk(1.0, c.close() - stop), {.tag = "breakout", .sl = stop, .tp_pct = 6});    }  }};QUATICK_EVENT_STRATEGY(Breakout)   // upload as-is: the server supplies bars, params and settings

OrderOpts fields are designated initializers in declaration order: type, limit, stop, trail_pct, trail_amount, tif, expire_bars, tag, reduce_only, oco, sl, tp, sl_pct, tp_pct.

Local research

research.cpp
auto bars = quatick::read_csv("btc_1h.csv", "1h");
quatick::Execution ex;
ex.cost_kind = quatick::CostKind::CryptoMakerTaker; ex.cost_value = 0.02; ex.taker_pct = 0.05;
ex.max_drawdown_stop_pct = 25;

auto r = quatick::run<Breakout>(bars, {}, ex);
auto risk = quatick::risk_metrics(r.equity);          // var95, cvar95, omega, ...
auto tm = quatick::trade_metrics(r.trades);           // sqn, kelly, by_exit, by_side

auto eval = [&](const quatick::Bars& b, const quatick::Params& p) { return quatick::run<Breakout>(b, p, ex); };
auto runs = quatick::grid_search(eval, bars, {{"n", {10, 20, 40}}}, "sharpe", 8);   // 8 threads
auto wf = quatick::walk_forward(eval, bars, {{"n", {10, 20, 40}}}, 3000, 1000);

std::vector<double> pnl; for (auto& t : r.trades) pnl.push_back(t.pnl);
auto mc = quatick::trade_monte_carlo(pnl, ex.capital, 10000, quatick::McMethod::Bootstrap);
build
c++ -std=c++20 -O2 -pthread -I packages/quatick-backtest-cpp/include research.cpp -o research
# CMake: add_subdirectory(packages/quatick-backtest-cpp) and link quatick::backtest

Three ways to upload C++

File containsThe server
std::<double> (const quatick::Bars&, const quatick::Params&)adds its own main and simulates the positions
a quatick:: and QUATICK_EVENT_STRATEGY(S)runs the event engine with the run’s costs and settings
its own int main()runs it as a program; it must write {"positions"|"signals"|""} to QUATICK_OUTPUT_JSON
ℹ
Note:The engine compiles every translation unit of a project with the SDK and every project folder on the include , and caches the binary by source hash, so sweeps and compile once.

See also

Related articles

  • Backtesting in Python and C++

    Backtesting / SDKs

    The quatick Python package and the header-only C++ library let you import indicators, backtest on your own machine and send the same file to Quatick.…

  • Engines — Python vs C++

    Automation / Predefined Strategies

    Two independent implementations of the same grid semantics, consuming the same config and the same command channel. The choice is a runtime choice, not a…

  • Python: Research Toolkit

    Backtesting / SDKs / Python

    Everything after the first backtest: tearsheet analytics, multi-asset portfolios, position sizing, optimization and walk-forward, overfitting tests, Monte…

  • The Backtest Engine

    Backtesting / Engine

    One service backtests every kind of strategy on Quatick. Each source type runs on the engine built for it, and every result is measured with the same…

  • Orders and Fills

    Backtesting / SDKs / Orders and Fills

    The event-driven engines of the Python and C++ SDKs share one set of order types and fill rules, so the same strategy fills identically in both languages…

  • Python: Event-Driven Strategies

    Backtesting / SDKs / Python

    Subclass quatick.Strategy to trade bar by bar with real orders: brackets, trailing stops, limits, risk-based sizing and a drawdown kill switch. The same…

  • QuaScript C++ Engine & Quant DSL

    Coding / QuaScript

    Sub-microsecond quantitative algorithmic scripting engine powered by C++20 bytecode VM, SIMD AVX2 acceleration, cache-aligned columnar memory, and direct…

  • Backtesting Methodology

    Backtesting / Methodology

    What a backtest is actually evidence of, the assumptions built into it, how much data is enough, and the procedure that makes a result worth acting on.

  • Execution Modelling

    Backtesting / Execution Modelling

    Commission, slippage, spread and fill assumptions — the difference between a backtest that means something and one that flatters. Costs are where most…

Browse all knowledge base articles →