ifieryarrows commited on
Commit
74702a5
Β·
verified Β·
1 Parent(s): b27dee6

Sync from GitHub (tests passed)

Browse files
Files changed (1) hide show
  1. deep_learning/training/hyperopt.py +13 -9
deep_learning/training/hyperopt.py CHANGED
@@ -102,11 +102,10 @@ def _objective(trial, base_cfg: TFTASROConfig, master_data: tuple) -> float:
102
  Composite objective (lower is better):
103
  score = val_loss + variance_penalty
104
 
105
- The variance penalty pushes Optuna away from "flat but directionally correct"
106
- configs that game the Sharpe component with near-zero pred_std. Penalty
107
- coefficient is 2.0 (strong) β€” VR<0.5 configs are heavily penalised because
108
- the loss function changes (TANH_SCALE, amplitude_loss) now make the model
109
- *capable* of higher VR; low VR indicates a bad config, not a fundamental limit.
110
  """
111
  try:
112
  import lightning.pytorch as pl
@@ -189,12 +188,17 @@ def _objective(trial, base_cfg: TFTASROConfig, master_data: tuple) -> float:
189
  actual_std = float(y_actual[:n].std())
190
  vr = pred_std / actual_std if actual_std > 1e-9 else 0.0
191
 
192
- # Penalty activates when VR < 0.5 (predictions cover less than half
193
- # the real volatility). Scaled so VR=0 β†’ penalty=2.0, VR=0.5 β†’ 0.
194
- # Strong coefficient (2.0) ensures flat configs cannot win even with
195
- # very good val_loss, since typical val_loss range is [-0.15, +0.3].
 
 
 
196
  if vr < 0.5:
197
  variance_penalty = 2.0 * (1.0 - vr / 0.5)
 
 
198
 
199
  trial.set_user_attr("variance_ratio", round(vr, 4))
200
  trial.set_user_attr("pred_std", round(pred_std, 6))
 
102
  Composite objective (lower is better):
103
  score = val_loss + variance_penalty
104
 
105
+ Two-sided variance penalty keeps predictions in a healthy amplitude zone:
106
+ VR < 0.5 β†’ strong penalty (2.0Γ—) β€” flat predictions are useless
107
+ 0.5–1.5 β†’ no penalty β€” wide healthy zone, not a narrow band
108
+ VR > 1.5 β†’ gentle penalty (0.5Γ—) β€” overconfident but still has signal
 
109
  """
110
  try:
111
  import lightning.pytorch as pl
 
188
  actual_std = float(y_actual[:n].std())
189
  vr = pred_std / actual_std if actual_std > 1e-9 else 0.0
190
 
191
+ # Two-sided penalty with a wide healthy zone [0.5, 1.5]:
192
+ # VR < 0.5 β†’ strong penalty (flat predictions, the original problem)
193
+ # 0.5–1.5 β†’ no penalty (3Γ— wide zone, not a narrow band)
194
+ # VR > 1.5 β†’ gentle penalty (overconfident, predictions louder than market)
195
+ #
196
+ # Asymmetric: too-flat is worse than too-loud (flat predictions are
197
+ # useless; loud predictions at least carry directional signal).
198
  if vr < 0.5:
199
  variance_penalty = 2.0 * (1.0 - vr / 0.5)
200
+ elif vr > 1.5:
201
+ variance_penalty = 0.5 * (vr - 1.5)
202
 
203
  trial.set_user_attr("variance_ratio", round(vr, 4))
204
  trial.set_user_attr("pred_std", round(pred_std, 6))