PT

From the Spreadsheet with Solver to AI Orchestration: A Process Account on Dividend Portfolio Optimization

Alisson Prata, CFP® ·

This does not constitute investment advice or securities analysis. The author is not a CVM-accredited analyst. Past performance does not guarantee future results.

The spreadsheet with Solver solves the portfolio optimization problem. It maximizes the Sharpe ratio, respects relative constraints on the weights, and converges to a solution in seconds. The problem is what it does not allow with rigor and scale at the same time: separation between the calibration period and the test period, a dynamic risk-free rate retrieved via API, a static backtest with six years of history, and auditable methodological boundaries. Not because it is impossible in Excel, but because the implementation cost is high enough that simplification beats rigor most of the time.

What changes when AI enters as the implementation environment, and what does not change, is what this text describes.

AI did not replace analytical judgment. It tore down the implementation barrier.

The design process was deliberately dialogical, not hierarchical. Each architectural choice came after at least one round of exchange: I proposed a direction, Claude or Gemini brought up implications I had not mapped out, and the adjustment followed from there. Separating calibration from testing into fixed windows, retrieving the CDI via the Central Bank API instead of using a fixed rate, setting the bounds at 50% to 200% over the analyst's weights, redistributing the weights of discontinued tickers among the remaining ones instead of discarding the portfolios: each of these decisions went through this dynamic. The weight redistribution, for example, came along with the observation that tickers with no data tend to be discontinued or problematic, which constitutes a mild form of survivorship risk. Knowing this before finalizing the decision is exactly what the dialogical process adds. Responsibility for the choices is mine. The path to reaching them was shared.

The code, the script structure, and the iterative execution of each version were Claude's.

There is a mistaken version of how to use AI in analytical work: throw the problem at the tool and accept the output. What works is different. AI is the implementation environment. The analyst is the architect of the decisions. When this hierarchy is inverted, the result is code that runs but answers poorly formulated questions.

What the Experiment Showed

The test used two recommended dividend portfolios from two Brazilian firms, exactly as published in June 2022, with tickers and weights verified against the original PDFs. The optimizer, a Sharpe maximizer with constraints relative to the analyst's weights, was calibrated exclusively with data from June 2019 to May 2022 and tested from June 2022 to June 2026. As a passive benchmark, DIVO11 was used, a dividend ETF with history over the full period. The CDI over the test period, drawn from BCB series 11, was 13.1% per year.

The result was asymmetric between the two firms.

In the first portfolio, the optimizer delivered an annual return of 25.3%, an excess of 12.2 percentage points over the CDI, and a Sharpe ratio of 0.65. The analyst delivered a 19.7% return, 6.6 points of excess, and a Sharpe ratio of 0.39. In the second portfolio, the result reversed: the analyst delivered a 17.3% return, 4.2 points of excess, and a Sharpe ratio of 0.22. The optimized portfolio delivered a 14.4% return, 1.3 points of excess, and a Sharpe ratio of 0.08, practically identical to the passive DIVO11, which delivered a 14.3% return and the same 0.08 Sharpe ratio over the period.

The explanation for the reversal is the mechanism that Michaud formalized in 1989: the optimizer concentrated two-thirds of the second portfolio in three assets based on what was optimal within the calibration window. In the test period, what was optimal in-sample did not hold up out-of-sample. And the detail that matters is in the decomposition: the concentrated portfolio had lower volatility than the analyst's (16.7% versus 18.9% per year). The cost of concentration was not taking on more risk. It was betting on expected returns for the wrong assets. The analyst's more uniform distribution proved more defensible precisely against this estimation error in returns, which is the core of Michaud's argument, and not against an excess of volatility that did not occur.

An earlier experiment in the series quantified this same mechanism via bootstrap: with 500 random splits and training windows of about 80 trading sessions, the optimizer's median Sharpe ratio ranged from 1.9 to 3.0 in-sample and fell to 0.16 to 0.59 out-of-sample, an average degradation of 88%. In a later round with three-year calibration windows, the degradation disappeared. Estimation error is not a binary defect in the model: it is a function of the size of the window that feeds it.

The asymmetric result invalidates any categorical claim in either direction: the optimizer does not always beat the analyst, and the analyst is not always more defensible than the model.

Adversarial Instruction Detects. Analytical Domain Expertise Validates, Prioritizes, and Corrects.

