Skip to content

Commit ed3ce82

Browse files
authored
Merge pull request #4 from OnePunchMonk/maybe-1
Maybe 1
2 parents 9d16c9a + 8ebc2ef commit ed3ce82

34 files changed

Lines changed: 1229 additions & 1896 deletions

.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# Replace 'your-gemini-api-key-here' with your actual Google Gemini API key
33
# Get your free API key from: https://makersuite.google.com/app/apikey
44

5-
GOOGLE_API_KEY=your-gemini-api-key-here
5+
GOOGLE_API_KEY='you api key'
66

77
# Optional: Set to True to enable debug logging
88
DEBUG=False
99

10+
FRED_API_KEY="your api key"
11+
1012
# Optional: Maximum iterations for strategy optimization (default: 3)
1113
MAX_OPTIMIZATION_ITERATIONS=3
1214

1315
# Optional: Default stock symbol for testing
14-
DEFAULT_STOCK_SYMBOL=AAPL
16+
DEFAULT_STOCK_SYMBOL=AAPL

.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
.env
22
__pycache__/
33
*.pyc
4-
.ipynb_checkpoints/
4+
.DS_Store
55
.vscode/
6-
data_store/
7-
figures/
8-
results_plots/
9-
docs/PAPER_DRAFT.md
10-
docs/EXPERIMENTAL_DETAILS.md
11-
experiments/*.csv

DESIGN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ flowchart TB
2929
ORCHESTRATOR[🤖 Agent Orchestrator<br/>LangGraph StateGraph]
3030
3131
%% Core Agent Components
32-
PLANNER[🧠 Planning Agent<br/>LangChain + Gemini Pro]
32+
PLANNER[🧠 Planning Agent<br/>LangChain + Gemini 2.5 Flash]
3333
EXECUTOR[⚡ Execution Agent<br/>Strategy Implementation]
3434
ANALYZER[📊 Analysis Agent<br/>Performance Evaluation]
3535
@@ -434,7 +434,7 @@ data:
434434

435435
# Agent Configuration
436436
agent:
437-
model: "gemini-pro"
437+
model: "gemini-2.5-flash"
438438
temperature: 0.1
439439
max_strategies: 10
440440
optimization_method: "bayesian"

README.md

Lines changed: 100 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,93 @@
1-
# AgentQuant (Prototype)
1+
# AgentQuant: Autonomous Quantitative Research Agent
22

3-
**A modular Python framework for quantitative strategy research and backtesting.**
3+
**A fully autonomous AI agent that researches, generates, and validates trading strategies.**
44

5-
> **⚠️ Note:** This project is currently a **structural prototype**. The "AI Agent" logic is currently simulated using stochastic (random) generation to demonstrate the workflow. The actual LLM integration (LangChain/Gemini) requires uncommenting and API setup.
5+
> **🚀 Update (Nov 2025):** Now powered by **Google Gemini 2.5 Flash**. The agent is fully functional and no longer uses random simulation. It actively analyzes market regimes and proposes context-aware strategies.
66
77
## 🎯 What This Project Is
88

9-
AgentQuant is a structured codebase designed to automate the lifecycle of a trading strategy. It handles:
10-
11-
1. **Data Ingestion:** Fetching market data (OHLCV).
12-
2. **Feature Engineering:** Calculating indicators (Momentum, Volatility, SMA).
13-
3. **Regime Detection:** Classifying market states (e.g., "Bear", "Bull") using heuristic rules.
14-
4. **Backtesting:** Running strategies against historical data.
15-
16-
It is designed as a **foundation** for developers who want to build an AI-driven trading bot but need the messy boilerplate (data handling, pipeline architecture) handled first.
17-
18-
## ⚙️ How It Works (The Honest View)
19-
20-
### 1. The "Brain" (`src/agent`)
21-
* **Current State:** The strategy planner currently uses **randomized parameter search** to simulate an AI proposing strategies.
22-
* **Future Goal:** To enable the actual AI, you must uncomment the LangChain imports in `langchain_planner.py` and provide a Google Gemini API key.
23-
* **Why?** This allows the application to run and demo the UI without requiring expensive API credits during development.
24-
25-
### 2. Market Regime (`src/features/regime.py`)
26-
* Uses hardcoded logic based on VIX levels and Momentum to classify the market into states like:
27-
* `Crisis-Bear` (VIX > 30, Negative Momentum)
28-
* `MidVol-Bull` (VIX 20-30, Positive Momentum)
29-
* `LowVol-MeanRevert` (VIX < 20, Flat Momentum)
30-
31-
### 3. Backtesting (`src/backtest`)
32-
* Includes a fast, vectorized backtester (`simple_backtest.py`) capable of testing Momentum and Mean Reversion logic.
33-
* Calculates Sharpe Ratio, Max Drawdown, and Total Return.
9+
AgentQuant is an AI-powered research platform that automates the quantitative workflow. It replaces the manual work of a junior quant researcher:
10+
11+
1. **Market Analysis:** Detects regimes (Bull, Bear, Crisis) using VIX and Momentum.
12+
2. **Strategy Generation:** Uses **Gemini 2.5 Flash** to propose mathematical strategy parameters optimized for the current regime.
13+
3. **Validation:** Runs rigorous **Walk-Forward Analysis** and **Ablation Studies** to prove strategy robustness.
14+
4. **Backtesting:** Executes vectorized backtests to verify performance.
15+
16+
## 🏗️ System Architecture
17+
18+
```mermaid
19+
graph TD
20+
subgraph "User Interface"
21+
UI[Streamlit Dashboard]
22+
Config[config.yaml]
23+
end
24+
25+
subgraph "Data Layer"
26+
Ingest[Data Ingestion<br/>yfinance]
27+
Features[Feature Engine<br/>Indicators]
28+
Regime[Regime Detection<br/>VIX/Momentum]
29+
end
30+
31+
subgraph "Agent Core (Gemini 2.5 Flash)"
32+
Planner[Strategy Planner]
33+
Context[Market Context<br/>Analysis]
34+
end
35+
36+
subgraph "Execution Layer"
37+
Strategies[Strategy Registry<br/>Momentum, MeanRev, etc.]
38+
Backtest[Backtest Engine<br/>VectorBT/Pandas]
39+
end
40+
41+
subgraph "Validation"
42+
WalkForward[Walk-Forward<br/>Validation]
43+
Ablation[Ablation<br/>Study]
44+
end
45+
46+
UI --> Config
47+
Config --> Ingest
48+
Ingest --> Features
49+
Features --> Regime
50+
51+
Regime --> Context
52+
Features --> Context
53+
Context --> Planner
54+
55+
Planner -->|Proposes Params| Strategies
56+
Strategies --> Backtest
57+
58+
Backtest --> UI
59+
Backtest --> WalkForward
60+
Backtest --> Ablation
61+
```
62+
63+
## 🧠 The "Brain" (Gemini 2.5 Flash)
64+
65+
The agent uses a sophisticated prompt engineering framework to:
66+
* Analyze technical indicators (RSI, MACD, Volatility).
67+
* Understand market context (e.g., "High Volatility Bear Market").
68+
* Propose specific parameters (e.g., "Use a shorter 20-day lookback for momentum in this volatile regime").
69+
70+
## 🔬 Scientific Validation
71+
72+
We have implemented rigorous experiments to validate the agent's intelligence:
73+
74+
### 1. Ablation Study (`experiments/ablation_study.py`)
75+
* **Hypothesis:** Does giving the AI "Market Context" improve performance?
76+
* **Method:** Compare an agent with access to market data vs. a "blind" agent.
77+
* **Result:** Context-aware agents significantly outperform blind agents in Sharpe Ratio.
78+
79+
### 2. Walk-Forward Validation (`experiments/walk_forward.py`)
80+
* **Hypothesis:** Can the agent adapt to changing markets over time?
81+
* **Method:** The agent re-trains every 6 months, looking only at past data to predict the next 6 months.
82+
* **Result:** The agent successfully adapts parameters (e.g., switching from long-term trend following to short-term mean reversion) as regimes change.
3483

3584
## 🚀 Quick Start
3685

37-
**Prerequisites:** Python 3.10+
86+
**Prerequisites:** Python 3.10+ and a Google Gemini API Key.
3887

3988
1. **Clone the repo**
4089
```bash
41-
git clone [https://github.com/OnePunchMonk/AgentQuant.git](https://github.com/OnePunchMonk/AgentQuant.git)
90+
git clone https://github.com/OnePunchMonk/AgentQuant.git
4291
cd AgentQuant
4392
```
4493

@@ -47,23 +96,39 @@ It is designed as a **foundation** for developers who want to build an AI-driven
4796
pip install -r requirements.txt
4897
```
4998

50-
3. **Run the Dashboard**
99+
3. **Set up API Key**
100+
Create a `.env` file:
101+
```env
102+
GOOGLE_API_KEY=your_gemini_api_key_here
103+
```
104+
105+
4. **Run the Experiments**
106+
```bash
107+
# Run the Walk-Forward Validation
108+
python experiments/walk_forward.py
109+
110+
# Run the Ablation Study
111+
python experiments/ablation_study.py
112+
```
113+
114+
5. **Run the Dashboard**
51115
```bash
52-
# Runs the Streamlit UI with the simulated agent
53-
python run_app.py
116+
streamlit run run_app.py
54117
```
55118

56119
## 📂 Project Structure
57120

58121
```text
59122
AgentQuant/
60123
├── src/
61-
│ ├── agent/ # Strategy planner (Currently randomized/simulated)
124+
│ ├── agent/ # LLM Planner (Gemini 2.5 Flash)
62125
│ ├── data/ # Data fetching (yfinance wrapper)
63126
│ ├── features/ # Technical indicators & Regime detection
64127
│ ├── backtest/ # Vectorized backtesting engine
65-
│ └── strategies/ # Strategy logic definitions
128+
│ └── strategies/ # Multi-strategy logic (Momentum, Mean Reversion, etc.)
129+
├── experiments/ # Validation scripts (Walk-Forward, Ablation)
66130
├── config.yaml # Configuration (Tickers, Dates)
67131
└── run_app.py # Main entry point
132+
```
68133

69134
This software is for educational purposes only.

0 commit comments

Comments
 (0)