jdb78 / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
3.85k stars 609 forks source link

TFT and General questions #490

Open GabrielDeza opened 3 years ago

GabrielDeza commented 3 years ago

Hi,

I just found about this library after working with gluon-TS and this is really cool! My problem setting for my thesis project requires unknown real features which surprisingly is not supported in most other libraries (GluonTS). As I have only used this library for the past week, I have a couple questions: Background: my data is the daily difference in open and close price of a stock (ie: TESLA) and I have collected 15 features that are derived from twitter (ie: number of tweets, positive sentiment etc). In total I have 5 years of data which is 1306 days accounting for markets being closed on weekends. Using the stallion tutorial, I was able to create a dataset as follows:

training = TimeSeriesDataSet(
    data[lambda x: x.time_idx <= training_cutoff],
    time_idx="time_idx",
    target="diff", #difference in open and close price
    group_ids=["company"], #
    min_encoder_length=5,  # keep encoder length long (as it is in the validation set)
    max_encoder_length=5,
    min_prediction_length=5,
    max_prediction_length=5,
    static_categoricals=["company"],
    static_reals=[],
    #time_varying_known_categoricals=[],
    time_varying_known_reals=["time_idx"],
    time_varying_unknown_categoricals=[],
    time_varying_unknown_reals=[the 15 twitter features])
  1. Is TFT the best model for my problem statement? Although I am able to train TFT, the results are not that good (just a flat constant prediction).

  2. Is TFT the only model that allows time_varying_unknown_reals? I saw here that you mentioned DeepAR could be used but I didn't fully understand the transformation mentioned.

  3. Should/are features and targets scaled? I know there is an option to pass in scalers but was wondering if it was necessary and if so how they should be scaled (both targets and features).

  4. In my case, I would like to train a model with a short prediction length (ie: 3~5 days) but validate my results over a window of 50 days. Although I could not find functionality to perform a rolling set, is it possible to do it manually by just recreating a validation set that is slightly longer every rolling set?

  5. The tutorials mentioned that the group scalar made everything positive. Was this important?

  6. Since my scenario has 1 group (ie: they are all the same company, Tesla), my "company" column is all the same. Is this the correct way to do so?

Thank you for answering any of my questions, this library offers so much functionality that I am getting a little overwhelmed trying to understand every argument to get sensible forecasts.

jdb78 commented 3 years ago
  1. Add the target to the unkown reals. Stock market prediction is hard, and maybe you have no good signal.
  2. ?
  3. You can use unknown reals if they are lagged properly turning them into known reals for other algorithms such as DeepAR.
  4. There will be auto-scaling. Use an explicit target_normalizer to gain more control. Your time series are on different levels and definitely require scaling.
  5. Use a max_prediction_length of 50. The dataset is rolling by default. I would train the same way as I validate but you can pass the same arguments to from_dataset as you pass to the init method, i.e. pass a different max_prediction_length.
  6. You bias the model in the right direction. There are no negative stock prices.
  7. Yes. But really doubt deep learning will do the trick for such a small dataset for you.