-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtest_simulation_api.py
More file actions
45 lines (40 loc) · 1.5 KB
/
test_simulation_api.py
File metadata and controls
45 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json
def test_simulation():
url = "http://localhost:8000/api/simulate-headline"
# Mock prediction data
mock_prediction = {
"symbol": "RELIANCE",
"company_name": "Reliance Industries",
"dates": ["2026-04-06", "2026-04-07", "2026-04-08", "2026-04-09", "2026-04-10"],
"prices": [2500, 2510, 2520, 2530, 2540],
"prediction_start_index": 2,
"confidence_score": 75
}
test_cases = [
"Massive profit surge and strategic expansion",
"Unexpected lawsuit and catastrophic crash",
"Neutral market update"
]
for headline in test_cases:
print(f"\nTesting Headline: {headline}")
payload = {
"prediction": mock_prediction,
"headline": headline
}
try:
response = requests.post(url, json=payload)
if response.status_code == 200:
result = response.json()
shift_label = result.get("simulation_label")
original_forecast = mock_prediction["prices"][2:]
new_forecast = result["prices"][2:]
print(f"Result: {shift_label}")
print(f"Original Forecast: {original_forecast}")
print(f"Simulated Forecast: {new_forecast}")
else:
print(f"Error: {response.status_code} - {response.text}")
except Exception as e:
print(f"Request failed: {e}")
if __name__ == "__main__":
test_simulation()