Astocoder commited on
Commit
46c6e13
ยท
1 Parent(s): 8be84ff

update my all files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -3
  2. README.md +90 -24
  3. server/app.py +5 -1
Dockerfile CHANGED
@@ -1,12 +1,21 @@
1
  FROM python:3.11-slim
2
 
 
 
 
 
 
3
  WORKDIR /app
4
 
 
5
  COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
7
 
8
- COPY . .
 
9
 
 
10
  EXPOSE 7860
11
 
12
- CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port ", "7860"]
 
 
1
  FROM python:3.11-slim
2
 
3
+ # Create non-root user
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+
8
  WORKDIR /app
9
 
10
+ # Copy requirements first
11
  COPY requirements.txt .
12
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
13
 
14
+ # Copy all files
15
+ COPY --chown=user . /app
16
 
17
+ # Expose port 7860 (Hugging Face default)
18
  EXPOSE 7860
19
 
20
+ # Run the server
21
+ CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -8,9 +8,10 @@ An OpenEnv-compliant environment that tests AI agents on financial data analysis
8
  Quant-Gym is a benchmark environment where AI agents can practice:
9
  - Fetching real-time market data
10
  - Analyzing financial news sentiment
 
11
  - Evaluating trading strategies with risk metrics
12
 
13
- This is a **research benchmark** for evaluating AI reasoning in financial contexts, not a trading tool.
14
 
15
  ## ๐Ÿ“Š Environment Tasks
16
 
@@ -24,55 +25,67 @@ This is a **research benchmark** for evaluating AI reasoning in financial contex
24
 
25
  | Endpoint | Method | Description |
26
  |----------|--------|-------------|
 
27
  | `/health` | GET | Health check |
28
  | `/reset` | POST | Reset environment to initial state |
29
- | `/step` | POST | Execute an action (BUY/SELL/GET_PRICE/BACKTEST) |
30
  | `/state` | GET | Get current environment state |
31
  | `/tasks` | GET | List all available tasks |
 
32
 
33
  ## ๐Ÿ”ง Installation
34
 
35
  ### Prerequisites
36
  - Python 3.10+
37
- - Docker (for containerized deployment)
38
 
39
  ### Local Setup
40
 
