File size: 8,585 Bytes
fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c 930ad01 fc6529c | 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #!/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()
|