DEV Community

Prof. Dr. Gustavo Henrique Valente: Building a Regime-Detection Layer for Brazilian Market Data

Most financial dashboards start with prices.

For a developer building analytical tools, that is understandable. Prices are available, easy to chart and simple to compare.

But for portfolio-risk analysis, price is usually the final output of several deeper states.

In Brazilian markets, those states include interest rates, inflation, currency, equity breadth and cross-asset correlation.

A regime-detection layer should try to classify those states before making any interpretation of asset performance.

The Goal

The purpose of the system is not to predict the next Ibovespa close or the next USD/BRL tick.

The purpose is to answer a more useful question:

What environment is the portfolio currently operating in?

A practical system might classify Brazil’s market state into categories such as:

Restrictive rates.

Inflation persistence.

Currency support.

Currency pressure.

Narrow equity breadth.

Broad equity participation.

Correlation stress.

Mixed or uncertain regime.

The final label should always include a confidence score.

Data Blocks

The first block is rates.

Useful inputs may include the Selic rate, DI futures, nominal yields, inflation expectations and estimated real rates.

The system should detect whether rates are moving in parallel, steepening, flattening or diverging between the front end and long end.

The second block is inflation.

The system should not store only the headline number. It should separate food, services, housing, regulated prices and imported categories when available.

Different categories have different persistence.

The third block is currency.

USD/BRL should be decomposed into possible drivers: interest-rate differential, global dollar strength, commodity conditions, local risk premium and foreign capital flows.

The fourth block is equity breadth.

This can include sector participation, advancing versus declining names, turnover concentration and the share of index movement explained by a small group of companies.

The fifth block is correlation.

Rolling correlations across equities, bonds, currency, commodities and digital assets can indicate whether diversification is becoming more fragile.

Simple System Design

A clean architecture might contain five stages.

Data ingestion.

Feature engineering.

Signal classification.

Confidence scoring.

Human-readable explanation.

The explanation layer is essential.

A model that says “currency pressure is rising” should also explain whether that signal comes from the global dollar, local rates, commodity movement or market liquidity.

Without an explanation layer, the system becomes a black box.

Black boxes are difficult to govern in financial environments.

Example Feature Logic

For the rates block:

If the Selic is high, real rates are positive and the long end of the curve rises faster than the front end, the system may classify the rate regime as restrictive with long-end stress.

For the inflation block:

If headline inflation falls but service inflation and expectations remain firm, the system should avoid classifying inflation risk as fully resolved.

For the currency block:

If the real strengthens while the global dollar weakens, the model should not automatically attribute the move to domestic improvement.

For the breadth block:

If the equity index rises while participation narrows, the market state should be marked as less robust.

For the correlation block:

If rolling correlations rise across assets during volatility, the system should flag diversification stress.

Why This Matters

Developers often measure model quality by prediction accuracy.

In portfolio systems, interpretability and stability can be just as important.

A regime classifier that correctly identifies rising uncertainty may help risk managers even if it never predicts an exact price.

The model should tell users when confidence is high, when signals are mixed and when human review is required.

That is especially important in Brazil, where monetary policy, inflation, fiscal expectations, currency movement and global liquidity often interact quickly.

Final Principle

A good financial AI system should not try to sound certain.

It should try to be useful.

For Brazilian market data, usefulness begins with recognizing that prices are not the whole story.

They are the result of changing regimes.

Build the state layer first.

Interpret the price later.

https://www.profdrgustavohenriquevalente.com/

Top comments (0)