Quant Memo
Advanced

TimeGAN for Sequential Synthetic Data

TimeGAN combines an autoencoder's supervised step-by-step training with a GAN's adversarial realism check, so synthetic sequences get both correct temporal dynamics and plausible overall shape — something either technique alone tends to miss.

Prerequisites: The GAN Minimax Objective, Variational Autoencoders

A GAN trained directly on raw sequences learns to produce realistic-looking windows, but has no explicit pressure to get the step-to-step dynamics right — nothing directly checks whether xt+1x_{t+1} plausibly follows from xtx_t the way it does in real data, only whether a whole window looks real in aggregate. An autoencoder trained to predict the next step gets the dynamics right by construction, but on its own tends to produce blurry, averaged-out sequences because minimizing squared error rewards hedging between plausible futures rather than committing to one sharp, realistic one. TimeGAN's idea is to use both losses on the same shared latent space, so each fixes the other's blind spot.

The analogy: a coach and a judge working together

Training a sequence generator with only a step-prediction loss is like a coach who corrects your form one movement at a time but never watches the whole routine — you can nail every isolated step and still produce something that looks robotic overall. Training with only an adversarial loss is like a judge who only scores the finished routine's overall impression, never checking whether any individual movement was technically correct. TimeGAN puts both a coach and a judge on the same routine at once: a supervised step-by-step loss (the coach) enforces correct-moment-to-moment dynamics, and an adversarial loss (the judge) enforces that the whole sequence, viewed as one thing, is indistinguishable from a real one.

Four networks, one shared latent space

TimeGAN trains four networks jointly, all operating in a shared learned latent space hh rather than on raw data directly: an embedder ee mapping real sequences into hh, a recovery network rr mapping back out, a generator producing latent sequences from noise, and a discriminator telling real latent sequences from generated ones. The generator is trained with three losses added together:

L=Ladversarial+λSLsupervised+λRLreconstruction\mathcal{L} = \mathcal{L}_{\text{adversarial}} + \lambda_S \, \mathcal{L}_{\text{supervised}} + \lambda_R \, \mathcal{L}_{\text{reconstruction}}

In words: be realistic overall (adversarial), get each next latent step right given the real previous steps (supervised — the coach), and let the embedder/recovery pair reconstruct real data accurately (reconstruction, so the latent space stays a faithful, invertible representation rather than collapsing to something meaningless). The supervised loss specifically is:

Lsupervised=E[htgh(ht1)2]\mathcal{L}_{\text{supervised}} = \mathbb{E}\Big[\big\lVert h_t - g_h(h_{t-1}) \big\rVert^2\Big]

In words: given the real latent state at t1t-1, penalize the generator's prediction of the next latent state hth_t against the actual next real latent state — a direct, per-step accuracy check that a purely adversarial loss never provides.

Worked example 1: the supervised loss catching a dynamics error

Suppose real latent states at consecutive steps are ht1=2.0h_{t-1}=2.0, ht=2.3h_t = 2.3 (a modest rise). The generator, conditioned on the real ht1=2.0h_{t-1}=2.0, predicts h^t=3.5\hat{h}_t = 3.5 — wildly overshooting. Supervised loss for this step: (2.33.5)2=1.44(2.3-3.5)^2 = 1.44, a large penalty applied immediately, per step, regardless of what the discriminator thinks of the sequence as a whole. A purely adversarial setup might not catch this error at all if the surrounding sequence still looks aggregately plausible.

Worked example 2: how the losses trade off

Say at some training checkpoint, adversarial loss is 0.50.5, supervised loss is 0.080.08, reconstruction loss is 0.020.02, with λS=10,λR=10\lambda_S=10, \lambda_R=10 (typical TimeGAN weighting, since the latter two are on a smaller natural scale). Total: 0.5+10(0.08)+10(0.02)=0.5+0.8+0.2=1.50.5 + 10(0.08) + 10(0.02) = 0.5+0.8+0.2=1.5. If a later checkpoint improves adversarial realism to 0.30.3 but supervised accuracy worsens to 0.150.15: total =0.3+1.5+0.2=2.0=0.3+1.5+0.2=2.0 — worse overall despite the "judge" score improving, because the "coach" score got much worse and is weighted heavily. This is the mechanism that stops TimeGAN from trading away correct dynamics purely to look realistic in aggregate.

Path explorer
13055time →
end (bold path) 100.38spread of ends 58.966 independent paths, same settings

A mean-reverting path like this has an exact, checkable one-step rule (pull toward a long-run mean); TimeGAN's supervised loss is the same idea generalized to whatever step-to-step rule the real training data actually follows, learned rather than assumed.

real x_1..T embedder noise z_1..T generator real h_t fake h_t D supervised loss
Real and generated sequences are both mapped into one shared latent space; the discriminator checks overall realism while the supervised loss (dashed link) directly compares real vs. predicted next latent steps.

TimeGAN trains a generator against both an adversarial loss (is the whole sequence realistic) and a supervised next-step loss computed in a shared learned latent space (is each step's dynamics correct given the real previous step) — fixing the blurriness of pure step-prediction models and the loose dynamics of pure GANs at once.

What this means in practice

TimeGAN-style models are used to generate synthetic multi-asset or multi-feature sequences — for example, joint price and volume paths, or panels of correlated factor returns — where getting the cross-sectional and temporal structure both right matters for downstream backtests, not just the marginal shape of any single series.

A model can post an excellent adversarial (discriminator-fooling) score while still getting basic dynamics wrong — for instance, generating returns that are individually plausible in isolation but whose one-step autocorrelation structure doesn't match real data at all. Always check the supervised/one-step-ahead accuracy separately from the adversarial realism score; a good overall "look" is not evidence of correct dynamics.

Related concepts

Practice in interviews

Further reading

  • Yoon, Jarrett & van der Schaar, Time-series Generative Adversarial Networks (2019)
ShareTwitterLinkedIn