Update volume_agent.py
Browse files- volume_agent.py +20 -4
volume_agent.py
CHANGED
|
@@ -1,9 +1,25 @@
|
|
| 1 |
class VolumeSurgeAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
def run(self, df, threshold=1.8):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
recent_avg = df['Volume'].iloc[-20:-1].mean()
|
| 4 |
latest_volume = df['Volume'].iloc[-1]
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
| 1 |
class VolumeSurgeAgent:
|
| 2 |
+
"""
|
| 3 |
+
Detects volume surges compared to recent average volume.
|
| 4 |
+
Returns a structured object with surge status and ratio.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
def run(self, df, threshold=1.8):
|
| 8 |
+
if len(df) < 21:
|
| 9 |
+
return {
|
| 10 |
+
"volume_surge": False,
|
| 11 |
+
"ratio": 0,
|
| 12 |
+
"status": "⚠️ Insufficient data"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
recent_avg = df['Volume'].iloc[-20:-1].mean()
|
| 16 |
latest_volume = df['Volume'].iloc[-1]
|
| 17 |
+
ratio = latest_volume / recent_avg
|
| 18 |
+
|
| 19 |
+
surge = ratio > threshold
|
| 20 |
|
| 21 |
+
return {
|
| 22 |
+
"volume_surge": surge,
|
| 23 |
+
"ratio": round(ratio, 2),
|
| 24 |
+
"status": "✅ Spike" if surge else "Normal"
|
| 25 |
+
}
|