Insider Trading Bot¶
This bot follows the people who know a company best: its own CEOs, CFOs, and directors. When they buy their company’s stock with their own money, the bot puts more of your account into that stock. When they sell a lot, it puts in less. This is legal insider trading: executives must report every trade to the SEC within two business days, and anyone can read those reports. Why follow them? In a study in the Journal of Finance, copying insiders’ unusual, non-routine trades earned about 0.82% a month more than the market (Cohen, Malloy and Pomorski, 2012).
How it works¶
Research agent reads the insider trade reports that executives file with the SEC for each stock on your watchlist, going back 30 days.
It keeps real open-market buys and sells and skips stock awards, gifts, option exercises, and planned sales. It reports how many dollars insiders bought and sold, and who traded.
Trading agent starts with the same amount in every watchlist stock. It adds more to stocks insiders are buying and less to stocks they are dumping.
The trading agent places the orders and checks that they filled. The bot repeats this once a day.
Change watchlist to follow any stocks you like.
Run it on BotSpot¶
Run this bot on BotSpot without installing anything. BotSpot runs LumiBot in the cloud, backtests it, and connects it to your broker.
Backtest tear sheet¶
GPT-6 Luna, January 5 to 23, 2026, Yahoo daily prices, $100,000 start. The bot bought all ten watchlist stocks and ended at $100,542 (+0.5%) while SPY was about flat. It found no open-market insider buys in that window, so it held the watchlist evenly. Cash never went below $2,168.
Open the full tear sheet. A short backtest shows the bot works as written. It is not a promise of future returns.
The code¶
The whole bot is one short file. The prompts are plain English, and they are the strategy.
"""Insider Trading Bot.
Buys more of the stocks whose CEOs and directors are buying their own company's
shares, and less of the stocks they are selling. A research agent reads the
insider trade reports executives file with the SEC. A trading agent then moves
the account toward the stocks insiders are buying.
"""
from lumibot.strategies import Strategy
class InsiderTradingBot(Strategy):
parameters = {"watchlist": ["AAPL", "MSFT", "JPM", "BAC", "XOM", "CVX", "PFE", "INTC", "F", "KO"]}
def initialize(self):
self.sleeptime = "1D"
self.agents.create(
name="researcher",
allow_trading=False,
system_prompt=(
"For each stock in the watchlist, look up the insider trades its executives reported to the "
"SEC in the last 30 days. Count only real buys and sells on the open market, not stock "
"awards, gifts, or option exercises. Report the dollars bought and sold for each stock and "
"who traded. Do not trade."
),
)
self.agents.create(
name="trader",
allow_trading=True,
system_prompt=(
"Hold every stock in the watchlist. Put more money in the stocks insiders are buying and less "
"in the stocks they are selling. Never short."
),
)
def on_trading_iteration(self):
facts = {"watchlist": self.parameters["watchlist"]}
research = self.agents["researcher"].run(task_prompt="Find this month's insider buys and sells.", context=facts)
self.agents["trader"].run(
task_prompt="Lean the account toward insider buying.", context={**facts, "research": research.summary}
)
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
if IS_BACKTESTING:
from lumibot.backtesting import YahooDataBacktesting
InsiderTradingBot.backtest(YahooDataBacktesting)
else:
InsiderTradingBot().run_live()
Run it yourself¶
pip install lumibot
python -m lumibot.example_strategies.ai_insider_trading_bot
Put these in your .env file: OPENAI_API_KEY, and your broker keys (for example ALPACA_API_KEY, ALPACA_API_SECRET, and ALPACA_IS_PAPER=true for paper trading). With IS_BACKTESTING=false the bot trades. With IS_BACKTESTING=true it backtests instead; set BACKTESTING_START and BACKTESTING_END to pick the dates, and start with a week or two, because every AI call costs a little.
Good to know¶
The SEC blocks automated web browsers, so the research agent reads the reports straight from the SEC’s data feed through LumiBot. In a backtest it only sees reports filed before each test day.
Big companies often go weeks with no insider buys on the open market. Then the bot simply holds the watchlist evenly.
See AI Trading Bot Examples for more AI trading bots and Backtest, paper, or live: choose the runner for backtest and live runs.