41
  ```bash
42
  # Clone the repository
43
- git clone https://github.com/Samikshacode934/quant-gym-openenv.git
44
  cd quant-gym-openenv
45
 
46
  # Install dependencies
47
  pip install -r requirements.txt
48
 
49
- # Download market data
50
- python download_data.py
51
 
52
  # Start the server
53
- python -m uvicorn server.app:app --host 0.0.0.0 --port 8000
54
 
55
 
56
  ๐ŸŽฎ Action Schema
57
  The agent can take the following actions:
 
 
58
  {
59
- "type": "BUY | SELL | GET_PRICE | BACKTEST",
60
  "amount": 10,
61
  "explanation": "RSI indicates oversold condition",
62
  "strategy": "momentum"
63
  }
64
 
 
 
 
 
 
 
 
65
 
66
 
67
  ๐Ÿ‘๏ธ Observation Schema
68
  The environment returns:
69
 
 
70
  {
71
- "timestamp": "2026-03-31 14:30:00",
72
- "price": 248.45,
73
  "balance": 8500.00,
74
  "holdings": 10,
75
- "portfolio_value": 10984.50,
76
  "last_news": {
77
  "headline": "Apple announces new AI chip",
78
  "sentiment": "positive"
@@ -84,23 +97,76 @@ The environment returns:
84
  }
85
  }
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
 
 
88
 
 
89
 
90
- Architecture
 
 
 
91
  quant-gym-openenv/
92
- โ”œโ”€โ”€ models.py # Pydantic schemas
93
- โ”œโ”€โ”€ openenv.yaml # OpenEnv configuration
94
- โ”œโ”€โ”€ inference.py # Baseline agent
95
- โ”œโ”€โ”€ requirements.txt # Dependencies
 
 
96
  โ”œโ”€โ”€ server/
97
- โ”‚ โ”œโ”€โ”€ app.py # FastAPI server
98
- โ”‚ โ”œโ”€โ”€ environment.py # Trading logic
99
- โ”‚ โ”œโ”€โ”€ Dockerfile # Container config
100
  โ”‚ โ””โ”€โ”€ data/
101
- โ”‚ โ”œโ”€โ”€ prices.csv # Market data
102
- โ”‚ โ””โ”€โ”€ news.json # News headlines
103
  โ””โ”€โ”€ graders/
104
- โ”œโ”€โ”€ task1_grader.py
105
- โ”œโ”€โ”€ task2_grader.py
106
- โ””โ”€โ”€ task3_grader.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  Quant-Gym is a benchmark environment where AI agents can practice:
9
  - Fetching real-time market data
10
  - Analyzing financial news sentiment
11
+ - Executing buy/sell trades
12
  - Evaluating trading strategies with risk metrics
13
 
14
+ **This is a research benchmark for evaluating AI reasoning in financial contexts, not a trading tool.**
15
 
16
  ## ๐Ÿ“Š Environment Tasks
17
 
 
25
 
26
  | Endpoint | Method | Description |
27
  |----------|--------|-------------|
28
+ | `/` | GET | Welcome message |
29
  | `/health` | GET | Health check |
30
  | `/reset` | POST | Reset environment to initial state |
31
+ | `/step` | POST | Execute an action (BUY/SELL/GET_PRICE/BACKTEST/GET_NEWS) |
32
  | `/state` | GET | Get current environment state |
33
  | `/tasks` | GET | List all available tasks |
34
+ | `/docs` | GET | Interactive API documentation (FastAPI) |
35
 
36
  ## ๐Ÿ”ง Installation
37
 
38
  ### Prerequisites
39
  - Python 3.10+
40
+ - Docker (optional, for containerized deployment)
41
 
42
  ### Local Setup
43
 
44
  ```bash
45
  # Clone the repository
46
+ git clone https://github.com/Astocoder/quant-gym-openenv.git
47
  cd quant-gym-openenv
48
 
49
  # Install dependencies
50
  pip install -r requirements.txt
51
 
52
+ # Set up Hugging Face token (optional, for LLM features)
53
+ echo 'HF_TOKEN=your_hf_token_here' > .env
54
 
55
  # Start the server
56
+ python -m uvicorn server.app:app --host 0.0.0.0 --port 8000 --reload
57
 
58
 
59
  ๐ŸŽฎ Action Schema
60
  The agent can take the following actions:
61
+
62
+ json
63
  {
64
+ "type": "BUY | SELL | GET_PRICE | BACKTEST | GET_NEWS",
65
  "amount": 10,
66
  "explanation": "RSI indicates oversold condition",
67
  "strategy": "momentum"
68
  }
69
 
70
+ Action Examples
71
+ Action Description
72
+ {"type": "GET_PRICE"} Get current stock price
73
+ {"type": "BUY", "amount": 10} Buy 10 shares
74
+ {"type": "SELL", "amount": 5} Sell 5 shares
75
+ {"type": "GET_NEWS", "explanation": "your analysis"} Get news with analysis
76
+ {"type": "BACKTEST", "strategy": "momentum"} Backtest momentum strategy
77
 
78
 
79
  ๐Ÿ‘๏ธ Observation Schema
80
  The environment returns:
81
 
82
+ json
83
  {
84
+ "timestamp": "step_5",
85
+ "price": 155.00,
86
  "balance": 8500.00,
87
  "holdings": 10,
88
+ "portfolio_value": 10050.00,
89
  "last_news": {
90
  "headline": "Apple announces new AI chip",
91
  "sentiment": "positive"
 
97
  }
98
  }
99
 
