fix-track-record-dates
Browse files- __pycache__/__init__.cpython-311.pyc +0 -0
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/kotak_neo.cpython-311.pyc +0 -0
- models/tomorrow_latest_prediction.csv +2 -2
- models/tomorrow_summary.json +6 -5
- nifty_backend/__pycache__/__init__.cpython-311.pyc +0 -0
- nifty_backend/__pycache__/runtime.cpython-311.pyc +3 -0
- nifty_backend/__pycache__/yahoo_history_client.cpython-311.pyc +0 -0
- nifty_backend/runtime.py +103 -19
- scripts/__pycache__/refresh_daily_data.cpython-311.pyc +0 -0
- scripts/__pycache__/refresh_first5_prediction.cpython-311.pyc +0 -0
- scripts/__pycache__/retrain_opening_model.cpython-311.pyc +0 -0
- scripts/__pycache__/run_ist_scheduler.cpython-311.pyc +0 -0
__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (31 kB). View file
|
|
|
__pycache__/kotak_neo.cpython-311.pyc
ADDED
|
Binary file (74.3 kB). View file
|
|
|
models/tomorrow_latest_prediction.csv
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
input_date,target_date,prediction,prob_up,confidence,threshold,model_name,source_model,validation_accuracy,test_accuracy
|
| 2 |
-
2026-
|
|
|
|
| 1 |
+
input_date,target_date,prediction,prob_up,confidence,threshold,model_name,source_model,validation_accuracy,test_accuracy
|
| 2 |
+
2026-06-01,2026-06-02,DOWN,0.44104410506976766,0.5589558949302323,0.534,nifty_tomorrow_direction_model,locked_multiwindow_nifty50_ensemble_v2,0.5780141843971631,0.6736842105263158
|
models/tomorrow_summary.json
CHANGED
|
@@ -25,10 +25,10 @@
|
|
| 25 |
"valid_end": "2025-08-17",
|
| 26 |
"test_start": "2025-08-18",
|
| 27 |
"test_end": "2026-05-26",
|
| 28 |
-
"latest_forecast_date": "2026-
|
| 29 |
-
"latest_forecast_for": "next trading
|
| 30 |
-
"latest_forecast_prob_up": 0.
|
| 31 |
-
"latest_forecast_signal": "
|
| 32 |
"feature_count": 204,
|
| 33 |
"validation_prob_std": 0.06800064531350844,
|
| 34 |
"test_prob_std": 0.06311239013827799,
|
|
@@ -38,5 +38,6 @@
|
|
| 38 |
"source_model": "locked_multiwindow_nifty50_ensemble_v2",
|
| 39 |
"target": "next trading session NIFTY 50 direction",
|
| 40 |
"artifact_type": "daily_forecaster_outputs",
|
| 41 |
-
"artifact_source": "C:\\Users\\jhaji\\Downloads\\forecasting project\\Code\\models\\nifty_forecaster\\outputs"
|
|
|
|
| 42 |
}
|
|
|
|
| 25 |
"valid_end": "2025-08-17",
|
| 26 |
"test_start": "2025-08-18",
|
| 27 |
"test_end": "2026-05-26",
|
| 28 |
+
"latest_forecast_date": "2026-06-01",
|
| 29 |
+
"latest_forecast_for": "next trading session 2026-06-02",
|
| 30 |
+
"latest_forecast_prob_up": 0.44104410506976766,
|
| 31 |
+
"latest_forecast_signal": "DOWN",
|
| 32 |
"feature_count": 204,
|
| 33 |
"validation_prob_std": 0.06800064531350844,
|
| 34 |
"test_prob_std": 0.06311239013827799,
|
|
|
|
| 38 |
"source_model": "locked_multiwindow_nifty50_ensemble_v2",
|
| 39 |
"target": "next trading session NIFTY 50 direction",
|
| 40 |
"artifact_type": "daily_forecaster_outputs",
|
| 41 |
+
"artifact_source": "C:\\Users\\jhaji\\Downloads\\forecasting project\\Code\\models\\nifty_forecaster\\outputs",
|
| 42 |
+
"latest_target_date": "2026-06-02"
|
| 43 |
}
|
nifty_backend/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (257 Bytes). View file
|
|
|
nifty_backend/__pycache__/runtime.cpython-311.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6968b7ea4eb2d4595aaafb2e5dbd05ac9ef04691779edcf223dcec996fd657a5
|
| 3 |
+
size 118798
|
nifty_backend/__pycache__/yahoo_history_client.cpython-311.pyc
ADDED
|
Binary file (27.8 kB). View file
|
|
|
nifty_backend/runtime.py
CHANGED
|
@@ -978,7 +978,7 @@ def refresh_tomorrow_prediction(session_date: date | None = None) -> dict[str, A
|
|
| 978 |
input_day = date.fromisoformat(str(cleaned.get("input_date"))[:10])
|
| 979 |
except Exception:
|
| 980 |
input_day = None
|
| 981 |
-
if input_day is not None:
|
| 982 |
clear_dashboard_payload_cache()
|
| 983 |
return cleaned
|
| 984 |
summary = load_tomorrow_summary()
|
|
@@ -1101,12 +1101,86 @@ def dashboard_payload() -> dict[str, Any]:
|
|
| 1101 |
return copy.deepcopy(_dashboard_payload_cached(key))
|
| 1102 |
|
| 1103 |
|
| 1104 |
-
def warm_dashboard_payload_cache() -> None:
|
| 1105 |
-
dashboard_payload()
|
| 1106 |
-
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1110 |
summary = load_model_summary()
|
| 1111 |
t5_latest = _latest_saved_prediction_uncached()
|
| 1112 |
tomorrow_summary = load_tomorrow_summary()
|
|
@@ -1182,9 +1256,9 @@ def _dashboard_payload_cached(key: tuple[tuple[str, int | None, int | None], ...
|
|
| 1182 |
"test_rows": int(len(t5_test)) if not t5_test.empty else int(summary.get("test_rows") or 0),
|
| 1183 |
},
|
| 1184 |
]
|
| 1185 |
-
metrics = {
|
| 1186 |
-
"validation_accuracy": tomorrow_summary.get("validation_accuracy"),
|
| 1187 |
-
"test_accuracy": tomorrow_summary.get("test_accuracy"),
|
| 1188 |
"baseline_test_accuracy": tomorrow_summary.get("baseline_accuracy"),
|
| 1189 |
"validation_auc": summary.get("validation_auc"),
|
| 1190 |
"test_auc": summary.get("test_auc"),
|
|
@@ -1192,10 +1266,19 @@ def _dashboard_payload_cached(key: tuple[tuple[str, int | None, int | None], ...
|
|
| 1192 |
"feature_count": tomorrow_summary.get("feature_count"),
|
| 1193 |
"recent_accuracy": tomorrow_accuracy,
|
| 1194 |
"recent_accuracy_days": int(len(tomorrow_recent)) if not tomorrow_recent.empty else 0,
|
| 1195 |
-
"total_test_days": int(tomorrow_summary.get("n_test") or len(tomorrow_test) or 0),
|
| 1196 |
-
"models": model_metrics,
|
| 1197 |
-
}
|
| 1198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1199 |
"latest": t5_latest,
|
| 1200 |
"tomorrow_latest": tomorrow_latest,
|
| 1201 |
"tplus1_latest": tplus1_latest,
|
|
@@ -1210,11 +1293,12 @@ def _dashboard_payload_cached(key: tuple[tuple[str, int | None, int | None], ...
|
|
| 1210 |
"opening_features": _json_ready_frame(opening),
|
| 1211 |
"monthly_accuracy": _json_ready_frame(monthly),
|
| 1212 |
"direction_mix": _json_ready_frame(direction_mix),
|
| 1213 |
-
"recent_predictions": _json_ready_frame(recent_predictions),
|
| 1214 |
-
"t5_recent_predictions": _json_ready_frame(recent_predictions),
|
| 1215 |
-
"tomorrow_recent_predictions": _json_ready_frame(tomorrow_recent),
|
| 1216 |
-
"tplus1_recent_predictions": _json_ready_frame(tplus1_test.tail(40)),
|
| 1217 |
-
|
|
|
|
| 1218 |
"data_status": {
|
| 1219 |
"nifty_1m_rows": int(len(pd.read_parquet(NIFTY_1M_PATH, columns=["date"]))),
|
| 1220 |
"nifty_1d_rows": int(len(pd.read_parquet(NIFTY_1D_PATH, columns=["date"]))),
|
|
|
|
| 978 |
input_day = date.fromisoformat(str(cleaned.get("input_date"))[:10])
|
| 979 |
except Exception:
|
| 980 |
input_day = None
|
| 981 |
+
if input_day is not None and (session_date is None or input_day >= session_date):
|
| 982 |
clear_dashboard_payload_cache()
|
| 983 |
return cleaned
|
| 984 |
summary = load_tomorrow_summary()
|
|
|
|
| 1101 |
return copy.deepcopy(_dashboard_payload_cached(key))
|
| 1102 |
|
| 1103 |
|
| 1104 |
+
def warm_dashboard_payload_cache() -> None:
|
| 1105 |
+
dashboard_payload()
|
| 1106 |
+
|
| 1107 |
+
|
| 1108 |
+
def build_prediction_track_record(
|
| 1109 |
+
daily: pd.DataFrame,
|
| 1110 |
+
t5_test: pd.DataFrame,
|
| 1111 |
+
tomorrow_test: pd.DataFrame,
|
| 1112 |
+
tplus1_test: pd.DataFrame,
|
| 1113 |
+
t5_latest: dict[str, Any],
|
| 1114 |
+
tomorrow_latest: dict[str, Any],
|
| 1115 |
+
tplus1_latest: dict[str, Any],
|
| 1116 |
+
) -> list[dict[str, Any]]:
|
| 1117 |
+
daily_rows = daily.copy()
|
| 1118 |
+
daily_rows["date"] = pd.to_datetime(daily_rows["date"], errors="coerce").dt.normalize()
|
| 1119 |
+
daily_rows = daily_rows.dropna(subset=["date"]).sort_values("date")
|
| 1120 |
+
daily_rows = daily_rows[
|
| 1121 |
+
daily_rows["open"].map(lambda value: np.isfinite(float(value)) if pd.notna(value) else False)
|
| 1122 |
+
& daily_rows["close"].map(lambda value: np.isfinite(float(value)) if pd.notna(value) else False)
|
| 1123 |
+
].copy()
|
| 1124 |
+
daily_rows = daily_rows[daily_rows["open"].astype(float) != 0]
|
| 1125 |
+
if daily_rows.empty:
|
| 1126 |
+
return []
|
| 1127 |
+
|
| 1128 |
+
predictions_by_date: dict[str, dict[str, Any]] = {}
|
| 1129 |
+
|
| 1130 |
+
def add_prediction(target_date: Any, prediction: Any, source: str, priority: int, meta: dict[str, Any] | None = None) -> None:
|
| 1131 |
+
day = str(target_date or "")[:10]
|
| 1132 |
+
pred = str(prediction or "").upper()
|
| 1133 |
+
if not day or pred not in {"UP", "DOWN"}:
|
| 1134 |
+
return
|
| 1135 |
+
existing = predictions_by_date.get(day)
|
| 1136 |
+
if existing and existing.get("_priority", 0) >= priority:
|
| 1137 |
+
return
|
| 1138 |
+
predictions_by_date[day] = {
|
| 1139 |
+
"prediction": pred,
|
| 1140 |
+
"source": source,
|
| 1141 |
+
"_priority": priority,
|
| 1142 |
+
**(meta or {}),
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
for _, row in t5_test.iterrows():
|
| 1146 |
+
add_prediction(row.get("date"), row.get("prediction"), "T+5", 30, {"prob_up": row.get("prob_up")})
|
| 1147 |
+
for _, row in tomorrow_test.iterrows():
|
| 1148 |
+
pred = row.get("prediction")
|
| 1149 |
+
if pd.isna(pred) and "pred" in row:
|
| 1150 |
+
pred = "UP" if int(row.get("pred")) == 1 else "DOWN"
|
| 1151 |
+
add_prediction(row.get("target_date") or row.get("date"), pred, "Tomorrow", 20, {"prob_up": row.get("prob_up")})
|
| 1152 |
+
for _, row in tplus1_test.iterrows():
|
| 1153 |
+
add_prediction(row.get("target_date") or row.get("date"), row.get("prediction"), "T+1", 10, {"prob_up": row.get("prob_up")})
|
| 1154 |
+
|
| 1155 |
+
add_prediction(tomorrow_latest.get("target_date"), tomorrow_latest.get("prediction"), "Tomorrow", 40, {"prob_up": tomorrow_latest.get("prob_up")})
|
| 1156 |
+
add_prediction(tplus1_latest.get("target_date"), tplus1_latest.get("prediction"), "T+1", 35, {"prob_up": tplus1_latest.get("prob_up")})
|
| 1157 |
+
add_prediction(t5_latest.get("input_date"), t5_latest.get("prediction"), "T+5", 45, {"prob_up": t5_latest.get("prob_up")})
|
| 1158 |
+
|
| 1159 |
+
records: list[dict[str, Any]] = []
|
| 1160 |
+
for _, row in daily_rows.tail(20).iterrows():
|
| 1161 |
+
day = row["date"].date().isoformat()
|
| 1162 |
+
day_open = float(row["open"])
|
| 1163 |
+
day_close = float(row["close"])
|
| 1164 |
+
actual_move = (day_close - day_open) / day_open
|
| 1165 |
+
actual_direction = "UP" if actual_move >= 0 else "DOWN"
|
| 1166 |
+
pred = predictions_by_date.get(day)
|
| 1167 |
+
prediction = pred.get("prediction") if pred else None
|
| 1168 |
+
records.append(
|
| 1169 |
+
{
|
| 1170 |
+
"date": day,
|
| 1171 |
+
"prediction": prediction,
|
| 1172 |
+
"prediction_source": pred.get("source") if pred else None,
|
| 1173 |
+
"prob_up": pred.get("prob_up") if pred else None,
|
| 1174 |
+
"actual_move": actual_move,
|
| 1175 |
+
"actual_direction": actual_direction,
|
| 1176 |
+
"correct": None if prediction is None else prediction == actual_direction,
|
| 1177 |
+
}
|
| 1178 |
+
)
|
| 1179 |
+
return records
|
| 1180 |
+
|
| 1181 |
+
|
| 1182 |
+
@lru_cache(maxsize=4)
|
| 1183 |
+
def _dashboard_payload_cached(key: tuple[tuple[str, int | None, int | None], ...]) -> dict[str, Any]:
|
| 1184 |
summary = load_model_summary()
|
| 1185 |
t5_latest = _latest_saved_prediction_uncached()
|
| 1186 |
tomorrow_summary = load_tomorrow_summary()
|
|
|
|
| 1256 |
"test_rows": int(len(t5_test)) if not t5_test.empty else int(summary.get("test_rows") or 0),
|
| 1257 |
},
|
| 1258 |
]
|
| 1259 |
+
metrics = {
|
| 1260 |
+
"validation_accuracy": tomorrow_summary.get("validation_accuracy"),
|
| 1261 |
+
"test_accuracy": tomorrow_summary.get("test_accuracy"),
|
| 1262 |
"baseline_test_accuracy": tomorrow_summary.get("baseline_accuracy"),
|
| 1263 |
"validation_auc": summary.get("validation_auc"),
|
| 1264 |
"test_auc": summary.get("test_auc"),
|
|
|
|
| 1266 |
"feature_count": tomorrow_summary.get("feature_count"),
|
| 1267 |
"recent_accuracy": tomorrow_accuracy,
|
| 1268 |
"recent_accuracy_days": int(len(tomorrow_recent)) if not tomorrow_recent.empty else 0,
|
| 1269 |
+
"total_test_days": int(tomorrow_summary.get("n_test") or len(tomorrow_test) or 0),
|
| 1270 |
+
"models": model_metrics,
|
| 1271 |
+
}
|
| 1272 |
+
track_record = build_prediction_track_record(
|
| 1273 |
+
daily,
|
| 1274 |
+
t5_test,
|
| 1275 |
+
tomorrow_test,
|
| 1276 |
+
tplus1_test,
|
| 1277 |
+
t5_latest,
|
| 1278 |
+
tomorrow_latest,
|
| 1279 |
+
tplus1_latest,
|
| 1280 |
+
)
|
| 1281 |
+
return {
|
| 1282 |
"latest": t5_latest,
|
| 1283 |
"tomorrow_latest": tomorrow_latest,
|
| 1284 |
"tplus1_latest": tplus1_latest,
|
|
|
|
| 1293 |
"opening_features": _json_ready_frame(opening),
|
| 1294 |
"monthly_accuracy": _json_ready_frame(monthly),
|
| 1295 |
"direction_mix": _json_ready_frame(direction_mix),
|
| 1296 |
+
"recent_predictions": _json_ready_frame(recent_predictions),
|
| 1297 |
+
"t5_recent_predictions": _json_ready_frame(recent_predictions),
|
| 1298 |
+
"tomorrow_recent_predictions": _json_ready_frame(tomorrow_recent),
|
| 1299 |
+
"tplus1_recent_predictions": _json_ready_frame(tplus1_test.tail(40)),
|
| 1300 |
+
"track_record": track_record,
|
| 1301 |
+
},
|
| 1302 |
"data_status": {
|
| 1303 |
"nifty_1m_rows": int(len(pd.read_parquet(NIFTY_1M_PATH, columns=["date"]))),
|
| 1304 |
"nifty_1d_rows": int(len(pd.read_parquet(NIFTY_1D_PATH, columns=["date"]))),
|
scripts/__pycache__/refresh_daily_data.cpython-311.pyc
ADDED
|
Binary file (937 Bytes). View file
|
|
|
scripts/__pycache__/refresh_first5_prediction.cpython-311.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
scripts/__pycache__/retrain_opening_model.cpython-311.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
scripts/__pycache__/run_ist_scheduler.cpython-311.pyc
ADDED
|
Binary file (5.79 kB). View file
|
|
|