Synthetic OHLC Simulation via DCC–GARCH — Free Online Preview | Dr Krzysztof Ozimek
Free Online Preview

Synthetic OHLC Simulation via DCC–GARCH

Including a Comprehensive R and Python Implementation and
a Brief Walk-Forward Backtesting Interface

📚 Bundle: PDF Textbook (39 pages) · R & Python Scripts & Projects 📖 Price: $59 + VAT ISBN 978-83-980747-2-8

PDF Preview  ·  Full Product Page

Get the Bundle
Synthetic Data in Inferential Backtesting bundle cover

Introduction

From One Path to Many

Every quantitative finance practitioner who has run a backtest has encountered the same uncomfortable arithmetic: one historical dataset, one sequence of market conditions, one realized outcome. The temptation is to treat this single trajectory as representative—to read the backtest result as though the market had no other direction it could have taken. This textbook is built on the rejection of that temptation. Its starting point is the recognition that the historical record, however long, is a single draw from a much larger space of plausible market evolutions, and that simulation is the discipline of exploring that space deliberately rather than accepting the accident of what happened to occur.

The instrument of that exploration, in this textbook, is the Dynamic Conditional Correlation GARCH (DCC–GARCH) model. Fitted once to an observed OHLC price series, it becomes a calibrated generative mechanism: a compact mathematical object that can be run forward thousands of times, each run producing a plausible alternative history with the same volatility clustering, the same correlation dynamics, and the same intrabar price geometry as the original data—but not the same path. Beyond replicating the baseline dynamics, the same engine can generate stressed alternatives: paths in which volatility is elevated at the origin, correlations are shifted toward a crisis regime, shocks follow heavier tails, or the terminal price level is prescribed in advance. The resulting ensemble replaces a single backtesting trajectory with a distribution of trajectories, turning a point estimate of strategy performance into a structured object amenable to statistical inference.

Why DCC–GARCH for OHLC Simulation

The choice of DCC–GARCH as the simulation engine is neither incidental nor merely conventional. It reflects a specific match between what the model can do and what OHLC data require. Financial returns are not i.i.d. Gaussian: volatility clusters, marginal distributions carry heavy tails, and pairwise correlations are non-stationary—they spike during market stress and recede in calm regimes. These are not pathologies to be corrected; they are structural features that a simulation model must replicate if the synthetic paths it generates are to be financially credible.

DCC–GARCH addresses all three simultaneously. It factors the conditional covariance matrix \(\mathbf{H}_t = \mathbf{D}_t \mathbf{R}_t \mathbf{D}_t\) into a diagonal matrix of marginal conditional volatilities, each governed by its own GARCH(1,1) equation, and a time-varying correlation matrix driven by the scalar DCC(1,1) recursion. The factorization is what makes the model tractable for the four-dimensional latent representation of OHLC data: rather than estimating a 4-dimensional covariance process jointly, Stage 1 fits four independent univariate GARCH models and Stage 2 estimates just two DCC parameters regardless of dimension. The 28 parameters that result—16 from Stage 1, 2 DCC scalars, and 10 elements of the plug-in unconditional correlation matrix—are sufficient to characterize the full joint dynamics of the latent OHLC series.

Equally important is what the DCC–GARCH model does not attempt: it makes no claim about the direction of returns. The model is a second-moment model—it governs the size and dependence structure of shocks, not where prices go. This restraint is a feature, not a limitation. A simulation tool that imposes directional views contaminates the synthetic ensemble with the researcher's priors. One that models only the covariance structure leaves the direction of each simulated path entirely to the draws of the random number generator, producing genuine scenario diversity.

The Latent OHLC Representation

A candlestick bar \((O_t, H_t, L_t, C_t)\) is not four independent numbers. It carries a hard geometric constraint: \(L_t \leq \min(O_t, C_t) \leq \max(O_t, C_t) \leq H_t\), which is native to the data, not an assumption imposed from outside. Naively feeding raw OHLC prices into a multivariate time series model and then decoding the output will routinely produce bars that violate this constraint, making the synthetic paths financially meaningless before any strategy is applied to them.

The solution developed in this textbook is a bijective encoding map that transforms each bar into a four-dimensional latent vector \(\mathbf{z}_t = (d_t^{OC},\, d_t^{HA},\, d_t^{LB},\, y_t)^\top\), where \(d_t^{OC} = C_t - O_t\) is the signed body, \(d_t^{HA}\) and \(d_t^{LB}\) are the log-scaled upper and lower wick magnitudes, and \(y_t = \ln\mu_t\) is the log midprice. All four components lie freely in \(\mathbb{R}\) with no ordering constraints among them. DCC–GARCH is applied to the first-differenced series \(\mathbf{x}_t = \Delta\mathbf{z}_t\), which is stationary. Simulation produces a sequence of \(\mathbf{x}_t\), cumulation recovers \(\mathbf{z}_t\), and the decoding map inverts the encoding algebraically, yielding OHLC bars that satisfy the geometric constraint at every simulated step, by construction, without any post-processing.

This architecture means that constraint validity is a structural property of the simulation pipeline, not a correction applied after the fact. It also means that every component of the bar has a distinct and interpretable role in the latent space, making the stressing levers developed in Chapter 2 precisely targeted—for example, a lever that modifies the initial value of \(d_0^{OC}\) shifts only the directional character of the opening bar, leaving the wick structure and price level untouched. Five such levers are available in total, each acting on a different dimension of the simulation: the starting state, the initial volatility regime, the initial correlation structure, the shock distribution at every step, and the terminal price level.

