Most regime tools ask for a fixed number of states. This article implements a Dirichlet process mixture for MQL5 with truncated stick-breaking and varying coordinate ascent, so the cluster count is inferred from data and the evidence bound is monitored each iteration. The package includes a nine-file library, an out-of-sample indicator that scores each bar, a six-level test suite, and a shuffle-based null control to judge how much the recovered count means.
Open any regime detection tool: the first input is the number of regimes. Nobody knows the right number, and the setting matters. A model forced to find two states will find two even if the market had one, or six. The transition matrix, the per regime statistics and the position sizing rule all sit on a number guessed before any data was read.
The Dirichlet process removes the guess. Each new observation either joins an existing cluster, with probability proportional to its size, or opens a brand new one. The number of clusters is therefore a random variable with a distribution, not a setting with a value, and it grows as data arrives at a rate known in closed form.
It is a different question from the one a change point detector answers: a detector says the series just broke, a mixture names what it broke into. It is also unusually testable. The prior's mean and variance are exact sums. The fitter has an invariant a correct implementation cannot break. The predictive density must integrate to one. Most of the code can be validated before any price data is used.
The library consists of nine header files with no external dependencies. It fits a truncated stick-breaking Gaussian mixture with full covariance using coordinate ascent rather than sampling. On top of that, it provides an indicator that scores each bar against a model fitted on strictly older data, and a market scan that compares the system to a null.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Dirichlet Process Mixtures: How Many Market Regimes Are There, and Does the Answer Mean Anything?.
Open any regime detection tool: the first input is the number of regimes. Nobody knows the right number, and the setting matters. A model forced to find two states will find two even if the market had one, or six. The transition matrix, the per regime statistics and the position sizing rule all sit on a number guessed before any data was read.
The Dirichlet process removes the guess. Each new observation either joins an existing cluster, with probability proportional to its size, or opens a brand new one. The number of clusters is therefore a random variable with a distribution, not a setting with a value, and it grows as data arrives at a rate known in closed form.
It is a different question from the one a change point detector answers: a detector says the series just broke, a mixture names what it broke into. It is also unusually testable. The prior's mean and variance are exact sums. The fitter has an invariant a correct implementation cannot break. The predictive density must integrate to one. Most of the code can be validated before any price data is used.
The library consists of nine header files with no external dependencies. It fits a truncated stick-breaking Gaussian mixture with full covariance using coordinate ascent rather than sampling. On top of that, it provides an indicator that scores each bar against a model fitted on strictly older data, and a market scan that compares the system to a null.
Author: Hammad Dilber