Artificial intelligenceIntermediate26 min read

Naming a cluster does not discover a market regime

Explore market clustering through distances, scaling, silhouette scores, label matching and time-aware assignment. Separate useful groups from retrospective regime stories.

Smooth beach stones arranged in three loose groups on cream paper, with an ambiguous stone between the groups
Conceptual photograph: grouping objects is a choice about similarity before it becomes a story about their meaning.

The names arrived after the colors

Three groups appear on Mateo’s screen. He has clustered hypothetical market observations using recent price and liquidity descriptors. One group contains several quiet periods, another contains large movements, and the third includes some days he remembers as difficult. Within minutes, the labels become “calm,” “trend” and “crisis.” The software never supplied those meanings. Mateo did, after looking at the chart and recognizing fragments of the history.

Naming is useful when it helps communicate a precise description. It becomes dangerous when the name silently upgrades a geometric grouping into a discovered economic mechanism. A cluster is initially a statement about similarity under a chosen representation. Whether it corresponds to a persistent market state, predicts something useful or supports a trading decision requires additional evidence. The three claims should not be bundled together simply because the visualization is attractive.

Our investigation is entirely hypothetical. Every coordinate, count and comparison below is an invented teaching example, not a result from TradeAndRoll systems. Mateo wants to construct a grouping process that another researcher can reproduce, assign to later observations and interpret without borrowing knowledge from the future. His first deliverable is a defensible description of the groups, not a profitable regime-switching strategy.

The distinction changes the workflow. Instead of asking which names sound most convincing, Mateo asks what one row represents, which inputs were available at its decision time, what distance means and how a new row receives a label. He then checks whether the groups remain recognizable under modest changes. Only after these steps does he investigate whether grouping improves a separate, explicitly defined research decision.

Decide what one point represents before choosing an algorithm

A point could represent one minute, one completed session, a rolling twenty-bar window or a single trading candidate. These units answer different questions. A session-level cluster summarizes a completed session, while a pre-entry cluster needs inputs available before the candidate entry. Calling both a market-state model obscures their information requirements. Mateo writes the unit of observation at the top of the dataset manifest.

Suppose he chooses one observation at each completed hourly bar. Its features describe only information available at that close. The next hour’s return is not an input. A session’s eventual high-low range is also unavailable if the session has not finished. A feature can look descriptive and still contain future information relative to the moment the label is supposed to be used. The clustering algorithm does not protect against that timing mistake.

Overlapping windows introduce another issue. If consecutive points each summarize the previous twenty bars, neighboring points share nineteen bars. A cluster containing hundreds of adjacent observations may represent only a few extended episodes. The row count remains correct, but it does not describe hundreds of independent occurrences. Mateo keeps both the number of assigned rows and the number of distinct temporal episodes visible.

The observation unit determines the interpretation of persistence. Labels that last many rows may simply reflect slow-moving rolling features. That can be appropriate for a particular purpose, but it should not be advertised as an independently discovered durable regime. The report records lookback lengths, overlap and sampling frequency so a reader can distinguish genuine changes in the representation from the mechanical memory built into it.

Similarity is a design decision with units

Consider an invented two-dimensional representation. The first coordinate is a volatility measure expressed in basis points; the second is a dimensionless directional-efficiency measure. Point A is (10, 0.1), B is (20, 0.1), and C is (10, 0.9). Under ordinary Euclidean distance on these raw values, A is ten units from B but only 0.8 units from C. The volatility coordinate dominates this particular comparison because its numerical scale is much larger.

Now divide volatility by ten while leaving directional efficiency unchanged. The distance from A to B becomes one, while the distance from A to C remains 0.8. If volatility is divided by twenty, the first distance becomes 0.5 and B becomes the nearer neighbor. The observations did not change; the representation of their units did. This is why a grouping can change dramatically after a seemingly innocent preprocessing choice.

Mateo does not conclude that every feature must receive identical variance. Equal numerical influence is itself a preference, not a neutral law. He chooses scaling according to the intended notion of similarity and records how its parameters were estimated. If the scale comes from data, only the permitted development observations contribute to that estimate. Later data are transformed with the frozen rule until an explicit update occurs.

A distance metric is an assumption about what differences matter. A useful review asks whether a small numerical distance corresponds to observations that should be treated similarly for the proposed purpose. If the answer is unclear, choosing a more sophisticated clustering algorithm will not repair the missing definition. The representation needs work before its groups can carry a meaningful interpretation.

