LLM Advisor
An autonomous trading agent that combines statistical mean reversion with LLM-based sentiment analysis for risk management.
PythonGemini APIAlpacaPandasBacktesting
USER: Analyze SPY sentiment
AGENT: Volatility high. Reducing position size.
Backtest Sharpe
2.14
📉Max Drawdown
-8.5%
Avg Trade
+0.45%
Risk Checks
Real-time
Agentic Workflow
1. Sentiment Analysis
Every 15 minutes, the system feeds headlines and market context into Gemini 1.5 Flash. The LLM outputs a "Market State" score (Bullish/Bearish/Choppy) and a suggested risk multiplier.
2. Statistical Execution
The core engine calculates Z-scores on price action. If the Z-score exceeds thedynamically adjusted threshold (set by the Agent), it executes mean reversion trades via Alpaca.
Automated Risk Manager
Safety is paramount. The system includes hard-coded circuit breakers that override AI decisions if maximum drawdown is hit.
risk_manager.py
def check_risk_parameters(current_pnl, max_drawdown_limit):
"""
Hard stop if we exceed daily loss limit.
"""
if current_pnl < -max_drawdown_limit:
logger.critical(f"Daily stop loss hit: {current_pnl}")
return {
"can_trade": False,
"action": "LIQUIDATE_ALL",
"reason": "MAX_DRAWDOWN_HIT"
}
# ... other checks (exposure, volatility) ...
return {"can_trade": True}