Apply model to new data?

Open
#605 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python

Research direction

The thread is a usage question about applying a fitted GARCH model to new data via arch_model, .fit, and .forecast (including the params= argument). Read the forecast method and any docs on bootstrap forecasts and exogenous x. Reproduce the snippet that yields different self.fcst vs test_fcst, then decide whether the API already supports out-of-sample application or needs a documented/params fix. Done means a clear answer or a small API/docs change that makes applying a fitted model to new series unambiguous.

Written by the indexing model from the issue text.

Description

I was wondering if there's a way to create a model and then apply it to new data.

What I'm trying to do is: bootstrap data, create/fit model for a bootstrap, apply that model to original data. At first I thought maybe the new data could be passed in to "forecast" as it is in some other python packages, but I didn't see anything in the docs for that.

I did see that params can be passed in and so I'm wondering if that's the correct approach. How I was visualizing that is: bootstrap data, create/fit model, create/fit a new model and then forecast with that model but pass the original params. This seems a little convoluted since I'm not sure why I'd need to fit the new model conceptually, but since .forecast is a method on .fit and it seems necessary there.

I tried to build up to seeing if the params approach would work, but I'm running into an issue. I'll share the general idea/code here to see if that sheds light on anything obvious, but if not I can create a full example too. Basically I was creating/fitting a model and then forecasting with it (not on other data, just on the same data), which gave me a set of parameters and forecasts. I then re-attempted the forecast and set the params to be the same as the original model, but was getting different forecast values (everything else was kept the same).

Below I'm getting different values for self.fcst and test_fcst:

   # Run the model
    garch_model = arch_model(self.depen_data, x=self.indep_data, mean=mean, vol="Garch",
                             p=p, o=o, q=q, power=power, dist=dist)
    self.res = garch_model.fit()
    params = self.res.params

    # create forecast
    predict_length = self.horizon + self.lag
    self.fcst = self.res.forecast(horizon=predict_length,
                                  method="bootstrap", reindex=False, x=self.fcst_indep_data)
    test_fcst = self.res.forecast(params=params, horizon=predict_length,
                                  method="bootstrap", reindex=False, x=self.fcst_indep_data)

So my question is whether either of these approaches (or any other pre-existing approach) is correct and, if the params approach is correct, whether someone has insight on what I'm doing wrong.

Dominant language
Python
Stars
1.6k
Forks
298
Avg merge
14h 46m
Merged PRs (30d)
106

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bashtage/arch

All issues in bashtage/arch

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.