]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix: ensure std on samples apply Bessel correction
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 21 Sep 2025 10:09:35 +0000 (12:09 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 21 Sep 2025 10:09:35 +0000 (12:09 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
ReforceXY/user_data/freqaimodels/ReforceXY.py
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/Utils.py

index 67e6fca456e7303f642856a3ce8362de51bce58f..dedd96d1b473e286c5f3cebed852fb7dc9910c2d 100644 (file)
@@ -1971,11 +1971,10 @@ class InfoMetricsCallback(TensorboardCallback):
             for k, values in numeric_acc.items():
                 if not values:
                     continue
-                mean = np.mean(values)
-                aggregated_info[k] = mean
+                aggregated_info[k] = np.mean(values)
                 if len(values) > 1:
                     try:
-                        aggregated_info[f"{k}_std"] = np.std(values)
+                        aggregated_info[f"{k}_std"] = np.std(values, ddof=1)
                     except Exception:
                         pass
 
@@ -2011,7 +2010,12 @@ class InfoMetricsCallback(TensorboardCallback):
             try:
                 self.logger.record("info/n_envs", int(len(infos_list)))
             except Exception:
-                pass
+                try:
+                    self.logger.record(
+                        "info/n_envs", int(len(infos_list)), exclude=("tensorboard",)
+                    )
+                except Exception:
+                    pass
 
             if filtered_values > 0:
                 try:
@@ -2127,18 +2131,18 @@ class InfoMetricsCallback(TensorboardCallback):
                             category, {}
                         ).get(metric)
                         if isinstance(value, (int, float)) and count and count > 0:
-                            mean = float(value) / float(count)
-                            self.logger.record(f"{category}/{metric}_mean", mean)
+                            self.logger.record(
+                                f"{category}/{metric}_mean", float(value) / float(count)
+                            )
                     except Exception:
                         try:
                             count = aggregated_tensorboard_metric_counts.get(
                                 category, {}
                             ).get(metric)
                             if isinstance(value, (int, float)) and count and count > 0:
-                                mean = float(value) / float(count)
                                 self.logger.record(
                                     f"{category}/{metric}_mean",
-                                    mean,
+                                    float(value) / float(count),
                                     exclude=("tensorboard",),
                                 )
                         except Exception:
@@ -2152,8 +2156,23 @@ class InfoMetricsCallback(TensorboardCallback):
             else:
                 progress_done = 0.0
             progress_remaining = 1.0 - progress_done
-            self.logger.record("train/progress_done", progress_done)
-            self.logger.record("train/progress_remaining", progress_remaining)
+            try:
+                self.logger.record("train/progress_done", progress_done)
+                self.logger.record("train/progress_remaining", progress_remaining)
+            except Exception:
+                try:
+                    self.logger.record(
+                        "train/progress_done",
+                        progress_done,
+                        exclude=("tensorboard",),
+                    )
+                    self.logger.record(
+                        "train/progress_remaining",
+                        progress_remaining,
+                        exclude=("tensorboard",),
+                    )
+                except Exception:
+                    pass
         except Exception:
             progress_remaining = 1.0
 
@@ -2162,7 +2181,17 @@ class InfoMetricsCallback(TensorboardCallback):
             if callable(lr):
                 lr = lr(progress_remaining)
             if isinstance(lr, (int, float)) and np.isfinite(lr):
-                self.logger.record("train/learning_rate", float(lr))
+                try:
+                    self.logger.record("train/learning_rate", float(lr))
+                except Exception:
+                    try:
+                        self.logger.record(
+                            "train/learning_rate",
+                            float(lr),
+                            exclude=("tensorboard",),
+                        )
+                    except Exception:
+                        pass
         except Exception:
             pass
 
@@ -2172,7 +2201,17 @@ class InfoMetricsCallback(TensorboardCallback):
                 if callable(cr):
                     cr = cr(progress_remaining)
                 if isinstance(cr, (int, float)) and np.isfinite(cr):
-                    self.logger.record("train/clip_range", float(cr))
+                    try:
+                        self.logger.record("train/clip_range", float(cr))
+                    except Exception:
+                        try:
+                            self.logger.record(
+                                "train/clip_range",
+                                float(cr),
+                                exclude=("tensorboard",),
+                            )
+                        except Exception:
+                            pass
             except Exception:
                 pass
 
index 96a249f7a3d8a03329bf2163e0ea32f2da552ce3..79cc03a80643c00f2f47de55b4ba96404f1332a3 100644 (file)
@@ -503,7 +503,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             )
 
         dk.data["DI_value_mean"] = di_values.mean()
-        dk.data["DI_value_std"] = di_values.std()
+        dk.data["DI_value_std"] = di_values.std(ddof=1)
         dk.data["extra_returns_per_train"]["DI_value_param1"] = f[0]
         dk.data["extra_returns_per_train"]["DI_value_param2"] = f[1]
         dk.data["extra_returns_per_train"]["DI_value_param3"] = f[2]
index ddade7f950d4d4a6edde6105e213437e17dbca5b..f50bc3eeb5bdefc0b89a19feef0080957cf93b5f 100644 (file)
@@ -222,7 +222,7 @@ def vwapb(
     dataframe: pd.DataFrame, window: int = 20, std_factor: float = 1.0
 ) -> tuple[pd.Series, pd.Series, pd.Series]:
     vwap = qtpylib.rolling_vwap(dataframe, window=window)
-    rolling_std = vwap.rolling(window=window, min_periods=window).std()
+    rolling_std = vwap.rolling(window=window, min_periods=window).std(ddof=1)
     vwap_low = vwap - (rolling_std * std_factor)
     vwap_high = vwap + (rolling_std * std_factor)
     return vwap_low, vwap, vwap_high