Download scripts/validate_dataset.py from future-edge-group/ipulse-ai-batch5-advisor-forecast-panel: direct link, hf CLI and curl.
- Browser
- Download file 8.59 kB
-
https://huggingface.co/datasets/future-edge-group/ipulse-ai-batch5-advisor-forecast-panel/resolve/main/scripts/validate_dataset.py
- Command line
-
hf download hf://datasets/future-edge-group/ipulse-ai-batch5-advisor-forecast-panel/scripts/validate_dataset.py
-
curl -L -o validate_dataset.py https://huggingface.co/datasets/future-edge-group/ipulse-ai-batch5-advisor-forecast-panel/resolve/main/scripts/validate_dataset.py
8.59 kB
| #!/usr/bin/env python3 | |
| """Validate the public Batch 5 advisor-panel CSV package using only stdlib.""" | |
| from __future__ import annotations | |
| import csv | |
| import math | |
| from collections import Counter, defaultdict | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA = ROOT / "data" | |
| VERSION = "ipulse-batch5-advisor-panel-v1.1.0" | |
| ADVISORS = {f"A{i:02d}" for i in range(1, 13)} | |
| ASSETS = { | |
| "ACN.NYSE", | |
| "ADBE.NASDAQ", | |
| "AVAX-USD.CC", | |
| "ETH-USD.CC", | |
| "NOC.NYSE", | |
| "SHEL.LSE", | |
| "SOL-USD.CC", | |
| } | |
| FORBIDDEN_FRAGMENTS = ( | |
| "predrqst_", | |
| "taskconfig_", | |
| "aianalyst_", | |
| "aianlstmode_", | |
| "persona_", | |
| "input_context_snapshot", | |
| "raw_model_response", | |
| "prompt_assembly", | |
| ) | |
| def read_csv(name: str) -> list[dict[str, str]]: | |
| path = DATA / name | |
| with path.open(newline="", encoding="utf-8") as handle: | |
| return list(csv.DictReader(handle)) | |
| def close(a: float, b: float, tolerance: float = 1e-6) -> bool: | |
| return math.isclose(a, b, rel_tol=tolerance, abs_tol=tolerance) | |
| def validate_public_surface() -> None: | |
| for path in DATA.glob("*.csv"): | |
| text = path.read_text(encoding="utf-8").lower() | |
| for fragment in FORBIDDEN_FRAGMENTS: | |
| assert fragment not in text, f"{path.name}: forbidden fragment {fragment}" | |
| def validate_configurations(rows: list[dict[str, str]]) -> None: | |
| assert len(rows) == 12 | |
| assert {row["advisor_code"] for row in rows} == ADVISORS | |
| assert {row["dataset_version"] for row in rows} == {VERSION} | |
| assert {row["model_family"] for row in rows} == {"Google Gemini 3.1 Pro Preview"} | |
| assert all(row["rag_enabled"].lower() == "false" for row in rows) | |
| def validate_forecast_paths(rows: list[dict[str, str]]) -> None: | |
| assert len(rows) == 1680 | |
| assert {row["dataset_version"] for row in rows} == {VERSION} | |
| assert {row["asset_symbol"] for row in rows} == ASSETS | |
| assert {row["advisor_code"] for row in rows} == ADVISORS | |
| grouped: dict[tuple[str, str], list[dict[str, str]]] = defaultdict(list) | |
| for row in rows: | |
| grouped[(row["asset_symbol"], row["advisor_code"])].append(row) | |
| assert len(grouped) == 84 | |
| anchors_by_asset: dict[str, set[tuple[str, float]]] = defaultdict(set) | |
| for (asset, advisor), group in grouped.items(): | |
| assert len(group) == 20, (asset, advisor, len(group)) | |
| group.sort(key=lambda row: int(row["forecast_step"])) | |
| assert [int(row["forecast_step"]) for row in group] == list(range(1, 21)) | |
| assert [row["forecast_date"] for row in group] == sorted(row["forecast_date"] for row in group) | |
| anchor_price = float(group[0]["anchor_price"]) | |
| assert anchor_price > 0.0 | |
| anchors_by_asset[asset].add((group[0]["anchor_date"], anchor_price)) | |
| growth = 1.0 | |
| assert close(float(group[0]["anchor_index"]), 100.0) | |
| for row in group: | |
| growth *= 1.0 + float(row["step_return_pct"]) / 100.0 | |
| expected_return = (growth - 1.0) * 100.0 | |
| expected_index = 100.0 * growth | |
| assert close(float(row["cumulative_forecast_return_pct"]), expected_return) | |
| assert close(float(row["implied_forecast_index"]), expected_index) | |
| assert close( | |
| float(row["implied_forecast_price"]), | |
| anchor_price * expected_index / 100.0, | |
| ) | |
| assert row["shared_input_snapshot_within_asset"].lower() == "true" | |
| assert all(len(values) == 1 for values in anchors_by_asset.values()) | |
| def validate_horizon_summaries( | |
| summaries: list[dict[str, str]], paths: list[dict[str, str]] | |
| ) -> None: | |
| assert len(summaries) == 168 | |
| assert {row["dataset_version"] for row in summaries} == {VERSION} | |
| assert {row["horizon"] for row in summaries} == {"1y", "5y"} | |
| keys = {(row["asset_symbol"], row["advisor_code"], row["horizon"]) for row in summaries} | |
| assert len(keys) == 168 | |
| endpoint = {} | |
| for row in paths: | |
| step = int(row["forecast_step"]) | |
| if step in (4, 20): | |
| horizon = "1y" if step == 4 else "5y" | |
| endpoint[(row["asset_symbol"], row["advisor_code"], horizon)] = row | |
| for row in summaries: | |
| key = (row["asset_symbol"], row["advisor_code"], row["horizon"]) | |
| path = endpoint[key] | |
| assert close( | |
| float(row["path_compounded_base_return_pct"]), | |
| float(path["cumulative_forecast_return_pct"]), | |
| ) | |
| assert close( | |
| float(row["path_implied_target_index"]), | |
| float(path["implied_forecast_index"]), | |
| ) | |
| assert close(float(row["anchor_price"]), float(path["anchor_price"])) | |
| assert close( | |
| float(row["path_implied_target_price"]), | |
| float(path["implied_forecast_price"]), | |
| ) | |
| if row["horizon"] == "1y": | |
| assert row["separately_reported_5y_base_return_pct"] == "" | |
| assert row["separately_reported_5y_rating"] == "" | |
| else: | |
| assert row["separately_reported_5y_base_return_pct"] != "" | |
| assert row["separately_reported_5y_rating"] != "" | |
| def validate_events(rows: list[dict[str, str]]) -> None: | |
| assert len(rows) == 1008 | |
| assert {row["dataset_version"] for row in rows} == {VERSION} | |
| assert {row["asset_symbol"] for row in rows} == ASSETS | |
| assert {row["advisor_code"] for row in rows} == ADVISORS | |
| allowed = { | |
| "horizon_driver", | |
| "horizon_friction", | |
| "horizon_tail_opportunity", | |
| "horizon_tail_risk", | |
| } | |
| assert {row["event_type"] for row in rows} == allowed | |
| assert all(row["event_name"].strip() for row in rows) | |
| counts = Counter(row["event_type"] for row in rows) | |
| assert counts == Counter( | |
| { | |
| "horizon_driver": 336, | |
| "horizon_friction": 336, | |
| "horizon_tail_opportunity": 168, | |
| "horizon_tail_risk": 168, | |
| } | |
| ) | |
| def validate_realized_prices( | |
| rows: list[dict[str, str]], paths: list[dict[str, str]] | |
| ) -> None: | |
| assert len(rows) == 465 | |
| assert {row["dataset_version"] for row in rows} == {VERSION} | |
| assert {row["asset_symbol"] for row in rows} == ASSETS | |
| assert len({(row["asset_symbol"], row["observed_date"]) for row in rows}) == 465 | |
| path_anchors: dict[str, set[tuple[str, float]]] = defaultdict(set) | |
| for row in paths: | |
| path_anchors[row["asset_symbol"]].add( | |
| (row["anchor_date"], float(row["anchor_price"])) | |
| ) | |
| assert all(len(values) == 1 for values in path_anchors.values()) | |
| grouped: dict[str, list[dict[str, str]]] = defaultdict(list) | |
| for row in rows: | |
| grouped[row["asset_symbol"]].append(row) | |
| for asset, group in grouped.items(): | |
| group.sort(key=lambda row: row["observed_date"]) | |
| anchor_date = group[0]["anchor_date"] | |
| anchor_price = float(group[0]["anchor_price"]) | |
| assert (anchor_date, anchor_price) in path_anchors[asset] | |
| assert group[0]["observed_date"] == anchor_date | |
| assert [row["observed_date"] for row in group] == sorted( | |
| row["observed_date"] for row in group | |
| ) | |
| assert len({row["observed_date"] for row in group}) == len(group) | |
| for row in group: | |
| assert row["anchor_date"] == anchor_date | |
| assert close(float(row["anchor_price"]), anchor_price) | |
| observed_close = float(row["observed_close"]) | |
| assert observed_close > 0.0 | |
| expected_return = 100.0 * (observed_close / anchor_price - 1.0) | |
| assert close(float(row["realized_price_return_pct"]), expected_return) | |
| assert close(float(row["realized_index"]), 100.0 + expected_return) | |
| assert row["return_definition"] == "raw_close_price_return_ex_dividends" | |
| def main() -> None: | |
| configurations = read_csv("advisor_configurations.csv") | |
| paths = read_csv("advisor_forecast_paths.csv") | |
| summaries = read_csv("advisor_horizon_summary.csv") | |
| events = read_csv("advisor_drivers_and_risks.csv") | |
| realized = read_csv("realized_price_paths.csv") | |
| validate_public_surface() | |
| validate_configurations(configurations) | |
| validate_forecast_paths(paths) | |
| validate_horizon_summaries(summaries, paths) | |
| validate_events(events) | |
| validate_realized_prices(realized, paths) | |
| print("PASS") | |
| print(f"advisor_configurations={len(configurations)}") | |
| print(f"advisor_forecast_paths={len(paths)}") | |
| print(f"advisor_horizon_summary={len(summaries)}") | |
| print(f"advisor_drivers_and_risks={len(events)}") | |
| print(f"realized_price_paths={len(realized)}") | |
| if __name__ == "__main__": | |
| main() | |