Jitendra12421 commited on
Commit
01448db
·
verified ·
1 Parent(s): 3ef4254

Upload 42 files

Browse files
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-05-26,2026-05-27,DOWN,0.4892079705003583,0.5107920294996418,0.543,nifty_tomorrow_direction_model,tuned_daily_forest_single,0.5780141843971631,0.6182795698924731
 
1
  input_date,target_date,prediction,prob_up,confidence,threshold,model_name,source_model,validation_accuracy,test_accuracy
2
+ 2026-05-27,2026-05-29,DOWN,0.503279589082978,0.503279589082978,0.543,nifty_tomorrow_direction_model,tuned_daily_forest_single,0.5780141843971631,0.6182795698924731
models/tomorrow_summary.json CHANGED
@@ -25,13 +25,13 @@
25
  "valid_end": "2025-08-17",
26
  "test_start": "2025-08-18",
27
  "test_end": "2026-05-20",
28
- "latest_forecast_date": "2026-05-26",
29
- "latest_forecast_for": "next trading session 2026-05-27",
30
- "latest_forecast_prob_up": 0.4892079705003583,
31
  "latest_forecast_signal": "DOWN",
32
  "feature_count": 301,
33
  "model_name": "nifty_tomorrow_direction_model",
34
  "source_model": "tuned_daily_forest_single",
35
  "target": "next trading session NIFTY 50 direction",
36
- "latest_target_date": "2026-05-27"
37
  }
 
25
  "valid_end": "2025-08-17",
26
  "test_start": "2025-08-18",
27
  "test_end": "2026-05-20",
28
+ "latest_forecast_date": "2026-05-27",
29
+ "latest_forecast_for": "next trading session 2026-05-29",
30
+ "latest_forecast_prob_up": 0.503279589082978,
31
  "latest_forecast_signal": "DOWN",
32
  "feature_count": 301,
33
  "model_name": "nifty_tomorrow_direction_model",
34
  "source_model": "tuned_daily_forest_single",
35
  "target": "next trading session NIFTY 50 direction",
36
+ "latest_target_date": "2026-05-29"
37
  }
nifty_backend/__pycache__/runtime.cpython-311.pyc CHANGED
Binary files a/nifty_backend/__pycache__/runtime.cpython-311.pyc and b/nifty_backend/__pycache__/runtime.cpython-311.pyc differ
 
nifty_backend/runtime.py CHANGED
@@ -578,14 +578,34 @@ def load_tomorrow_summary() -> dict[str, Any]:
578
  }
579
 
580
 