Distances from A to B and C change when the volatility coordinate is divided by twenty: ten versus 0.8 becomes 0.5 versus 0.8
Hypothetical coordinates. Rescaling one dimension changes which observation is nearest without changing the underlying observations.

Compact groups do not automatically describe economic states

Mateo starts with a simple method whose behavior he can inspect. The scikit-learn clustering guide distinguishes algorithms with different notions of grouping, including centroid-based and density-based approaches. That diversity matters: a method designed around compact regions and a method designed around dense connected regions need not divide the same representation in the same way. Their disagreement is not automatically a software defect.

In his hypothetical one-dimensional example, the values are 0, 0.2, 0.4, 2.0, 2.2 and 2.4. Two compact groups centered at 0.2 and 2.2 provide a straightforward description. The total within-group squared distance is 0.16. One group centered at 1.2 has total squared distance 6.16. These arithmetic facts support the observation that the six values form two separated collections under squared distance.

They do not establish why the observations differ. The separation could reflect a session convention, a change in data feed, a known volatility difference or a preprocessing artifact. Naming the two collections “accumulation” and “distribution” would introduce a causal and economic story not contained in the coordinates. Mateo instead begins with literal descriptions, such as lower and higher values of the specified descriptor.

A descriptive grouping can still be useful. It may help audit data quality, compare model errors across observed conditions or select representative examples for manual review. Those uses do not require claiming that the groups reveal the market’s true hidden states. Keeping the initial claim modest makes it easier to determine whether the grouping actually serves a concrete research purpose.

A silhouette score has a narrow but valuable meaning

For a particular observation, let a be its average distance to other members of its own group and b the smallest average distance to another group. The silhouette value is (b − a) divided by the larger of a and b. The official silhouette documentation defines this comparison and the admissible number of labels. It is a measure of separation in the chosen distance space, not a score for financial usefulness.

Take a hypothetical point with a = 0.2 and b = 1.0. Its silhouette is 0.8. Another point has a = 0.6 and b = 0.4, giving −1/3, approximately −0.333. The first is closer on average to its own group; the second is closer on average to another. These calculations help Mateo identify ambiguous or awkward assignments rather than hiding every observation behind its final color.

An average silhouette can conceal a weak minority group. Suppose nine hypothetical observations each have silhouette 0.8 and one has −0.2. The mean is 0.7. That looks strong, but the exceptional observation still deserves inspection. If that observation represents a condition central to the intended use, the average alone is a poor decision criterion. Mateo reports the distribution and group sizes alongside the mean.

He also avoids comparing silhouette values across incompatible feature spaces as if they were measured on one common ruler. Changing the representation changes the distances being assessed. A better geometric score can coexist with a worse research representation. The next check is whether the groups describe relevant, available information and remain useful when applied under the intended chronological procedure.

Two hypothetical silhouette calculations: within-group distance 0.2 and alternative distance 1 give 0.8; 0.6 and 0.4 give minus one third
Silhouette compares distances within the selected representation. It does not measure a trading edge or explain the origin of a group.

Give the groups descriptions before giving them stories

Mateo prepares a profile for each group: counts, time coverage, feature medians, feature ranges and a few representative observations. He also examines whether one instrument, session or data vendor dominates a group. A cluster that mostly identifies a source-file change can be highly reproducible and economically uninteresting. Discovering that fact is useful because it prevents the data artifact from becoming a market narrative.

He initially uses neutral identifiers such as G0 and G1. Beside them he writes literal summaries: “higher recent range with low directional efficiency” or “lower spread descriptor during the sampled session.” These descriptions remain conditional on the feature definitions and development population. They are longer than “crisis,” but they tell a reader what was actually observed rather than asking the reader to accept a dramatic label.

A name can be added later if it stays clearly descriptive. The problem is not ordinary language; it is the disappearance of uncertainty. If a group contains both large upward and large downward movements, calling it bullish would be misleading. If a label comes from examining subsequent outcomes, it should be identified as a retrospective annotation rather than something the clustering process knew at assignment time.

The name must not carry more evidence than the profile. Mateo keeps the profile available whenever a name is used in a report. This also helps when the model is updated: the old name cannot be transferred automatically to a new numeric label without checking whether the underlying observations still share the same characteristics.

Numeric labels can swap while the partition stays identical

Two runs assign the first three observations to one group and the last three to another. Run A labels them 0, 0, 0, 1, 1, 1. Run B labels them 1, 1, 1, 0, 0, 0. A literal comparison of label numbers reports zero matches. Yet every pair of observations is grouped together or separated in exactly the same way. The partition is identical; only its arbitrary names changed.

