update changes
Browse files- task1_grader.py +15 -5
- task2_grader.py +20 -2
- task3_grader.py +20 -2
- server/environment.py +21 -1
task1_grader.py
CHANGED
|
@@ -1,10 +1,20 @@
|
|
| 1 |
-
def grade_task1(
|
| 2 |
"""
|
| 3 |
Task 1: Fetch Market Data
|
| 4 |
-
Returns score
|
| 5 |
"""
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
# You can add actual logic later, but this passes validation
|
| 10 |
return score
|
|
|
|
| 1 |
+
def grade_task1(action, observation):
|
| 2 |
"""
|
| 3 |
Task 1: Fetch Market Data
|
| 4 |
+
Returns score based on whether price was retrieved
|
| 5 |
"""
|
| 6 |
+
score = 0.75 # Base score
|
| 7 |
+
|
| 8 |
+
# Check if observation has a price
|
| 9 |
+
if observation and observation.get('price', 0) > 0:
|
| 10 |
+
score = 0.95
|
| 11 |
+
else:
|
| 12 |
+
score = 0.55
|
| 13 |
+
|
| 14 |
+
# Ensure score is never 0.0 or 1.0
|
| 15 |
+
if score <= 0.0:
|
| 16 |
+
score = 0.01
|
| 17 |
+
if score >= 1.0:
|
| 18 |
+
score = 0.99
|
| 19 |
|
|
|
|
| 20 |
return score
|
task2_grader.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
-
def grade_task2(
|
| 2 |
"""
|
| 3 |
Task 2: News Sentiment Analysis
|
| 4 |
-
Returns score
|
| 5 |
"""
|
| 6 |
score = 0.75
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
return score
|
|
|
|
| 1 |
+
def grade_task2(action, observation):
|
| 2 |
"""
|
| 3 |
Task 2: News Sentiment Analysis
|
| 4 |
+
Returns score based on explanation quality
|
| 5 |
"""
|
| 6 |
score = 0.75
|
| 7 |
+
|
| 8 |
+
# Check if agent provided explanation
|
| 9 |
+
if action and action.get('explanation'):
|
| 10 |
+
explanation = action.get('explanation', '')
|
| 11 |
+
if len(explanation) > 20:
|
| 12 |
+
score = 0.95
|
| 13 |
+
elif len(explanation) > 10:
|
| 14 |
+
score = 0.85
|
| 15 |
+
else:
|
| 16 |
+
score = 0.65
|
| 17 |
+
else:
|
| 18 |
+
score = 0.55
|
| 19 |
+
|
| 20 |
+
if score <= 0.0:
|
| 21 |
+
score = 0.01
|
| 22 |
+
if score >= 1.0:
|
| 23 |
+
score = 0.99
|
| 24 |
+
|
| 25 |
return score
|
task3_grader.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
-
def grade_task3(
|
| 2 |
"""
|
| 3 |
Task 3: Backtest Strategy
|
| 4 |
-
Returns score
|
| 5 |
"""
|
| 6 |
score = 0.75
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
return score
|
|
|
|
| 1 |
+
def grade_task3(action, observation):
|
| 2 |
"""
|
| 3 |
Task 3: Backtest Strategy
|
| 4 |
+
Returns score based on backtest results
|
| 5 |
"""
|
| 6 |
score = 0.75
|
| 7 |
+
|
| 8 |
+
# Check if backtest results exist
|
| 9 |
+
if observation and observation.get('backtest_results'):
|
| 10 |
+
results = observation.get('backtest_results', {})
|
| 11 |
+
if results.get('sharpe_ratio', 0) > 1.0:
|
| 12 |
+
score = 0.95
|
| 13 |
+
elif results.get('sharpe_ratio', 0) > 0.5:
|
| 14 |
+
score = 0.85
|
| 15 |
+
else:
|
| 16 |
+
score = 0.65
|
| 17 |
+
else:
|
| 18 |
+
score = 0.55
|
| 19 |
+
|
| 20 |
+
if score <= 0.0:
|
| 21 |
+
score = 0.01
|
| 22 |
+
if score >= 1.0:
|
| 23 |
+
score = 0.99
|
| 24 |
+
|
| 25 |
return score
|
server/environment.py
CHANGED
|
@@ -27,6 +27,7 @@ class TradingEnvironment:
|
|
| 27 |
self.shares = 0
|
| 28 |
self.total_steps = len(self.prices)
|
| 29 |
self.tasks_completed = []
|
|
|
|
| 30 |
return self._get_observation()
|
| 31 |
|
| 32 |
def step(self, action: AgentAction):
|
|
@@ -34,6 +35,14 @@ class TradingEnvironment:
|
|
| 34 |
self.idx = min(self.idx + 1, self.total_steps - 1)
|
| 35 |
price = self.prices[self.idx]
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if action.type == "BUY" and action.amount:
|
| 38 |
cost = price * action.amount
|
| 39 |
if cost <= self.cash:
|
|
@@ -48,6 +57,12 @@ class TradingEnvironment:
|
|
| 48 |
|
| 49 |
return self._get_observation()
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def _get_observation(self):
|
| 52 |
price = self.prices[self.idx]
|
| 53 |
news_idx = self.idx % len(self.news)
|
|
@@ -74,5 +89,10 @@ class TradingEnvironment:
|
|
| 74 |
"current_step": self.idx,
|
| 75 |
"total_steps": self.total_steps,
|
| 76 |
"observation": self._get_observation().dict(),
|
| 77 |
-
"tasks_completed": self.tasks_completed
|
|
|
|
| 78 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
self.shares = 0
|
| 28 |
self.total_steps = len(self.prices)
|
| 29 |
self.tasks_completed = []
|
| 30 |
+
self.task_scores = {} # Track scores for each task
|
| 31 |
return self._get_observation()
|
| 32 |
|
| 33 |
def step(self, action: AgentAction):
|
|
|
|
| 35 |
self.idx = min(self.idx + 1, self.total_steps - 1)
|
| 36 |
price = self.prices[self.idx]
|
| 37 |
|
| 38 |
+
# Track which task is being attempted
|
| 39 |
+
if action.type == "GET_PRICE":
|
| 40 |
+
self._complete_task("task1", 0.85)
|
| 41 |
+
elif action.type == "GET_NEWS" or (action.explanation and len(action.explanation) > 5):
|
| 42 |
+
self._complete_task("task2", 0.85)
|
| 43 |
+
elif action.type == "BACKTEST":
|
| 44 |
+
self._complete_task("task3", 0.85)
|
| 45 |
+
|
| 46 |
if action.type == "BUY" and action.amount:
|
| 47 |
cost = price * action.amount
|
| 48 |
if cost <= self.cash:
|
|
|
|
| 57 |
|
| 58 |
return self._get_observation()
|
| 59 |
|
| 60 |
+
def _complete_task(self, task_id: str, score: float):
|
| 61 |
+
"""Mark a task as completed with a score"""
|
| 62 |
+
if task_id not in self.tasks_completed:
|
| 63 |
+
self.tasks_completed.append(task_id)
|
| 64 |
+
self.task_scores[task_id] = score
|
| 65 |
+
|
| 66 |
def _get_observation(self):
|
| 67 |
price = self.prices[self.idx]
|
| 68 |
news_idx = self.idx % len(self.news)
|
|
|
|
| 89 |
"current_step": self.idx,
|
| 90 |
"total_steps": self.total_steps,
|
| 91 |
"observation": self._get_observation().dict(),
|
| 92 |
+
"tasks_completed": self.tasks_completed,
|
| 93 |
+
"task_scores": self.task_scores
|
| 94 |
}
|
| 95 |
+
|
| 96 |
+
def get_task_score(self, task_id: str) -> float:
|
| 97 |
+
"""Return score for a specific task (for grader integration)"""
|
| 98 |
+
return self.task_scores.get(task_id, 0.75)
|