581
- def latest_tomorrow_prediction() -> dict[str, Any]:
582
- if TOMORROW_LATEST_PATH.exists():
583
- row = pd.read_csv(TOMORROW_LATEST_PATH).iloc[-1].to_dict()
584
- return {k: (None if pd.isna(v) else v) for k, v in row.items()}
585
- summary = load_tomorrow_summary()
586
- return {
587
- "input_date": summary.get("latest_forecast_date"),
588
- "target_date": None,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  "prediction": summary.get("latest_forecast_signal"),
590
  "prob_up": summary.get("latest_forecast_prob_up"),
591
  "confidence": None,
@@ -844,17 +864,18 @@ def refresh_tomorrow_prediction(session_date: date | None = None) -> dict[str, A
844
  }
845
  pd.DataFrame([row]).to_csv(TOMORROW_LATEST_PATH, index=False)
846
  summary = dict(summary)
847
- summary.update(
848
- {
849
- "latest_forecast_date": row["input_date"],
850
  "latest_forecast_for": f"next trading session {row['target_date']}",
851
  "latest_forecast_prob_up": row["prob_up"],
852
  "latest_forecast_signal": row["prediction"],
853
  "latest_target_date": row["target_date"],
854
- }
855
- )
856
- TOMORROW_SUMMARY_PATH.write_text(json.dumps(summary, indent=2), encoding="utf-8")
857
- return row
 
858
 
859
 
860
  def _json_ready_frame(df: pd.DataFrame, limit: int | None = None) -> list[dict[str, Any]]:
@@ -1211,6 +1232,15 @@ def latest_prediction_input_date(path: Path) -> date | None:
1211
  return None if pd.isna(value) else value.date()
1212
 
1213
 
 
 
 
 
 
 
 
 
 
1214
  def expected_completed_daily_date(now: datetime | None = None) -> date:
1215
  now = now or datetime.now(IST)
1216
  if is_trading_day(now.date()) and now.time() < CLOSE_REFRESH_READY:
@@ -1244,6 +1274,7 @@ def stale_data_status(now: datetime | None = None) -> dict[str, Any]:
1244
  latest_daily = latest_parquet_date(NIFTY_1D_PATH)
1245
  latest_minutes = latest_parquet_date(NIFTY_1M_PATH)
1246
  latest_t5 = latest_prediction_input_date(LATEST_PATH)
 
1247
  latest_tplus1 = latest_prediction_input_date(TPLUS1_LATEST_PATH)
1248
  return {
1249
  "server_time_ist": now.isoformat(),
@@ -1253,10 +1284,12 @@ def stale_data_status(now: datetime | None = None) -> dict[str, Any]:
1253
  "latest_daily_date": latest_daily.isoformat() if latest_daily else None,
1254
  "latest_minute_date": latest_minutes.isoformat() if latest_minutes else None,
1255
  "latest_t5_date": latest_t5.isoformat() if latest_t5 else None,
 
1256
  "latest_tplus1_date": latest_tplus1.isoformat() if latest_tplus1 else None,
1257
  "daily_stale": is_stale(latest_daily, expected_daily),
1258
  "minutes_stale": is_stale(latest_minutes, expected_minutes),
1259
  "t5_stale": is_stale(latest_t5, expected_minutes),
 
1260
  "tplus1_stale": is_stale(latest_tplus1, expected_tplus1),
1261
  }
1262
 
@@ -1264,7 +1297,7 @@ def stale_data_status(now: datetime | None = None) -> dict[str, Any]:
1264
  def refresh_stale_data_once(now: datetime | None = None) -> dict[str, Any]:
1265
  now = now or datetime.now(IST)
1266
  status = stale_data_status(now)
1267
- if not any(status[key] for key in ("daily_stale", "minutes_stale", "t5_stale", "tplus1_stale")):
1268
  return {"status": "fresh", **status, "actions": []}
1269
  if not _stale_refresh_lock.acquire(blocking=False):
1270
  return {"status": "skipped", "reason": "stale refresh already running", **status, "actions": []}
@@ -1287,6 +1320,8 @@ def refresh_stale_data_once(now: datetime | None = None) -> dict[str, Any]:
1287
  outcomes = update_opening_outcomes_from_daily()
1288
  actions.append({"name": "daily", **daily_info})
1289
  actions.append({"name": "opening_outcomes", **outcomes})
 
 
1290
  try:
1291
  tomorrow = refresh_tomorrow_prediction(session_date=date.fromisoformat(status["expected_daily_date"]))
1292
  actions.append({"name": "tomorrow_prediction", "input_date": tomorrow.get("input_date")})
 
578
  }
579
 
580
 
581
+ def latest_tomorrow_prediction() -> dict[str, Any]:
582
+ latest_daily = latest_parquet_date(NIFTY_1D_PATH)
583
+ if TOMORROW_LATEST_PATH.exists():
584
+ row = pd.read_csv(TOMORROW_LATEST_PATH).iloc[-1].to_dict()
585
+ cleaned = {k: (None if pd.isna(v) else v) for k, v in row.items()}
586
+ try:
587
+ input_day = date.fromisoformat(str(cleaned.get("input_date"))[:10])
588
+ except Exception:
589
+ input_day = None
590
+ if latest_daily is not None and (input_day is None or input_day < latest_daily):
591
+ try:
592
+ return refresh_tomorrow_prediction(session_date=latest_daily)
593
+ except Exception:
594
+ return cleaned
595
+ return cleaned
596
+ summary = load_tomorrow_summary()
597
+ try:
598
+ summary_input_day = date.fromisoformat(str(summary.get("latest_forecast_date"))[:10])
599
+ except Exception:
600
+ summary_input_day = None
601
+ if latest_daily is not None and (summary_input_day is None or summary_input_day < latest_daily):
602
+ try:
603
+ return refresh_tomorrow_prediction(session_date=latest_daily)
604
+ except Exception:
605
+ pass
606
+ return {
607
+ "input_date": summary.get("latest_forecast_date"),
608
+ "target_date": None,
609
  "prediction": summary.get("latest_forecast_signal"),
610
  "prob_up": summary.get("latest_forecast_prob_up"),
611
  "confidence": None,
 
864
  }