Mateo compares membership structure rather than raw identifiers. The adjusted Rand index documentation describes a label-permutation-invariant comparison. For identical partitions such as these, the index is one. That gives him a useful mechanical check, but it does not prove that the grouping has economic meaning or will persist in later data. It answers a specific agreement question for the observations being compared.

For human-readable reporting, he can align groups using shared membership or feature profiles, while preserving the original model identifiers. If one old group splits into two new groups, forcing a one-to-one name mapping can conceal the change. The comparison should show splits, merges and unmatched groups explicitly. A clean-looking naming convention is less valuable than an honest account of changed structure.

Stable colors are not the same as stable groups. A dashboard may reuse blue for label zero in every run even when label zero has changed meaning. Mateo stores a versioned label dictionary and ties every displayed description to the fitted model that produced it. This small discipline prevents a visual convention from masquerading as evidence of temporal stability.

Six observations have labels 000111 in one run and 111000 in another; membership is identical despite zero literal label matches
Hypothetical label swap. Agreement should compare partitions, not the arbitrary numbers attached to them.

Fit first, then assign later observations

Mateo’s chronological exercise separates fitting from later assignment. In the development interval, he estimates preprocessing parameters and group representatives. He freezes both. Later observations are transformed with those saved parameters and assigned using a declared rule. If the chosen method has no natural out-of-sample assignment operation, he must specify an additional assignment method rather than silently refitting everything with the later data included.

Suppose two frozen one-dimensional representatives are 0.2 and 2.2. A later point at 0.8 is 0.6 from the first and 1.4 from the second, so nearest-center assignment chooses the first. A point at 1.2 is exactly one unit from each. The tie rule must be stated. A point at 6.0 is closer to 2.2 than 0.2 but far from both. Nearest does not mean familiar or well supported.

He therefore records distance to the assigned representative and an explicitly chosen unfamiliarity rule. A threshold selected on development information might mark very distant observations for separate review. That threshold is an operational convention, not a universal proof that a new regime has appeared. Its behavior must be assessed, including how often it rejects ordinary observations and what happens to subsequent decisions.

Assignment time is the moment the label becomes available. If the label depends on a completed hourly bar, it cannot explain a decision made earlier within that hour. The report links each label to its source-window endpoint and availability timestamp. This keeps a retrospective chart from quietly turning completed information into a signal that supposedly existed before the observation was finished.

Frozen centers at 0.2 and 2.2 assign 0.8 to the first group; 1.2 is a tie and 6.0 is distant from both
Hypothetical later observations. A nearest representative, a tie rule and an unfamiliarity check answer different assignment questions.

Refitting creates a new dictionary, not just refreshed colors

A later refit may change scaling, representatives, group count and label assignment. Mateo treats it as a new model version with its own dictionary. He does not overwrite the old assignments and then evaluate a historical policy as though the new labels had always been available. That would replace the original information set with a later interpretation of history.

Consider a simple illustration. Version one has centers 0.2 and 2.2, with a boundary at 1.2. Version two has centers 0.6 and 2.6, moving the boundary to 1.6. An observation at 1.4 changes groups even though its raw value is unchanged. The label change reflects a changed reference structure, not necessarily a change in that observation’s economic identity. Both versions can be reproduced if their artifacts are retained.

Mateo separates three questions: how a frozen model assigns later data, how a refitted model reorganizes common observations, and whether a policy with scheduled refits works as intended. The first tests application under a fixed dictionary. The second studies model change. The third requires a full chronological procedure including when refits occur and which data they may use. A single stability number cannot answer all three.

A refit is a research event with information consequences. Its schedule should be declared before evaluating the resulting policy, especially if a refit is triggered by disappointing outcomes. Otherwise the researcher may repeatedly redraw the state boundaries until a difficult period acquires a more flattering explanation. Preserving versions makes that adaptive history visible rather than erasing it.

Persistence can come from the measurement window

Suppose a label remains unchanged for twelve consecutive hourly observations. It is tempting to call that a twelve-hour regime. But if every feature averages the previous twenty hours, adjacent inputs are mechanically similar. The apparent persistence may be partly built into the representation. Mateo compares label runs with the memory length of the features before attaching an economic interpretation to their duration.

He distinguishes a run of labels from an independent episode. A run ends when the assigned label changes, but two runs separated by one ambiguous boundary point may still belong to one broader period. There is no universally correct way to merge them. If a smoothing or minimum-duration rule is introduced, it becomes part of the assignment procedure and must use only information available at the time it is applied.

