All posts

Building an AI Stock Agent That Reads My Portfolio and Debates the Next Market Session

When you own stocks, your thoughts do not stop just because the market has closed.

When you own stocks, your thoughts do not stop just because the market has closed.

Was today's decline just a pullback, or a sign that the trend has broken? Why did the stock fall after the company reported good earnings? Should I add to my position now, or simply wait? Do the reactions in the news and online communities actually mean anything?

The problem was that answering these questions required jumping between too many screens. I had to check my position size in my brokerage app, open a chart to inspect technical indicators, search the news, and then review market indices and community sentiment. Even after collecting all of that information, my final judgment was still easily influenced by my mood and whatever I happened to remember that day.

So I started building a personal stock-research agent. It gathers evidence for stocks I actually own, asks AI experts with different perspectives to form their own opinions, and organizes possible actions for the next trading day.

Rather than explaining the code line by line, this build log focuses on three questions:

  • What happens behind the scenes when I press the Analyze button?
  • Why did I create several AI experts instead of one?
  • Why should today's judgment be saved until the next day?

I did not want a simple up-or-down prediction

At first, it seemed enough to give an AI a ticker and a recent chart and ask, “Will it go up tomorrow?” But a number such as 60% probability of an increase is not enough to make an actual decision.

What I wanted was the context behind the number.

What if the chart points upward while the broader market has entered a risk-off regime?

What if the company's long-term outlook is strong, but short-term expectations are overheated? Is now still a good time to enter?

If I already own the stock, should the conclusion be the same as it would be for a new position?

I therefore defined the system not as “a model that predicts stock prices,” but as a research tool that gathers different forms of evidence, compares conflicting perspectives, and organizes them into a form that helps a person make a judgment.

What happens when I press Analyze?

stock-agent-architecture-overview

The overall flow has three main stages.

1. Gather evidence from my account and the market

The system first reads my current holdings and their market values from my Toss account. The connection is read-only; the system never places orders itself.

Once the stock to analyze has been selected, the agent gathers price and volume data, company information, news, social reactions, and broader market conditions.

  • Toss Account: Confirms whether I actually own the stock and how large the position is.
  • Yahoo Finance: Provides recent prices, volume, company growth metrics, and valuation data.
  • Finnhub News: Collects recent company news and potential catalysts.
  • Social Media: Reviews investor reactions on services such as Stocktwits and Reddit.
  • Market & Risk: Evaluates market risk appetite using SPY and QQQ alongside Bitcoin and Ethereum trends.

The news step does more than count headlines. When possible, the system visits an article and reads part of its body. Some paid or blocked pages are inaccessible, of course. When that happens, the result records that collection failed instead of pretending the full article was reviewed.

Information from these sources is consolidated into a research packet. Sources, links, and publication times are preserved so I can later see which evidence contributed to a judgment.

2. Five AI experts read the same material differently

Instead of giving everything to one AI, I divided the analysis into five roles.

  • The technical analyst examines trends, momentum, volatility, support, and resistance.
  • The fundamental analyst examines growth, profitability, valuation, and company catalysts.
  • The sentiment analyst looks for expectations, fear, and overheating in news articles and social reactions.
  • The market analyst focuses on broader market risk appetite and sector trends rather than the individual stock alone.
  • The risk manager looks for portfolio concentration, high volatility, missing data, and scenarios that contradict the prevailing view.

I separated these roles to reduce confirmation bias. Strong earnings may look like compelling bullish evidence to the fundamental analyst, while the risk manager may argue that expectations are already priced in or that volatility has become excessive.

Each expert provides more than a conclusion. They also state the evidence supporting it, the evidence against it, and the conditions under which they would admit that their conclusion was wrong.

The current coordinator compares these views and chooses a bullish or bearish direction only when one side is sufficiently stronger. When opinions are evenly divided, it remains neutral instead of forcing a conclusion. The system does not yet implement a full multi-round debate in which experts read and rebut one another. For now, it is closer to an independent expert panel followed by a conservative synthesis.

3. Translate a prediction into the language of action

A user needs more than the word bearish. In the final stage, the system combines the outlook with whether I already hold the stock and translates it into an action to review for the next trading day.

  • Strong bullish evidence for a stock I do not own becomes WATCH FOR ENTRY.
  • Strong bullish evidence for a stock I own becomes HOLD / ADD REVIEW.
  • Strong bearish evidence for a stock I do not own becomes AVOID NEW BUY.
  • Strong bearish evidence for a stock I own becomes HOLD DEFENSIVELY or SELL / STOP REVIEW.
  • An ambiguous judgment becomes WATCH or HOLD.

These labels do not trigger automatic orders. They are starting points for a person to review after checking new pre-market news and index movements.

One screen for the result, a separate report for the evidence

Because this is a tool I use daily, I built a React dashboard that shows the analysis flow in a browser.

stock-agent-dashboard-demo

