Skip to content
All library documents

Multi-Agent Debate for Leveraged ETF Directional Trading

Code Lumibot

Summary

This code outlines a daily trading workflow in which separate AI agents research a universe of leveraged exchange-traded funds, argue bullish and bearish cases, and pass their summaries to a trading judge. The universe includes leveraged long and inverse products tied to several indexes and sectors. The researcher ranks funds using recent prices and trends, while the bull and bear agents are instructed to make opposing assessments without placing trades. The trader agent then decides how to rebalance the account.

A key portfolio constraint is to avoid holding a leveraged fund and its inverse for the same index at once; the instructions say to sell the existing side before switching. The script includes paths for both Yahoo-based backtesting and live execution, but it provides no explicit ranking formula, agent evaluation method, allocation limits, leverage controls, transaction-cost model, or performance results. Since the trading decision depends on agent-generated analysis, reproducibility and risk control are unclear from the code. The example therefore illustrates an orchestration pattern, not a validated trading edge.

Key ideas

  • A research agent ranks a configured universe of leveraged ETFs using recent prices and trends.
  • Bullish and bearish agents produce opposing assessments for a separate trading agent to consider.
  • The trading agent is instructed to hold only one directional ETF for each index and sell before switching sides.
  • The strategy runs on a daily schedule and includes backtesting and live execution entry points.
  • The code does not specify allocation rules, leverage limits, or evidence of strategy performance.

Tags

Full text
# ai_trading_team_bull_bear_leveraged_etf.py


```py
"""TQQQ Strategy AI Trading Bot.

A bull AI and a bear AI debate the market, then the bot picks leveraged ETFs like
TQQQ (3x the Nasdaq-100 up) or SQQQ (3x down). A research agent ranks the ETFs,
the bull and bear agents argue at the same time, and a judge agent trades,
holding only one side of each index.
"""

from lumibot.strategies import Strategy


class AITradingTeamBullBearLeveragedETFStrategy(Strategy):
    parameters = {
        "universe": ["TQQQ", "SQQQ", "UPRO", "SPXU", "UDOW", "SDOW", "TNA", "TZA", "SOXL", "SOXS", "TMF", "TMV"]
    }

    def initialize(self):
        self.sleeptime = "1D"
        self.agents.create(
            name="researcher",
            allow_trading=False,
            system_prompt=("Rank the ETFs in the universe from recent prices and trends. Do not trade."),
        )
        self.agents.create(
            name="bull",
            allow_trading=False,
            system_prompt=("Argue for the ETFs most likely to rise. Do not trade."),
        )
        self.agents.create(
            name="bear",
            allow_trading=False,
            system_prompt=("Argue the biggest risks in each ETF. Do not trade."),
        )
        self.agents.create(
            name="trader",
            allow_trading=True,
            system_prompt=(
                "You are the judge. Weigh the bull and bear cases and split the account across the winning "
                "ETFs. Never hold an ETF and its opposite on the same index, like TQQQ and SQQQ. Sell the old "
                "side before you switch."
            ),
        )

    def on_trading_iteration(self):
        facts = {"universe": self.parameters["universe"]}
        research = self.agents["researcher"].run(task_prompt="Rank the ETFs.", 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

        AITradingTeamBullBearLeveragedETFStrategy.backtest(YahooDataBacktesting)
    else:
        AITradingTeamBullBearLeveragedETFStrategy().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.