This separation was not clear before running the experiment. The initial hypothesis was that formulating the right question for the reviewer was the hard part, and that whoever did not know what look-ahead bias was would not be able to ask the reviewer to look for it. What happened was different.

The instruction given to Gemini was generic: act as a rational reviewer, identify logical inconsistencies, point out design biases, without making concessions in tone. Look-ahead bias was detected under this instruction, without my naming it in advance. The error was concrete: the first version of the experiment used the portfolios' current composition applied retroactively, as if the 2022 analysts had recommended on that date what they recommend today. Gemini pointed out that any result generated by this design would be invalid, because the optimizer would be calibrated with information that did not exist at the time of the allocation decision. The correction required going back to the firms' original PDFs and rebuilding the portfolios with the exact tickers and weights from June 2022. The same holds for the criticism of causal attribution in the conclusion, which the reviewer identified without specific instruction about this type of flaw. In both episodes, the adversarial instruction was enough for the reviewer to find the problem. Analytical domain expertise came in afterward: to understand the criticism, assess whether it was valid, and correct it precisely.

Gemini was not the only review layer. Grok and ChatGPT came in for targeted cross-checks, when a second source reduced the risk of confirmation bias between the reviewer and the model that implemented the experiment. Claude in implementation, Gemini in continuous adversarial review, the others in sample-based verification: it is this division of roles, with asymmetric and explicit instructions, that the title calls orchestration.

The most defensible thesis, then, is not that the bottleneck lies in the quality of the questions you ask the model. The bottleneck lies in two distinct phases. Adversarial instruction opens the space for error detection. Analytical domain expertise closes the space for correction. Without the first, errors tend not to surface through the reviewer. Without the second, errors surface but are not corrected, or are corrected in the wrong direction.

A caveat about the models' default behavior: the advantage of the AI reviewer over the human reviewer exists, but it is conditional on adversarial instruction. The default behavior of LLMs is to endorse what was presented, not to challenge it. Explicit adversarial instruction is what turns this default into useful criticism. Without it, the AI reviewer reproduces the same problem as a human reviewer with no autonomy to disagree.

When This Process Does Not Work

The process described has limits worth naming before replicating it.

Analytical domain expertise is a prerequisite for the correction phase, not for detection. Someone without that expertise can obtain the adversarial criticism, but cannot assess whether it is valid or apply the correct fix. The reviewer points out the problem, and the analyst does not know whether or how to correct it. The validation ecosystem is only as effective as the expertise of whoever operates it at the correction stage.

The experiment also operates with a small sample: two portfolios, one realization of the test period. It is not statistically generalizable. It is evidence of direction, not proof of a rule. A rigorous test would require multiple firms, multiple periods, and significance tests on the estimated Sharpe ratios. The standard error of a Sharpe ratio calculated over four years of data is wide enough to make most results formally inconclusive from a statistical standpoint.

The experiment carries two regime caveats that come as a pair. The test period (CDI at 13.1% per year) was structurally different from the earlier low-rate cycle, which raises the bar for any variable-risk portfolio and systematically compresses the Sharpe ratios. The calibration window (June 2019 to May 2022) contains the March 2020 crash, which makes the optimized weights strongly dependent on that period's regime. If one regime caveat applies, so does the other.

The Bottleneck Is No Longer the Tool.

And it is not just the quality of the questions.

It is the combination of adversarial instruction with analytical domain expertise: the first opens the space for error detection; the second ensures that the errors found are corrected in the right direction. Removing either one reduces the system to one of its halves, and neither half works on its own.

The code runs in minutes. The experiment with look-ahead bias runs just as fast and produces equally convincing numbers. The difference is not in execution speed. It is in having the validation process that finds the error before publication, and the expertise to know what to do when it appears.

Resources and Tools

The complete Python scripts for the experiment, including data collection via Yahoo Finance and BCB, a static IS/OOS backtest with maximum-Sharpe optimization, and historical Monte Carlo simulation, are available in the GitHub repository: https://github.com/alissondpoliveira/mvo-carteiras-dividendos-b3

A simplified Excel version, where the user enters the tickers and weights of their portfolio and receives return, volatility, and Sharpe ratio with a dynamic CDI, is available for download: https://docs.google.com/spreadsheets/d/1OVdUqc2cqz6GwP23iWI_XMNPzwv0PWsX/edit?usp=sharing&ouid=114003155137833182047&rtpof=true&sd=true

Originally published on LinkedIn on July 7, 2026, in the Financial Syntax newsletter. View on LinkedIn