Debate-Based AI Stock Selection for Large-Cap Equities
Summary
This strategy uses a four-agent workflow to select among a fixed universe of large US stocks. A research agent ranks the stocks using recent prices, trends, and news. Bull and bear agents then independently argue for and against the candidates, and a trading agent acts as judge, allocating the account to winners and selling stocks that lose the debate. The research and debate agents cannot trade; only the judge can place trades.
The code runs this process once per daily trading iteration and includes paths for both Yahoo data backtesting and live operation. It provides an architecture and example prompts, but no performance results or rules for measuring the quality of the agents’ analysis. The allocation method, risk controls, and handling of uncertain or conflicting information are left unspecified. Because decisions rely on agent summaries of recent information, the example does not establish that the system has predictive value or guards against unreliable inputs.
Key ideas
- A research agent ranks a predefined universe of large US stocks using recent prices, trends, and news.
- Bull and bear agents independently assess each stock before trading decisions are made.
- A separate judge agent chooses debate winners, allocates the account among them, and sells losing positions.
- The example supports daily iterations and provides backtesting and live-running entry points, but reports no strategy performance.
Tags
Full text
# ai_trading_team_bull_bear_large_cap_stocks.py
```py
"""Bull vs Bear AI Stock Trading Bot.
Two AI agents argue about the biggest US stocks before any money moves. A
research agent ranks the stocks. A bull agent makes the case for buying and a
bear agent makes the case against, at the same time. A judge agent weighs both
sides and splits the account across the stocks that win the debate.
"""
from lumibot.strategies import Strategy
class AITradingTeamBullBearLargeCapStocksStrategy(Strategy):
parameters = {
"universe": ["AAPL", "MSFT", "NVDA", "AMZN", "META", "GOOGL", "TSLA", "AVGO", "COST", "JPM", "V", "LLY", "XOM"]
}
def initialize(self):
self.sleeptime = "1D"
self.agents.create(
name="researcher",
allow_trading=False,
system_prompt=("Rank the stocks in the universe from recent prices, trends, and news. Do not trade."),
)
self.agents.create(
name="bull",
allow_trading=False,
system_prompt=("Argue for buying the strongest stocks. Do not trade."),
)
self.agents.create(
name="bear",
allow_trading=False,
system_prompt=("Argue the biggest risks in each stock. Do not trade."),
)
self.agents.create(
name="trader",
allow_trading=True,
system_prompt=(
"You are the judge. Weigh the bull and bear cases, pick the stocks that win the debate, and "
"split the account across them. Sell the stocks that lose."
),
)
def on_trading_iteration(self):
facts = {"universe": self.parameters["universe"]}
research = self.agents["researcher"].run(task_prompt="Rank the stocks.", context=facts)
facts = {**facts, "research": research.summary}
debate = self.agents.run_together(
[("bull", "Make the bull case.", facts), ("bear", "Make the bear case.", facts)]
)
self.agents["trader"].run(
task_prompt="Judge the debate and rebalance.",
context={**facts, "bull": debate["bull"].summary, "bear": debate["bear"].summary},
)
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
if IS_BACKTESTING:
from lumibot.backtesting import YahooDataBacktesting
AITradingTeamBullBearLargeCapStocksStrategy.backtest(YahooDataBacktesting)
else:
AITradingTeamBullBearLargeCapStocksStrategy().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.