Skip to content
All library documents

A Multi-Agent Value Strategy for Long-Term Stock Selection

Code Lumibot

Summary

This example outlines a long-term equity selection process inspired by fundamental value investing. A research agent reviews the latest company reports and current share prices, then selects businesses based on profitability, competitive durability, and valuation. A separate skeptical reviewer challenges those picks by examining price, debt, and whether competitive advantages may be weakening. A trading agent holds the surviving names in roughly equal weights and sells a holding when the reviewer removes it.

The candidate universe is a fixed group of large, familiar US-listed companies. The strategy runs this research and review cycle daily, and the file includes both backtest and live-run entry points. It supplies no backtest results, performance evidence, data-quality checks, or rules for resolving inconsistent agent judgments. The approach therefore illustrates an agent workflow rather than demonstrating that the selection criteria or review process produce returns. Its long-term holding rule also leaves details such as portfolio limits and the treatment of cash unspecified.

Key ideas

  • A research agent screens companies for profitability, durable competitive advantages, and reasonable valuation.
  • A skeptical reviewer challenges selected companies on valuation, debt, and the strength of their business advantages.
  • A trading agent holds the surviving picks in roughly equal weights and exits names removed by the reviewer.
  • The example uses a fixed universe and repeats its review process daily.
  • No results or validation are provided to establish the strategy’s investment performance.

Tags

Full text
# ai_trading_team_warren_buffett_value.py


```py
"""Warren Buffett AI Stock Picker.

Invests the way Warren Buffett describes in his Berkshire Hathaway letters: buy
great businesses at fair prices and hold them. A research agent reads each
company's reports and picks the best mix of quality and price. A skeptic agent,
like Charlie Munger, attacks each pick. A trading agent owns what survives.
Not affiliated with or endorsed by Warren Buffett or Berkshire Hathaway.
"""

from lumibot.strategies import Strategy


class AITradingTeamWarrenBuffettValueStrategy(Strategy):
    parameters = {"universe": ["AAPL", "MSFT", "GOOGL", "COST", "V", "MA", "KO", "AXP", "JPM", "PG"]}

    def initialize(self):
        self.sleeptime = "1D"
        self.agents.create(
            name="researcher",
            allow_trading=False,
            system_prompt=(
                "Read each company's latest financial reports and check its stock price today. Pick the 3 to "
                "5 companies with the best mix of steady profits, a lasting edge over rivals, and a fair "
                "price. Do not trade."
            ),
        )
        self.agents.create(
            name="skeptic",
            allow_trading=False,
            system_prompt=(
                "You are a skeptic like Charlie Munger. Attack each pick: is the price too high, is the edge "
                "shrinking, is there too much debt? Keep only the picks that survive. Do not trade."
            ),
        )
        self.agents.create(
            name="trader",
            allow_trading=True,
            system_prompt=(
                "Own the picks the skeptic kept, split about evenly. Hold for the long run and ignore small "
                "price moves. Sell a stock only when the skeptic drops it."
            ),
        )

    def on_trading_iteration(self):
        facts = {"universe": self.parameters["universe"]}
        research = self.agents["researcher"].run(task_prompt="Pick the best companies.", context=facts)
        review = self.agents["skeptic"].run(
            task_prompt="Attack each pick.", context={**facts, "research": research.summary}
        )
        self.agents["trader"].run(
            task_prompt="Own the picks that survived.", context={**facts, "skeptic": review.summary}
        )


if __name__ == "__main__":
    from lumibot.credentials import IS_BACKTESTING

    if IS_BACKTESTING:
        from lumibot.backtesting import YahooDataBacktesting

        AITradingTeamWarrenBuffettValueStrategy.backtest(YahooDataBacktesting)
    else:
        AITradingTeamWarrenBuffettValueStrategy().run_live()

```

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.