Centered smoothing is particularly easy to misuse. A retrospective chart can remove brief label changes by consulting neighboring observations on both sides. A real-time procedure cannot inspect the future side without delay. Mateo either accepts the delay explicitly or uses a one-sided rule. The resulting labels may look less elegant, but they describe a process that could actually have been followed chronologically.

The raw label and the operational state should remain separate fields. The first records the grouping assignment; the second records any persistence rule used by a downstream policy. This separation allows a reviewer to see whether apparent stability came from the data representation, the clustering method or a later smoothing convention. It also makes failures easier to diagnose without rewriting the entire analysis.

A two-dimensional picture is not the whole geometry

If Mateo uses many descriptors or learned embeddings, he may project them into two dimensions for display. A clean separation in that picture is useful for orientation, but the projection has its own objective and distortions. Distances on the page need not equal distances in the original representation. A point that looks close to another in the plot may not be close under the metric used for clustering.

He labels the graphic as a visualization and records whether the groups were fitted before or after projection. Those are different pipelines. Clustering in the original representation and then plotting a projection can produce overlapping colors. Clustering in the projected coordinates may produce visually tidy groups that depend heavily on the projection settings. Neither should be described ambiguously as the same analysis.

The practical review includes original-space profiles and representative observations, not just a scatterplot. Mateo inspects a pair that appears close in the visualization and a pair near a boundary, checking their actual feature values. He also checks whether missing-data patterns or instrument identifiers dominate the representation. A visually striking separation can arise from a mundane preprocessing difference rather than a meaningful market distinction.

An embedding is another learned object to version and time. If it was trained on the full history, even an unsupervised representation may incorporate information from the later evaluation period. The researcher must decide whether the exercise is retrospective description or chronological application. The same coordinates cannot silently serve both purposes while retaining the stronger interpretation of the latter.

Describe outcomes without pretending the labels predicted them

After freezing descriptive groups, Mateo may examine subsequent outcomes by group. This can generate useful hypotheses, but the chronology matters. If he tries many representations and retains the one whose groups separate historical returns most impressively, outcome information has influenced the selection. The final groups are no longer an outcome-blind discovery merely because the clustering algorithm itself never received return labels.

He writes down the sequence of decisions. First came the representation, then the candidate groupings, then the outcome inspection, then any changes. This record prevents a common rhetorical shortcut: describing the final selected result as if it were the first untouched partition. The issue is the whole research procedure, including human choices, not just the formal inputs accepted by one software function.

A hypothetical group could have a higher average subsequent return and still be unsuitable for a trading rule. The difference might be small relative to costs, concentrated in one episode or associated with very few eligible decisions. The policy would also need a direction, size, timing and execution convention. Group-level outcome summaries are a starting point for specifying such a policy, not a complete result for it.

A retrospective label can describe the past without being a past signal. Mateo keeps descriptive findings available while clearly marking which decisions they informed. A later evaluation can then test the resulting frozen proposal. That preserves the value of exploratory work without pretending that exploration supplied evidence it was not designed to provide.

Compare the grouping with a simpler description

Before investing in a complex state model, Mateo asks what a simple descriptive rule would provide. For example, he might divide a declared volatility descriptor at a development-period threshold. This comparator is not automatically better, but it is easier to explain and reproduce. If a clustering pipeline adds substantial complexity, the research should identify what useful distinction that complexity contributes beyond the simpler partition.

The comparison depends on purpose. For manual review, useful distinction might mean selecting examples that cover more varied conditions. For error analysis, it might mean identifying a reproducible concentration of model mistakes. For an operational policy, it requires evaluating the actual policy and its costs. Mateo does not let a superior geometric score substitute for success on the intended task.

He also accounts for maintenance. A representation with many inputs may require more data feeds, more missing-value rules and more opportunities for version mismatch. Those are not arguments against complexity in principle. They are concrete costs that should be weighed against the documented benefit. A grouping that nobody can assign reliably outside the original notebook has limited operational value, however attractive its historical chart.

The comparison should preserve the same eligible observations. If the complex method silently drops difficult rows while the simple rule retains them, the apparent difference may come from coverage. Mateo reports assignments, rejected observations and reasons for rejection for both approaches. This makes the tradeoff between descriptive detail and practical coverage visible rather than hiding it inside different sample sizes.

Boundary observations deserve a place in the report

An attractive cluster report usually showcases representative points near the middle of each group. Those examples help explain the profiles, but the boundary cases reveal how much the label depends on small changes. Mateo keeps a separate boundary sample chosen by an explicit rule, such as a small difference between the distances to the two nearest representatives. He does not call that difference a probability unless a probabilistic model and its interpretation have actually been established.

