Add stock market example with LLM trader and analyst agents - #281
Add stock market example with LLM trader and analyst agents#281hussanshabbir wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
for more information, see https://pre-commit.ci
sadrasabouri
left a comment
There was a problem hiding this comment.
Hey @hussanshabbir, thanks for contributing to mesa-llm. I tried your example, and I think it fits well into mesa-llm examples. I reviewed your PR as an external reviewer to make it ready for maintainers' review.
In addition to the few comments I left, I highly encourage you to add a README.md in which you explain more about the examples (similar to other projects).
| observation = self.generate_obs() | ||
| history = get_trading_history(self) | ||
| price = self.model.current_price | ||
| prompt = ( | ||
| f"MARKET DATA:\n" | ||
| f"- Price: ${price:.2f}\n" | ||
| f"- Trend: {self.model.price_trend()}\n" | ||
| f"- RSI: {self.model.rsi():.1f} (>70 overbought, <30 oversold)\n" | ||
| f"- Budget: ${self.budget:.2f} | Shares: {self.shares}\n\n" | ||
| f"RECENT ACTIVITY:\n{history}\n\n" | ||
| "Use execute_trade to BUY, SELL, or HOLD. Justify briefly." | ||
| ) |
There was a problem hiding this comment.
nit: put the common part of step and astep into a seprate function.
| n=n_conservative, | ||
| reasoning=reasoning, | ||
| llm_model=llm_model, | ||
| system_prompt="You are a conservative trader. Only buy when RSI is below 35 and trend is rising. Sell quickly if you sense risk. Protect capital above all else.", |
There was a problem hiding this comment.
I'd say don't fixate on an LLM on a number and let it decide by itself what a critical value is as a "conservative trader."
This PR adds a stock market simulation example to mesa-llm, demonstrating
LLM-powered agents reasoning over quantitative financial data.
TraderAgent — uses ReAct reasoning to decide BUY/SELL/HOLD based on
live price, RSI, and trend data. Two archetypes: conservative and aggressive.
AnalystAgent— reads market indicators and broadcasts signals to nearby
traders via speak_to.
execute_trade tool — handles buy/sell/hold logic with budget and share tracking.
StockMarketModel — simulates price movement with random walk + mean
reversion, computes RSI and volatility, collects data via DataCollector.
Solara visualization — color-coded agents (green = profitable, red = loss).
Testing
Follows the same structure as the negotiation example. Compatible with any
LiteLLM provider (OpenAI, Anthropic, Ollama).
@colinfrisch @jackiekazil happy to adjust anything based on your feedback!