A newer version of the Gradio SDK is available: 6.20.0
title: LIVE Recommendation Trading AgentandStorestrategy
emoji: π
colorFrom: yellow
colorTo: pink
sdk: gradio
sdk_version: 6.18.0
python_version: '3.13'
app_file: app.py
pinned: false
short_description: 'Fully analytical assistant deploying localized LLM '
demo: https://youtu.be/v7obaRRzNnU
post: https://twitter.com/LaxmiTiwari_/status/2066588475567251682
tags:
- track:backyard
- achievement:offgrid
- achievement:welltuned
- achievement:offbrand
- achievement:llama
- achievement:sharing
- achievement:fieldnotes
π€ AI Trading Agent
An end-to-end quantitative trading research platform that combines Local Large Language Models (LLMs), Retrieval-Augmented Generation (RAG), and automated backtesting to streamline strategy development and market analysis. Most Useful for Individual Trader, it is safe, secure and Local app.
π Overview
The AI Trading Agent enables traders, researchers, and quantitative analysts to seamlessly transition from natural language ideas to backtested trading strategies. By anchoring a local LLM with a specialized trading knowledge base, the system ensures highly relevant code generation and data-driven market insights.
Key Capabilities
- Natural Language to Code: Generate executable trading strategies from plain text.
- Knowledge Management: Store, index, and retrieve trading strategies and research.
- Live Market Analysis: Run real-time technical analysis on popular assets.
- Automated Backtesting: Instantly validate generated strategies using historical data.
- Persistent Strategy Memory: Build an incremental, searchable database of quantitative knowledge.
β¨ Features
π€ AI-Powered Strategy Generation
Generate production-ready Backtrader strategies from natural language descriptions.
- Workflow Example: βGenerate an RSI mean reversion strategyβ
- Under the Hood: The system queries FAISS memory β Retrieves the closest matching strategy template β Passes context to the Gemma LLM β Generates clean Backtrader Python code β Executes an automated backtest β Returns code, performance metrics, and logs.
π§ Retrieval-Augmented Strategy Memory
Strategies are vectorized and stored inside a high-performance FAISS database.
- Capabilities: Semantic search, code reuse, knowledge persistence, and sub-millisecond retrieval.
π Live Market Recommendation Engine
Provides real-time technical analysis and actionable trading recommendations based on:
- Trend & Momentum Analysis
- Support & Resistance Detection
- Volatility & Volume Profiles
| Asset Category | Supported Tickers |
|---|---|
| Equities | AAPL, TSLA, MSFT, GOOG, AMZN, NVDA |
| Crypto | BTC-USD, ETH-USD |
Example Output:
- Recommendation: BUY (Confidence: 87%)
- Reasoning: Strong macro uptrend, positive short-term momentum, and healthy volume expansion on breakouts.
π₯ Strategy Knowledge Ingestion
Populate your vector database by importing quantitative data from multiple sources:
- Web URLs & Manual Text Input
- PDF, Markdown, and Text files
- Processing Pipeline: Extracts raw trading logic β Detects indicators β Generates structural embeddings β Stores vectors in FAISS.
π Indicator Validation Layer
To maintain data integrity, an automated guardrail scans ingested documents. Files must contain references to at least one supported indicator, or they are rejected:
RSI|SMA|EMA|MACD|Bollinger Bands|Stochastic|ADX|Volume
ποΈ System Architecture
ββββββββββββββββββββββ
β User Query/Input β
ββββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββββ
β FAISS Retrieval β
ββββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Gemma LLM β
ββββββββββββ¬ββββββββββ
β
βββββββββββββββββββββ΄ββββββββββββββββββββ
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Code Generation β β Market Analysis β
βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Backtrader β
β Sandbox Engine β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Results & Logs β
βββββββββββββββββββ
Technology Stack
AI & Retrieval Layer
LLM: Gemma GGUF (gemma-2-2b-it-Q4_K_M.gguf) via llama.cpp
Embeddings: Sentence Transformers (all-MiniLM-L6-v2)
Vector Database: FAISS (using L2 Distance similarity search)
Quantitative Layer
Market Data: Yahoo Finance API (yfinance)
Backtesting Engine: Backtrader
Data Analysis: Pandas & NumPy
UI & Deployment
Interface: Gradio
Deployment Target: Hugging Face Spaces / Local host
π Project Structure
AI-Trading-Agent/
β
βββ app.py # Main Gradio application entrypoint
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
β
βββ data/ # Local vector storage and ingested documents (still not)
βββ logs/ # Backtest execution logs and system errors
βββ model/ # Downloaded LLM weights (.gguf)
Getting Started
1. Model Setup
The system utilizes a quantized Gemma-2B model. Download and initialize it using the code snippet below:
from huggingface_hub import hf_hub_download
from llama_cpp import Llama
# Download model from Hugging Face
MODEL_PATH = hf_hub_download(
repo_id="bartowski/gemma-2-2b-it-GGUF",
filename="gemma-2-2b-it-Q4_K_M.gguf"
)
# Initialize local inference engine
llm = Llama(
model_path=MODEL_PATH,
n_ctx=8192,
n_threads=4,
n_gpu_layers=-1 # Set to -1 to offload all layers to GPU
)
2. Installation
Clone the repository and install the required environment dependencies:
# Clone the repository
git clone [https://github.com/yourusername/AI-Trading-Agent.git](https://github.com/yourusername/AI-Trading-Agent.git)
cd AI-Trading-Agent
# Install dependencies
pip install -r requirements.txt
# Run the UI locally
python app.py
Application Modules
π» Code Engine Studio: Natural language interface to generate, tweak, and instantly backtest Python trading code.
π¬ Live Recommendation: Real-time dashboard parsing market feeds for high-probability setups.
π₯ Strategy Encoding & Retrieval: Drag-and-drop workspace to ingest custom research documents into vector memory.
ποΈ Strategy Database: Administrative view to browse, inspect, and delete keys from your stored vector collections.
π Future Roadmap
[ ] Portfolio Optimization: Markowitz efficient frontier and Black-Litterman integration.
[ ] Pine Script Generation: Support for TradingView script synthesis.
[ ] Reinforcement Learning: Gymnasium-based market agents.
[ ] Multi-Agent Systems: CrewAI/Autogen setups for distinct Analyst vs. Risk Manager roles.
[ ] Production DB: Upgrade FAISS to PostgreSQL (pgvector) for persistent multi-user scaling.
[ ] Live Execution: Execution layer integration via Interactive Brokers or Alpaca APIs.
β οΈ Disclaimer
This project is intended strictly for educational and research purposes. Trading financial instruments involves significant risk
of capital loss. The authors do not guarantee the accuracy of generated code or market recommendations. Always perform thorough
independent verification and paper trading before risking real capital.
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference