Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using statsmodels ARMAResults as a mean model #101

Closed
Anjum48 opened this issue Oct 30, 2015 · 12 comments
Closed

Using statsmodels ARMAResults as a mean model #101

Anjum48 opened this issue Oct 30, 2015 · 12 comments

Comments

@Anjum48
Copy link

Anjum48 commented Oct 30, 2015

Is it possible to use ARMAResults calculated using statsmodels as a mean model so that a volatility process can be added?

I wasn't sure how this might work but I was thinking of something along the lines of this:

from arch.univariate.mean import ARCHModel
from arch.univariate import ARCH

model = ARCHModel(returns)
model.mean = arma_res  # statsmodels ARMAResults
model.volatility = ARCH()

results = model.fit(update_freq=5)
@timseries
Copy link

I think this would be very useful functionality.

@KenMbuthia
Copy link

I too second this idea.

However this could be that we have a fundamental misunderstanding on how ARCH model works? However in my understanding it would be best to first estimate the ARMA parameters then use them in GARCH.

I too have struggled with trying to set the mean model for GARCH using this module with the objective of building a GARCH model from its componets as described at http://arch.readthedocs.org/en/latest/univariate/univariate_volatility_modeling.html#building-a-model-from-components . Is it that we do not understand how to specify the mean model with prior estimated ARMA parameters? If this is the case then a step by step example on how this could be achieved could be added in the examples. Going through the examples at http://arch.readthedocs.org/en/latest/univariate/mean.html it is not clear on how one could achieve this or if it is currently possible. This would be highly appreciated and guide us on the path of better understanding this module.

Hoping not to go out of bounds, my main motivation for the above request is based on trying to replicate the results from https://www.quantstart.com/articles/ARIMA-GARCH-Trading-Strategy-on-the-SP500-Stock-Market-Index-Using-R . The Series by M. Halls Moore is quite a wonderful and interesting guide on how to practically apply time series analysis. So far in following the series, I have been able to follow along using statsmodels. However, the series is implemented using R and I have a preference for python so switching though possible, is not preferable. I have found this package to be the most up to date and best in terms of GARCH models. Statsmodels has garch though it is still in sandbox and there seems like some methods have yet to be implemented. Another solution would be to use r2py for using r packages but I still have preference to python.

I hope, you would consider this request and that also this is the appropriate place to place this requests.

@timseries
Copy link

I was thinking more along the lines of generating a one-liner prediction function using the ARFIMA-GARCH recurrence equations so that the mean process and confidence interval around the mean process could be forecast in one go.

@Anjum48
Copy link
Author

Anjum48 commented Feb 25, 2016

@KenMbuthia I was also following the Quantstart article in Python like yourself. I managed to get pretty far using statsmodels, but hit a road block soon as it got to using GARCH. I think arch is a brilliant package for it's simplicity but I think it would be even better it it played nice with the tsa components of statsmodels. I think I started writing a mean model class, but unfortunately didn't get very far before switching to R

@bashtage
Copy link
Owner

statsmodels's ARMA code is unfortunately too bespoke to statsmodels to be generally useful.

This said, one can always use 2-step estimation where:

  1. Fit ARMA(X) model and get residuals
  2. Fit a GARCH model with no mean to get variances.

@b3yang
Copy link

b3yang commented Mar 30, 2016

like what @bashtage has suggested, think it can be done by something like this (spx shown below on ARMA(1,1) with GARCH(1,1))

    _arma_model = sm.tsa.arima_model.ARMA(input_ts, (1,1))
    _model_result = _arma_model.fit()
    arch_model(_model_result.resid, mean='Zero', p=1, q=1)

image

@b3yang
Copy link

b3yang commented Mar 30, 2016

for forecasting though, how would you incorporate the forecasted variance into the mean model?
my guess would be something like append to resid then use _arma_predict_out_of_sample, do any of you see a problem here?

@bashtage
Copy link
Owner

I think it isn't likely that the two can be formally combined, so either 2 step estimation as described above or one can use a AR(p) process to approximate an ARMA model of any order.

@ramdhan1989
Copy link

like what @bashtage has suggested, think it can be done by something like this (spx shown below on ARMA(1,1) with GARCH(1,1))

    _arma_model = sm.tsa.arima_model.ARMA(input_ts, (1,1))
    _model_result = _arma_model.fit()
    arch_model(_model_result.resid, mean='Zero', p=1, q=1)

image

I try this but arch return zero if specify mean='zero'

@bashtage
Copy link
Owner

What do you mean returns zero?

@olofahlen
Copy link

@bashtage You said statsmodels is too bespoke. If my goal is to specify an ARIMA model for the conditional mean by inheriting arch.univariate.base.ARCHModel and implementing the methods, do you have any comments on how well this might work by wrapping the relevant class from statsmodels? Are you aware of anyone who might already have done this?

@bashtage
Copy link
Owner

Wrapping wouldn't require delving into the inner working of statsmodels, so it should theoretically be possible. I think one woucl wrap ARIMA and use the mean parameters to generate residuals, and then residuals to estimate volatility, and return the log-likelihood of these. This is a good idea and would be a welcome contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants