fix: use more stable "date to ms" method

This commit is contained in:
Matthias
2026-04-12 13:12:09 +02:00
parent 33211c8eb1
commit f6f0180fc1
4 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -308,7 +308,7 @@ def get_backtest_market_change(filename: Path, include_ts: bool = True) -> pd.Da
else:
df = pd.read_feather(filename)
if include_ts:
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
df.loc[:, "__date_ts"] = df.loc[:, "date"].dt.as_unit("ms").astype(np.int64)
return df
@@ -326,7 +326,7 @@ def get_backtest_wallet_change(filename: Path, strategy_name: str) -> pd.DataFra
data = load_file_from_zip(filename, f"{filename.stem}_{strategy_name}_wallet.feather")
df = pd.read_feather(BytesIO(data))
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
df.loc[:, "__date_ts"] = df.loc[:, "date"].dt.as_unit("ms").astype(np.int64)
return df
except ValueError:
pass
@@ -35,8 +35,8 @@ class JsonDataHandler(IDataHandler):
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
self.create_dir_if_needed(filename)
_data = data.copy()
# Convert date to int
_data["date"] = _data["date"].astype(np.int64) // 1000 // 1000
# Convert date to int (milliseconds)
_data["date"] = _data["date"].dt.as_unit("ms").astype(np.int64)
# Reset index, select only appropriate columns and save as json
_data.reset_index(drop=True).loc[:, self._columns].to_json(
+2 -2
View File
@@ -794,7 +794,7 @@ class RPC:
results = read_sql("wallet_history", con=Trade.session.bind, parse_dates=["timestamp"])
results = results.rename({"timestamp": "date"}, axis=1)
results.loc[:, "__date_ts"] = results.loc[:, "date"].astype("int64") // 1000 // 1000
results.loc[:, "__date_ts"] = results.loc[:, "date"].dt.as_unit("ms").astype("int64")
# Exclude non-bot managed for now
results_filtered = results.loc[results["bot_managed"]]
@@ -1536,7 +1536,7 @@ class RPC:
df_cols = [col for col in dataframe_columns if col in cols_set]
dataframe = dataframe.loc[:, df_cols]
dataframe.loc[:, "__date_ts"] = dataframe.loc[:, "date"].astype(int64) // 1000 // 1000
dataframe.loc[:, "__date_ts"] = dataframe.loc[:, "date"].dt.as_unit("ms").astype(int64)
# Move signal close to separate column when signal for easy plotting
for sig_type in signals.keys():
if sig_type in dataframe.columns:
+1 -1
View File
@@ -207,7 +207,7 @@ def generate_test_data(
def generate_test_data_raw(timeframe: str, size: int, start: str = "2020-07-05", random_seed=42):
"""Generates data in the ohlcv format used by ccxt"""
df = generate_test_data(timeframe, size, start, random_seed)
df["date"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
df["date"] = df.loc[:, "date"].dt.as_unit("ms").astype(np.int64)
return list(list(x) for x in zip(*(df[x].values.tolist() for x in df.columns), strict=False))