From the dashboard, I can select one of my current holdings or search for another stock and start an analysis. The interface shows how far the process has progressed through the account, market, news, social, and expert-analysis stages.

When the run is complete, it displays the final direction, suggested action, technical summary, each expert's opinion, and previous judgments. For a quick check, the dashboard is enough.

But a short summary is not enough when I am considering a buy or sell. Each run therefore generates a separate Markdown report as well.

stock-agent-markdown-report

The report contains:

  • A Korean-language summary of the core conclusion and checklist
  • Bullish and bearish evidence from technical analysis
  • Company growth and valuation
  • The market's current risk appetite
  • Each expert's argument, counterevidence, and invalidation conditions
  • Links to the news and social posts used in the judgment

The dashboard is a place to understand the current state quickly. The Markdown report is a place to review the reasoning slowly.

Why saving judgment history is the core feature

The feature I consider most important in this project is not the prediction itself, but Judgment History.

If the AI is bullish today and the stock falls tomorrow, I do not want to shrug and say, “It was wrong this time.” I want to be able to reconstruct the situation: what news was available, how the technical and market analyses conflicted, and whether a risk warning was ignored.

stock-agent-feedback-loop

Analysis results are stored in a local SQLite database. When the next trading day's data becomes available, the system compares the actual closing-price direction with the prediction and records it as correct, incorrect, or neutral. I can then reopen the experts' opinions and evidence for that run.

As the history grows, it becomes possible to answer questions such as:

  • Does the system perform well in bull markets but fail repeatedly in risk-off markets?
  • Is it consistently too optimistic about a particular stock or sector?
  • Does it overvalue news sentiment?
  • Are high-confidence judgments actually more accurate?

In the end, I think a good agent is not a system that produces one impressive answer. It is a system that remembers its judgments and can use them to improve the next one.

Finding candidates beyond my current holdings

The first version analyzed only stocks already in my account. After using it for a while, another question emerged naturally: “Which stocks have been pushed down heavily in the current market but may have room to rebound?”

I added two features in response.

The first is ticker search. I can search by company name or ticker and run the same analysis on a stock I do not own.

The second is Market Scout. It scans semiconductors, IT and software, and biotech and healthcare. It reviews recent drawdowns, momentum, company information, and news, then groups stocks into pullback rebound candidates, watch candidates, and low priority.

Market Scout is not an order recommendation either. It is a filter that narrows the set of candidates worth researching. After finding an interesting candidate, I run the expert analysis to inspect the evidence in more detail. Scan results are stored by date, allowing me to compare what happened to those candidates later.

Three choices that mattered while building it

Separate calculation from interpretation

Values with fixed formulas, such as RSI, MACD, moving averages, and volatility, are calculated in regular code. The AI interprets those calculated values. This makes the same data produce the same indicators and reduces the chance that the AI invents plausible-looking numbers.

Keep the analysis running when an AI component fails

A news API may fail, or a local AI may return an invalid format. The system does not discard the entire analysis because one source failed. It continues with the information that remains available and records a warning explaining what is missing.

This is also why I made it possible to choose between a fast rule-based analysis and local Codex or Hermes analysis modes. Depending on the situation, I can trade off speed, depth, and reliability.

Deliberately omit order execution

The system reads my real account, but it does not place orders. I believe a good tool should stop at helping the user make a judgment. For a problem as uncertain as next-day market direction, eliminating the final approval step would not be automation; it would be an amplification of risk.

What remains unsolved

This agent does not predict the market with certainty. It is closer to a tool that helps me review several incomplete sources in a more consistent way.

Free price and news data can be delayed or incomplete, and some article bodies cannot be accessed. Social media contains useful information and noise at the same time. Prices may also disagree when the brokerage account and market-data source use different reference times.

The expert debate has plenty of room to evolve. In the next version, I want the bullish and bearish sides to rebut one another's key evidence directly and then have each expert adjust their confidence after reading those rebuttals.

Once enough judgment history has accumulated, I also want to build a retrospective dashboard showing not only simple accuracy but performance by market regime and confidence calibration. The important question is not “Did the AI sound confident?” but “Were its confident judgments actually more accurate?”

Closing thoughts

When I started this project, I imagined an AI that would find stocks likely to rise the next day. While building it, I came to believe that the judgment process mattered more than the prediction.

The system should preserve which information it examined, why different experts disagreed, which risks it missed, and what actually happened the next day. That is how one plausible-sounding answer becomes a repeatable investment-research process.

The current Stock Research Agent is not a finished investment system. But it has turned a daily process that depended on scattered screens and intuition into one flow: collect, compare, record, and review.

For me, that change has been far more meaningful than a simple stock-price prediction.

This article and system are personal research records, not investment advice. All trading decisions and responsibility remain with the user.

END
Discussion

Share your thoughts on this article.

Sign in with GitHub to leave a comment or reaction.