865
  pd.DataFrame([row]).to_csv(TOMORROW_LATEST_PATH, index=False)
866
  summary = dict(summary)
867
+ summary.update(
868
+ {
869
+ "latest_forecast_date": row["input_date"],
870
  "latest_forecast_for": f"next trading session {row['target_date']}",
871
  "latest_forecast_prob_up": row["prob_up"],
872
  "latest_forecast_signal": row["prediction"],
873
  "latest_target_date": row["target_date"],
874
+ }
875
+ )
876
+ TOMORROW_SUMMARY_PATH.write_text(json.dumps(summary, indent=2), encoding="utf-8")
877
+ clear_dashboard_payload_cache()
878
+ return row
879
 
880
 
881
  def _json_ready_frame(df: pd.DataFrame, limit: int | None = None) -> list[dict[str, Any]]:
 
1232
  return None if pd.isna(value) else value.date()
1233
 
1234
 
1235
+ def latest_tomorrow_input_date() -> date | None:
1236
+ try:
1237
+ latest = latest_tomorrow_prediction()
1238
+ raw = latest.get("input_date")
1239
+ return date.fromisoformat(str(raw)[:10]) if raw else None
1240
+ except Exception:
1241
+ return None
1242
+
1243
+
1244
  def expected_completed_daily_date(now: datetime | None = None) -> date:
1245
  now = now or datetime.now(IST)
1246
  if is_trading_day(now.date()) and now.time() < CLOSE_REFRESH_READY:
 
1274
  latest_daily = latest_parquet_date(NIFTY_1D_PATH)
1275
  latest_minutes = latest_parquet_date(NIFTY_1M_PATH)
1276
  latest_t5 = latest_prediction_input_date(LATEST_PATH)
1277
+ latest_tomorrow = latest_tomorrow_input_date()
1278
  latest_tplus1 = latest_prediction_input_date(TPLUS1_LATEST_PATH)
1279
  return {
1280
  "server_time_ist": now.isoformat(),
 
1284
  "latest_daily_date": latest_daily.isoformat() if latest_daily else None,
1285
  "latest_minute_date": latest_minutes.isoformat() if latest_minutes else None,
1286
  "latest_t5_date": latest_t5.isoformat() if latest_t5 else None,
1287
+ "latest_tomorrow_date": latest_tomorrow.isoformat() if latest_tomorrow else None,
1288
  "latest_tplus1_date": latest_tplus1.isoformat() if latest_tplus1 else None,
1289
  "daily_stale": is_stale(latest_daily, expected_daily),
1290
  "minutes_stale": is_stale(latest_minutes, expected_minutes),
1291
  "t5_stale": is_stale(latest_t5, expected_minutes),
1292
+ "tomorrow_stale": is_stale(latest_tomorrow, expected_daily),
1293
  "tplus1_stale": is_stale(latest_tplus1, expected_tplus1),
1294
  }
1295
 
 
1297
  def refresh_stale_data_once(now: datetime | None = None) -> dict[str, Any]:
1298
  now = now or datetime.now(IST)
1299
  status = stale_data_status(now)
1300
+ if not any(status[key] for key in ("daily_stale", "minutes_stale", "t5_stale", "tomorrow_stale", "tplus1_stale")):
1301
  return {"status": "fresh", **status, "actions": []}
1302
  if not _stale_refresh_lock.acquire(blocking=False):
1303
  return {"status": "skipped", "reason": "stale refresh already running", **status, "actions": []}
 
1320
  outcomes = update_opening_outcomes_from_daily()
1321
  actions.append({"name": "daily", **daily_info})
1322
  actions.append({"name": "opening_outcomes", **outcomes})
1323
+
1324
+ if status["daily_stale"] or status["tomorrow_stale"]:
1325
  try:
1326
  tomorrow = refresh_tomorrow_prediction(session_date=date.fromisoformat(status["expected_daily_date"]))
1327
  actions.append({"name": "tomorrow_prediction", "input_date": tomorrow.get("input_date")})