Perform parallel (batch) prediction on multiple time series. All series must have the same historical length and prediction length (pred_len). Args: df_list (List[pd.DataFrame]): List of input DataFrames, each containing price columns and optional volume/amount columns.
(self, df_list, x_timestamp_list, y_timestamp_list, pred_len, T=1.0, top_k=0, top_p=0.9, sample_count=1, verbose=True)
| 560 | |
| 561 | |
| 562 | def predict_batch(self, df_list, x_timestamp_list, y_timestamp_list, pred_len, T=1.0, top_k=0, top_p=0.9, sample_count=1, verbose=True): |
| 563 | """ |
| 564 | Perform parallel (batch) prediction on multiple time series. All series must have the same historical length and prediction length (pred_len). |
| 565 | |
| 566 | Args: |
| 567 | df_list (List[pd.DataFrame]): List of input DataFrames, each containing price columns and optional volume/amount columns. |
| 568 | x_timestamp_list (List[pd.DatetimeIndex or Series]): List of timestamps corresponding to historical data, length should match the number of rows in each DataFrame. |
| 569 | y_timestamp_list (List[pd.DatetimeIndex or Series]): List of future prediction timestamps, length should equal pred_len. |
| 570 | pred_len (int): Number of prediction steps. |
| 571 | T (float): Sampling temperature. |
| 572 | top_k (int): Top-k filtering threshold. |
| 573 | top_p (float): Top-p (nucleus sampling) threshold. |
| 574 | sample_count (int): Number of parallel samples per series, automatically averaged internally. |
| 575 | verbose (bool): Whether to display autoregressive progress. |
| 576 | |
| 577 | Returns: |
| 578 | List[pd.DataFrame]: List of prediction results in the same order as input, each DataFrame contains |
| 579 | `open, high, low, close, volume, amount` columns, indexed by corresponding `y_timestamp`. |
| 580 | """ |
| 581 | # Basic validation |
| 582 | if not isinstance(df_list, (list, tuple)) or not isinstance(x_timestamp_list, (list, tuple)) or not isinstance(y_timestamp_list, (list, tuple)): |
| 583 | raise ValueError("df_list, x_timestamp_list, y_timestamp_list must be list or tuple types.") |
| 584 | if not (len(df_list) == len(x_timestamp_list) == len(y_timestamp_list)): |
| 585 | raise ValueError("df_list, x_timestamp_list, y_timestamp_list must have consistent lengths.") |
| 586 | |
| 587 | num_series = len(df_list) |
| 588 | |
| 589 | x_list = [] |
| 590 | x_stamp_list = [] |
| 591 | y_stamp_list = [] |
| 592 | means = [] |
| 593 | stds = [] |
| 594 | seq_lens = [] |
| 595 | y_lens = [] |
| 596 | |
| 597 | for i in range(num_series): |
| 598 | df = df_list[i] |
| 599 | if not isinstance(df, pd.DataFrame): |
| 600 | raise ValueError(f"Input at index {i} is not a pandas DataFrame.") |
| 601 | if not all(col in df.columns for col in self.price_cols): |
| 602 | raise ValueError(f"DataFrame at index {i} is missing price columns {self.price_cols}.") |
| 603 | |
| 604 | df = df.copy() |
| 605 | if self.vol_col not in df.columns: |
| 606 | df[self.vol_col] = 0.0 |
| 607 | df[self.amt_vol] = 0.0 |
| 608 | if self.amt_vol not in df.columns and self.vol_col in df.columns: |
| 609 | df[self.amt_vol] = df[self.vol_col] * df[self.price_cols].mean(axis=1) |
| 610 | |
| 611 | if df[self.price_cols + [self.vol_col, self.amt_vol]].isnull().values.any(): |
| 612 | raise ValueError(f"DataFrame at index {i} contains NaN values in price or volume columns.") |
| 613 | |
| 614 | x_timestamp = x_timestamp_list[i] |
| 615 | y_timestamp = y_timestamp_list[i] |
| 616 | |
| 617 | x_time_df = calc_time_stamps(x_timestamp) |
| 618 | y_time_df = calc_time_stamps(y_timestamp) |
| 619 |
no test coverage detected