Stressing Levers and the Simulation Interface

A simulation model that can only reproduce the unconditional dynamics of a calibrated dataset is useful but limited. What distinguishes this framework is the set of four named stressing levers—plus a fifth post-simulation endpoint mechanism—that allow the researcher to depart from the baseline in specific, financially interpretable, and fully reversible ways.

  • Lever 1 overrides the initial latent state vector \(\mathbf{z}_0\), enabling control over the starting price level, the direction of the first bar, and the initial wick structure.
  • Lever 2 scales the initial conditional standard deviations \(\sigma_0^{(i)}\) by factors \(\lambda^{(i)} > 1\), where \(i = 1, \ldots, 4\) indexes the four latent OHLC components, injecting a volatility shock at the simulation origin whose subsequent decay is entirely governed by the estimated GARCH parameters—no additional assumptions required.
  • Lever 3 interpolates the starting pseudo-correlation matrix \(\mathbf{Q}_0\) toward a user-supplied crisis-regime target \(\mathbf{Q}^*\), with the DCC recursion then reverting toward the long-run \(\bar{\mathbf{Q}}\) at its estimated speed.
  • Lever 4 modifies the shock distribution \(\pmb{\varepsilon}_t\) at every simulation step, accommodating five financially distinct scenarios:
    • a) fat-tailed draws,
    • b) global amplification,
    • c) directional conditioning via acceptance-rejection,
    • d) a single deterministic shock injection at a prescribed step,
    • e) and systematic macro factor loading.
  • Lever 5 (the \(\mu^*\)-transform), applied post-simulation via the clg argument, bridges each synthetic path to a prescribed cumulative log-return of the midprice without altering the three candle-shape components.

All five levers are independently settable and fully composable. Setting all to their neutral defaults recovers the baseline simulation exactly—a property that makes the stressing framework interpretable and the results reproducible.

Walk-Forward Backtesting Interface

Section 2.5 describes briefly but substantively how the function simulate_ohlc_dcc() can be employed in a Walk-Forward (WF) paradigm. It operates on a single historical OHLC path and produces \(S\) synthetic paths of the same length. Applied within this paradigm, each synthetic path—whether baseline or stressed—supports the same calibration-and-evaluation cycle as a real path: the trading model is calibrated on the in-sample (IS) block and evaluated on the consecutive out-of-sample (OOS) block. Repeating this across all \(S\) synthetic paths and all \(n\) WF-generated OOS blocks produces the \(S \times n\) performance matrix \(\mathbf{P}\), where \(P_k^{(s)}\) is the performance measure realization on the \(k\)-th OOS block along the \(s\)-th synthetic path. The resulting distribution of performance trajectories provides a substantially richer basis for statistical inference than a single historical evaluation; Section 2.5 offers the reader a first concrete look at what such inference can deliver.

Relationship to the Related Textbook

This textbook is one of two that share a common object—synthetic OHLC paths—but approach it from different angles. Synthetic Data in Inferential Backtesting (Ozimek, 2026) develops a broader simulation framework based on ARMA–GARCH–Copula marginal models, a Directional Change partitioning mechanism, and a TOTO foundation model for out-of-sample forecasting, and deploys the resulting paths within a full walk-forward backtesting framework culminating in the performance matrix \(\mathbf{P} \in \mathbb{R}^{S \times n}\) and its inferential uses.

The present textbook is narrower in scope and deeper in mechanism. Its contribution is the DCC–GARCH engine itself: the complete model specification, the two-stage quasi-MLE estimation procedure, the simulation algorithm, the stressing architecture, and the documented script bundle that implements all of this in both R and Python. Where the companion textbook asks what can be done with synthetic OHLC paths at the level of a backtesting system, this one asks how a specific class of such paths is generated, parameterized, and controlled at the level of the model. The two are complementary rather than overlapping: a reader of one will find the other a natural continuation rather than a repetition.

Nature and Epistemological Position

The DCC–GARCH model is well-established in the econometrics literature, and its properties—consistency of the two-stage estimator, conditions for stationarity, asymptotic behavior of the correlation recursion—have been studied extensively since Engle (2002). This textbook does not contribute to that theoretical literature. It takes the model as given and asks a different question: how does one build a simulation pipeline around it that is practically usable, financially interpretable, and pedagogically transparent?

The answer developed here is decidedly constructive rather than axiomatic. The choices made at each stage—the latent encoding, the two-stage estimation, the stressing lever design—are motivated by practical and financial reasoning, not by optimality theorems. The framework rests on explicit modelling assumptions: Gaussian baseline shocks, plug-in estimation of the long-run correlation matrix \(\bar{\mathbf{Q}}\), and a symmetric volatility response. These are not presented as the only defensible choices; they are the choices made here, and the reader who understands why each was made is in a position to revisit any of them.

The reader is therefore invited to engage with this material as a practitioner-researcher: to understand the mechanism well enough to adapt it, to recognize where the model's assumptions bind in a given application, and to use the accompanying scripts as a working laboratory. The framework presented here is a starting point with identified edges, not a finished system with certified properties. Its value lies in making a specific and coherent simulation workflow concrete, executable, and open to extension.

Accompanying Scripts

More about the scripts — including function signatures, argument definitions, and canonical usage patterns — can be found in the PDF preview.

Get the Bundle
$59 + VAT ISBN 978-83-980747-2-4