← Back to list

Deep Latent Variable Models

Prepared by Ernest Chan, Chairman, and Nahid Jetha, CEO

QTS Capital Management · 2025-12-11 20:36 · 1 claps · 6.2 min read
#latent-variables #prediction-model #gaussian #feature-selection #parameter
Open on Medium ↗
Wiki topics: BIZ · Business Strategy 💄 · Beauty 🏛️ · Politics

Deep Latent Variable Models

Prepared by Ernest Chan, Chairman, and Nahid Jetha, CEO

In our previous article, we introduced latent variable models, where the latent variable can be thought of as a feature vector that has been “encoded” efficiently. This encoding turns the feature vector X into a context vector z. Latent variable models sound very GenAI-zy, but they descend from models that quant traders have long been familiar with.

No doubt you have heard of PCA or SVD (see Chapter 3 of our book for a primer)? Principal components or singular vectors are ways to represent returns in terms of a small number of variables. These variables are latent, or hidden, because they are inferred from the observed returns themselves, and not observable like the Fama-French factors such as HML or SMB. The benefit of applying these latent factors to model returns is that we need fewer parameters — i.e. dimensional reduction. For example, the covariance matrix of 500 stocks’ returns have 125,250 parameters, whereas its 10-principal-component model has only 5,010 parameters. The methods to find these latent factors are diagonalization of the covariance matrix in the PCA case, or singular value decomposition of the “design” (data) matrix in the SVD case.

More generally, latent variable models are used to model the probability distributions of the observed features X:

Equation 1

Equation 1

In the simplest case, z is just a categorical variable that takes 0 or 1 as value, with a binomial distribution, and p(X|z) is a Gaussian with parameters that depend on z. (You might think of the “context vector” z as encoding the information about X in the most compact manner possible: just 0 or 1.) Both the binomial and the Gaussian distributions here have fixed, but unknown, parameters that do not depend on X. This is called a Gaussian Mixture Model (GMM) and p(X) is written as

π is the probability of z=1, and ℵ 1 is a Gaussian with different parameters for each z.

In another familiar case, p(z) is no longer independently distributed, but each 𝑧_t at time t depends on t its previous value 𝑧_t-1 , governed by the transition probability αt_ij

This is the famous HMM (Hidden Markov Model). In an HMM, z still takes on 0 or 1 as values, and p(X|z) is still Gaussian.

We don’t know the actual distribution p(z) of the hidden variable z — after all, it is hidden! So how do we estimate its probability? Unlike PCA or SVD, the training algorithm used to find these unknown but fixed parameters is the celebrated EM (Expectation-Maximization) algorithm.

In the EM algorithm, as in the more general Variational Inference (VI) algorithm to be described later, the key to training the model is to introduce a proposal distribution q(z|X) (which we called the “encoder” in the VAE framework described in the previous article) which approximates p(z|X) instead of p(z). We start by estimating q(z|X) using some arbitrary parameters 𝜃 ^old for p(z|X,𝜃^old ), i.e. q(z|X)=p(z|X,𝜃^old). In the EM algorithm framework, this proposal distribution is also variously called the membership probability, the responsibility, posterior probability, soft assignment, or state occupancy probability. In our Gaussian mixture case,

Notice the expectations computed for the Gaussians. That’s why this is called E-step. In the VAE framework, you can think of this step as obtaining the output of the encoder.

Now to find a better 𝜃 in the next iteration, we are supposed to maximize the log likelihood LL=log p(X|𝜃) by varying 𝜃. But we don’t know the actual likelihood in Eqn (1) above, we only know an approximation

Equation 2

Equation 2

Hence, we will maximize Q w.r.t. instead. This is the M-step. Next, we set 𝜃^old=𝜃 that was just optimized and rinse, repeat, until convergence (e.g. when Q doesn’t significantly increase anymore.) In the VAE framework, you can think of this as a “backpropagation” step that optimizes the log likelihood function that the “decoder” p(X|z, 𝜃) generates.

Now for the general deep latent variable model, p and q are still Gaussians, but their parameters are no longer constants. They are sample-specific (i.e. they are themselves functions of X). Researchers typically denote the parameters for the encoder q(z|X) as 𝜙 and those for the decoder p(X|z) as 𝜃. These parameters are now weights and biases of two separate DNNs (deep neural network). As shown in the VAE diagram of the previous article, the parameters for q are (𝜇_𝑞, 𝜎_q )=DNN_𝜙(𝑋) and those for p are (𝜇 _p, 𝜎_p )=DNN_𝜃(𝑧).

