Skip to content

Support for Business Days ('B' frequency) in Training and Prediction #3245

@LiPingYen

Description

@LiPingYen

Description

I would like to use business days ('B') as the time unit for both training and prediction in GluonTS. However, when I attempt to use 'B' as the frequency in my dataset and model configuration, I encounter repeated FutureWarnings, and the model fails to train properly.

Additionally:

  • When I set freq='B', the model fails to train properly.
  • When I change freq='D', the model trains without any issues.

To Reproduce

seed_everything(202402, workers=True)
test_dta = pd.read_csv('data/integrate_data.csv', parse_dates=True, index_col=0)

# Prepare single stock data
stock_id = '2330'
filtered_dta = test_dta.query("date >= '2019-12-01'").query(f"stock_id == {stock_id}")
date_new_index = pd.date_range(start=filtered_dta.index.min(), end=filtered_dta.index.max(), freq='B')
filtered_dta2 = filtered_dta.reindex(date_new_index)
stock_name = filtered_dta2.values[0][1]

freq = 'B' 
prediction_length = 14
context_length = 28
num_layers = 8
hidden_size = 64
batch_size = 128
num_batches_per_epoch = 5
max_epochs = 5

train = PandasDataset(filtered_dta2[:-prediction_length], target='stock_close_price', feat_dynamic_real=dynamic_features, freq=freq)
test = PandasDataset(filtered_dta2, target='stock_close_price', feat_dynamic_real=dynamic_features, freq=freq)

estimator = DeepAREstimator(
    freq=freq, 
    prediction_length=prediction_length, 
    context_length=context_length,
    num_layers=num_layers,
    hidden_size=hidden_size,
    batch_size=batch_size,
    num_batches_per_epoch=num_batches_per_epoch,
    distr_output=NormalOutput(),
    trainer_kwargs={'accelerator': 'mps', 'devices': 'auto', 'strategy': 'auto', 'callbacks': [RichProgressBar()], 'deterministic': True, 'max_epochs': max_epochs, 'log_every_n_steps': 100},
)
predictor = estimator.train(train)

Error message or code output

/Users/tayloryen/.local/share/virtualenvs/python_gluonts-OHlRrEvD/lib/python3.12/site-packages/gluonts/transform/feature.py:364: FutureWarning: Period with BDay freq is deprecated and will be removed in a future version. Use a DatetimeIndex with BDay freq instead.
  index = pd.period_range(start, periods=length, freq=start.freq)
/Users/tayloryen/.local/share/virtualenvs/python_gluonts-OHlRrEvD/lib/python3.12/site-packages/gluonts/transform/feature.py:364: FutureWarning: PeriodDtype[B] is deprecated and will be removed in a future version. Use a DatetimeIndex with freq='B' instead

Environment

  • Operating system: macOS 15.3.1
  • Python version: 3.12.8
  • GluonTS version: 0.16.0
  • pytorch-lightning version: 2.4.0
  • torch: 2.6.0

Expected Behavior

  • GluonTS should support business days ('B') as a valid frequency without warnings or errors.
  • The model should train and predict correctly when using 'B' as the time unit.

Request

Could you confirm whether GluonTS currently supports business day ('B') frequencies? If not, would it be possible to add support for this? Alternatively, is there a workaround to correctly handle business day frequency in training and prediction?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions