Diamonds in the Rough AI Turnaround Bot¶
Most stock screeners lock you into a fixed watchlist of twenty tickers. This open-ended AI turnaround bot searches across the entire US equity market with zero hardcoded symbols, looking for beaten-down public companies that have a real catalyst and early rebound momentum, then builds a diversified five to ten stock portfolio capped at twenty percent per holding.
How it works¶
The strategy pairs a dedicated research agent with a dedicated trading agent on a daily schedule:
Research agent scans across the broad US stock market for companies that have dropped sharply from their 52-week highs and are beginning to recover. It checks recent SEC filings, income statements, balance sheets, earnings news, and insider or institutional activity to separate real turnaround stories from distressed companies, returning five to ten diversified picks across sectors with no stock above a 20% target weight plus clear exit triggers.
Trading agent builds and rebalances the portfolio inside available cash, deploying roughly 95% of equity across the approved turnaround picks (capped at 20% per ticker, leaving about a 5% cash buffer). It sells holdings whose thesis fails or whose exit trigger hits before buying replacements, skips tiny trades within 2 percentage points of target weight, and never shorts.
Want a more concentrated basket or a different holding cap? Adjust max_positions in parameters or edit the prompt directly.
Run it on BotSpot¶
Browse ready-to-run AI strategies or deploy this bot in the cloud on BotSpot Marketplace. BotSpot runs LumiBot in the cloud, manages historical backtests, and connects directly to your broker.
Prefer to customize this strategy inside Claude, ChatGPT, Codex, or Cursor? Connect the free BotSpot MCP to edit code, run cloud backtests, and inspect charts from your AI assistant. Want guided step-by-step training on building AI trading systems? Explore BotSpot Courses or join the free AI Trading Challenge.
The code¶
The complete strategy lives in one short Python file with zero hardcoded ticker lists. The plain-English prompts define the research criteria and portfolio limits.
"""Diamonds in the Rough (AI Turnaround Strategy).
Open-ended AI turnaround discovery across the entire US stock market with zero
hardcoded tickers. A research agent scans the public US equity universe for
beaten-down businesses with fresh turnaround catalysts and early rebound
momentum, and a trading agent builds a diversified 5 to 10 stock portfolio
capped at 20% per position.
"""
from lumibot.strategies import Strategy
class DiamondsInTheRoughStrategy(Strategy):
parameters = {
"model": "openai/gpt-6-luna",
"max_positions": 10,
}
def initialize(self):
self.sleeptime = "1D"
model = self.parameters["model"]
self.agents.create(
name="researcher",
model=model,
allow_trading=False,
allow_network=True,
system_prompt=(
"Search across the entire US stock market for beaten-down public companies that "
"have fallen sharply from their 52-week highs and are now showing a real turnaround "
"catalyst and early upward momentum. Do not limit yourself to a fixed watchlist. "
"Review recent SEC filings, income statements, balance sheets, earnings news, and "
"any insider, institutional, or politician buying to separate genuine comebacks "
"(intact business, improving revenue or margins, solid balance sheet, real catalyst) "
"from distressed falling knives. Recommend 5 to 10 genuinely diversified US "
"turnaround stocks spread across multiple sectors, with no single stock above a "
"20% target weight, plus clear exit triggers for each pick and any current "
"holdings. Use only information available by today. Do not trade."
),
)
self.agents.create(
name="trader",
model=model,
allow_trading=True,
system_prompt=(
"Build and manage a diversified portfolio of 5 to 10 turnaround stocks from the "
"research report, capped at max_positions total holdings. Deploy about 95% of "
"account equity across the approved picks with at most 20% in any single stock, "
"leaving about a 5% cash buffer. Size orders from current market prices, sell "
"positions whose catalyst fails or exit trigger hits before buying replacements, "
"leave holdings alone when within 2 percentage points of target weight, never "
"short, and never spend more cash than available."
),
)
def on_trading_iteration(self):
research = self.agents["researcher"].run(
task_prompt=(
"Discover the best US stock turnaround candidates across the market today and "
"review any current holdings."
),
context={
"previous_notes": self.vars.get("last_notes", "none yet"),
"max_positions": self.parameters["max_positions"],
},
)
self.vars.set("last_notes", research.summary)
self.agents["trader"].run(
task_prompt="Rebalance the turnaround portfolio based on the research report.",
context={
"research": research.summary,
"max_positions": self.parameters["max_positions"],
},
)
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
if IS_BACKTESTING:
from lumibot.backtesting import YahooDataBacktesting
DiamondsInTheRoughStrategy.backtest(YahooDataBacktesting)
else:
DiamondsInTheRoughStrategy().run_live()
Run it yourself¶
pip install lumibot
python -m lumibot.example_strategies.ai_diamonds_in_the_rough
Add OPENAI_API_KEY and your broker credentials (for example ALPACA_API_KEY, ALPACA_API_SECRET, and ALPACA_IS_PAPER=true for paper trading) to your .env file. For ChatGPT subscription funding locally, see Use your ChatGPT subscription and set model to chatgpt/gpt-6-luna.
With IS_BACKTESTING=true, the file runs a historical backtest on Yahoo Finance daily data using BACKTESTING_START and BACKTESTING_END. With IS_BACKTESTING=false, the exact same strategy class trades with your configured broker.
Good to know¶
Open-ended market discovery lets the researcher find fresh turnaround candidates outside any preset list, but you should start with a short backtest window (one to two weeks) first to inspect decisions and measure model token costs.
Turnaround stocks can stay volatile or fall further after an initial bounce; the 20% single-stock cap and five to ten stock diversification rule limit single-company exposure.
In backtests, LumiBot clamps built-in market data and SEC filings to the simulated date, and the research agent is instructed to use only information available by that day.
Historical backtests verify strategy mechanics and accounting; they are not a guarantee of future returns.
See AI Trading Bot Examples for more AI trading bots and Backtest, paper, or live: choose the runner for backtest and live runners.