100
+ ๐Ÿƒ Running the Baseline Agent
101
+ # Set your Hugging Face token
102
+ export HF_TOKEN="your_hf_token_here"
103
+
104
+ # Run inference
105
+ python inference.py
106
+
107
+ Expected Output:-
108
+ [INFO] HF_TOKEN found (length: 37 chars)
109
+ [START] task=quant-gym env=quant-gym model=meta-llama/Llama-3.2-3B-Instruct
110
+ [STEP] step=1 action=BUY 5 reward=0.15 done=false error=null
111
+ [STEP] step=2 action=GET_PRICE reward=0.05 done=false error=null
112
+ [STEP] step=3 action=SELL 5 reward=0.20 done=false error=null
113
+ ...
114
+ [END] success=true steps=10 score=0.650 rewards=...
115
+
116
+
117
+ ๐Ÿณ Docker Deployment
118
+ Build and run with Docker:
119
+ # Build the image
120
+ docker build -t quant-gym .
121
 
122
+ # Run the container
123
+ docker run -p 7860:7860 quant-gym
124
 
125
+ Then access the API at http://localhost:7860
126
 
127
+ ๐ŸŒ Hugging Face Space
128
+ Live demo: https://huggingface.co/spaces/Astocoder/quant-gym
129
+
130
+ ๐Ÿ“ Project Structure
131
  quant-gym-openenv/
132
+ โ”œโ”€โ”€ Dockerfile # Container configuration
133
+ โ”œโ”€โ”€ inference.py # Baseline agent script
134
+ โ”œโ”€โ”€ models.py # Pydantic schemas
135
+ โ”œโ”€โ”€ openenv.yaml # OpenEnv configuration
136
+ โ”œโ”€โ”€ requirements.txt # Python dependencies
137
+ โ”œโ”€โ”€ README.md # This file
138
  โ”œโ”€โ”€ server/
139
+ โ”‚ โ”œโ”€โ”€ app.py # FastAPI server
140
+ โ”‚ โ”œโ”€โ”€ environment.py # Trading logic
 
141
  โ”‚ โ””โ”€โ”€ data/
142
+ โ”‚ โ”œโ”€โ”€ prices.csv # Market data
143
+ โ”‚ โ””โ”€โ”€ news.json # News headlines
144
  โ””โ”€โ”€ graders/
145
+ โ”œโ”€โ”€ task1_grader.py # Price fetch grader
146
+ โ”œโ”€โ”€ task2_grader.py # News analysis grader
147
+ โ””โ”€โ”€ task3_grader.py # Backtest grader
148
+
149
+
150
+ ๐Ÿ” Environment Variables
151
+ Variable Description Default
152
+ HF_TOKEN Hugging Face API token None (optional)
153
+ API_BASE_URL HF API endpoint https://api-inference.huggingface.co/v1
154
+ MODEL_NAME LLM model name meta-llama/Llama-3.2-3B-Instruct
155
+ BASE_URL Quant-Gym API URL http://localhost:8000
156
+
157
+
158
+ ๐Ÿ“ˆ Evaluation Criteria
159
+ OpenEnv Compliance: Full implementation of step()/reset()/state() APIs
160
+
161
+ Task Completion: All 3 tasks return scores between 0.0-1.0
162
+
163
+ Reward Function: Partial progress signals for meaningful learning
164
+
165
+ Reproducibility: Static data ensures consistent results
166
+
167
+
168
+ โš ๏ธ Disclaimer
169
+ This is a research benchmark environment for evaluating AI agent reasoning. It does not provide financial advice or real trading recommendations. All data is for simulation purposes only.
170
+
171
+
172
+
server/app.py CHANGED
@@ -2,11 +2,15 @@ import sys
2
  import os
3
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
4
 
5
- from fastapi import FastAPI, HTTPException, Request
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from pydantic import BaseModel
8
  from typing import Optional, Dict, Any, List
9
  from enum import Enum
 
 
 
 
10
 
11
  # Simple models for the API
12
  class ActionType(str, Enum):
 
2
  import os
3
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
4
 
5
+ from fastapi import FastAPI, HTTPException
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from pydantic import BaseModel
8
  from typing import Optional, Dict, Any, List
9
  from enum import Enum
10
+ from server.app import app as quant_gym_app
11
+
12
+
13
+ app = quant_gym_app
14
 
15
  # Simple models for the API
16
  class ActionType(str, Enum):