In the hypothetical two-center example, a point at 1.19 lies 0.99 from the lower center and 1.01 from the upper center. A point at 1.21 reverses those distances. Their labels differ even though their coordinates differ by only 0.02. A downstream policy that makes radically different decisions for the two groups would amplify this small representational difference. The clustering result alone does not justify such an abrupt policy response.

Mateo can report the distance margin alongside the hard label. For 1.19, the difference between second-nearest and nearest distances is 0.02; for 0.8, it is 0.8. The first is closer to the decision boundary under this particular geometry. That observation does not establish an error probability or prove that the second assignment is economically correct. It describes the sensitivity of the assignment rule to movement in the chosen coordinate.

He next checks plausible measurement variation. Suppose the descriptor could change by 0.03 under an alternative but documented rounding convention. An observation at 1.19 may then cross the boundary. The appropriate action might be to preserve greater numerical precision, specify one rounding rule or introduce a separately tested operational buffer. It should not be to select whichever convention produces the preferred historical group. The implementation and the intended use determine the relevant response.

Missing inputs require similarly explicit treatment. A row filled with development medians can land near a common group center even though its actual condition is unknown. That assignment may look confident geometrically because imputation placed it in a typical location. Mateo preserves missingness flags and separates complete observations from imputed ones in the profile. A short distance after imputation is not evidence that the underlying unobserved values were ordinary.

He also investigates very small groups rather than automatically deleting them. A tiny group might identify a genuine unusual condition, a bad quote or a particular data-processing failure. Its size alone cannot settle the interpretation. The review examines source records, timing and feature construction. If it is excluded from a later analysis, the exclusion rule and affected observations remain visible, including what happens when a similar observation appears again.

Ambiguity is an output worth preserving. A useful descriptive system can say that some observations sit between its groups or outside familiar coverage. Forcing every case into a confident story makes the report easier to read but harder to trust. Mateo’s final profile therefore includes representative, boundary, distant and incomplete cases. Together they describe where the grouping works as a summary and where the summary should be treated cautiously.

The boundary review also changes how results are communicated to someone adapting a robot. A label should arrive with its version, availability time and relevant quality flags, not as an isolated word such as crisis. The recipient can then decide whether the proposed use tolerates ambiguous assignments. If the use requires certainty that the method cannot provide, the responsible research conclusion is to change the use or collect better evidence rather than strengthen the language around the same labels.

Make a small assignment test before a large regime narrative

The saved package also needs an explicit rule for reading input files. Mateo records column names, numeric parsing, time convention and missing-value representation. A decimal separator interpreted incorrectly can move an observation much farther than any ordinary market change. A repeated timestamp can duplicate a row and alter descriptive counts. These are mundane problems, but they affect the evidence before the clustering method has any opportunity to help. He checks a few source rows against their transformed versions and preserves the reconciliation in the package. A later reviewer can then distinguish a change in market observations from a change introduced while loading them.

Mateo builds a tiny fixture containing ordinary observations, a tie, a distant point and a missing-input case. For each, the expected preprocessing and assignment behavior are stated before the implementation is checked. In the two-center example, 0.8 belongs to the lower center, 1.2 invokes the declared tie rule, and 6.0 is assigned or rejected according to the documented unfamiliarity convention. These checks do not validate the economic idea, but they validate the mechanics being discussed.

He repeats the fixture after saving and reloading the model artifacts. The result should not depend on a hidden notebook variable or a fresh scaler fit. If an update changes the expected labels, the change should be explained by a versioned decision rather than accepted because the output still looks reasonable. This is where modest, inspectable examples often find problems that a large colored chart conceals.

An AI assistant can help build the inspection report if the request is concrete: “Use this frozen preprocessing and grouping artifact. Show feature definitions, distances, assignment rules and rejected cases. Compare partitions without relying on raw label numbers. Separate descriptive names from outcome-based annotations. Do not infer a market mechanism or invent performance.” The prompt asks for evidence that can be checked, not a persuasive account of hidden regimes.

The free TradeAndRoll demo offers ten Forex systems, their rules and source code, demo CSV data and research ideas. One useful exercise is to describe the conditions under which a chosen system produces candidates, while keeping grouping separate from its trading logic. Start with a label you can reproduce before building a story around it. A precise descriptive result is a stronger foundation for the next experiment than a dramatic regime name whose information history nobody can reconstruct.

Back to the Blog