Note the parallel with transformers. Conventional features selection, like the parameters of a conventional latent variable model (e.g. GMM and HMM), are fixed for the entire data set. But transformer-based features selection, like the parameters of a VAE, are sample-specific, offering much more flexibility. Of course, the price of this flexibility and specificity is that VAE can no longer be trained by the EM algorithm. It requires a method called Variational Inference (VI) Approximation. Similar to Eqn (2) above, the 𝐿𝐿=log𝑝(𝑋| 𝜃 , 𝜙) can be written as an expectation over q, but this time with an explicit error term D_KL :

Kingma and Welling 2019,“An Introduction to Variational Autoencoders”

Kingma and Welling 2019,“An Introduction to Variational Autoencoders”

Note the first term, called ELBO (Evidence Lower Bound, pronounced “elbow”), is analogous to Q in Eqn (2), except that it is an explicit function of X. The error term is the Kullback-Leibler Divergence — essentially the difference — between the proposal distribution 𝑞_𝜙(𝑧|𝑋) and the actual posterior distribution 𝑝_𝜃(𝑧|𝑋). Because D_KL ≥ 0 always, LL ≥ ん_𝜃,𝜙 always, and by maximizing ん_𝜃,𝜙 we can maximize LL as well. At the same time, as ん_𝜃,𝜙 increases, D_KL goes to zero, and 𝑞_𝜙(𝑧|𝑋) will be closer to 𝑝_𝜃(𝑧|𝑋). In other words, the proposal gets more and more realistic. To maximize ん_𝜃,𝜙 which is the loss function of the encoder-decoder network DNN_𝜙(𝑋) and DNN_𝜃(𝑧), we can apply SGD (stochastic gradient descent) on both 𝜃 and 𝜙 simultaneously. We will also need to assume a simple Gaussian prior 𝑝(𝑧)=ℵ(0,𝐼). For more details on training, see Chapter 6 of our book.

The entire process of training a VAE (encoder+decoder), just as in training a GMM or HMM, is unsupervised — no labels are needed. As we mentioned in our previous article, this allows us to pre- train a VAE using a vast amount of unlabeled data with perhaps only some relevance to the labeled data at hand. Once the VAE is pre-trained, we can use z (a sample of the output of the encoder) as features to train a supervised model for classification or regression. Other ways of using, training, or fine-tuning the VAE were explained in that article as well.

In summary, we see how VAE is really a generalization of the more familiar latent variable models like GMM and HMM, except here the parameters of the distributions q(z|X) and p(X|z) themselves depend on the input sample X. This allows for much more flexibility in modeling real-world data, just as the transformer allows for sample-specific features selection. The price to pay for this flexibility is that there are lots more parameters (weights and biases of the encoder and decoder) to fit, and we need much more data to fit them. But the saving grace is that we only need unlabeled training data, which is abundant in most domains including finance.

PredictNow.ai, an independent technology firm founded by Dr. Ernest Chan, has conducted research

applying latent-variable models to daily risk-on/off regime characterization in financial time series.

Readers interested in this research can contact info@predictnow.ai.

DISCLAIMER

QTS Capital Management LLC (“QTS”) is a Commodity Trading Advisor and Commodity Pool Operator registered with the U.S. Commodity Futures Trading Commission and a Member of the National Futures Association.

This material is provided for educational and informational purposes only and does not constitute investment advice or an offer to buy or sell any financial instrument.

Past performance is not necessarily indicative of future results.

All investments involve risk, including the possible loss of principal. There can be no assurance that an investment strategy will achieve its objectives or will otherwise meet expectations. Futures trading is not suitable for all investors.


메타데이터
post_id
b86597e88bf3
slug
deep-latent-variable-models-b86597e88bf3
url
https://medium.com/@qtscm/deep-latent-variable-models-b86597e88bf3
canonical_url
https://medium.com/@qtscm/deep-latent-variable-models-b86597e88bf3
author_url
https://medium.com/@qtscm
status
ok
fetched_at
2026-06-15 20:49:13