Comments (3)
The mean is jointly estimated with the variance parameters. If you want the exact in-sample mean, you would need to first demean the data using the rolling mean, and then fit a model with ZeroMean
. This would involve recreating the model for each sample.
If you use the fit
with first and last, then it will jointly estimate everything.
The fastest way is to use the previous fit values for starting values. Here is a demo:
import arch
from arch.data import sp500
import datetime as dt
r = 100 * sp500.load().iloc[:, -2].pct_change().dropna()
last_obs = 1100
now = dt.datetime.now()
for i in range(1000, last_obs):
res = arch.arch_model(r.iloc[i - 1000 : i]).fit(disp="off")
print(f"{(dt.datetime.now() - now).total_seconds()} (new model, no starting values)")
now = dt.datetime.now()
for i in range(1000, last_obs):
arch.arch_model(r).fit(disp="off", first_obs=i - 1000, last_obs=i)
print(f"{(dt.datetime.now() - now).total_seconds()} (no starting values)")
last = None
now = dt.datetime.now()
for i in range(1000, last_obs):
res = arch.arch_model(r.iloc[i - 1000 : i]).fit(disp="off", starting_values=last)
last = res.params
print(f"{(dt.datetime.now() - now).total_seconds()} (starting values)")
On my machine I see
1.941473 (new model, no starting values)
1.928971 (no starting values)
1.236577 (starting values)
One final option is to only occasionally update the parameters. This updates parameters every 10 observations. Otherwise it uses the last values.
last = None
now = dt.datetime.now()
for i in range(1000, last_obs):
mod = arch.arch_model(r.iloc[i - 1000 : i])
if i % 10 == 0 or last is None:
res = mod.fit(disp="off", starting_values=last)
last = res.params
mod.forecast(res.params, horizon=1)
print(
f"{(dt.datetime.now() - now).total_seconds()} (starting values, occasionally update)"
)
0.224142 (starting values, occasionally update)
from arch.
One final answer -- when using first_obs
and last_obs
, the parameters are estimated only using the selected sample.
from arch.
Thanks for your prompt response. All the above makes perfect sense to me.
I wonder if you think adding an argument to allow demean in the rolling basis is a good idea, i.e. fit(demean=True, ...)
passes the demean samples before fitting in the model. If so, I can create a PR for it.
from arch.
Related Issues (20)
- Issues with the 'rescale' parameter HOT 3
- Exogenous variable in the Volatility Equation HOT 1
- ENH: Add NGARCH specification to set of volatility processes
- Issue when using arch.bootstrap.MCS HOT 9
- My scratch implementation does not match the result for EGARCH HOT 1
- Tests fail: ImportError while loading conftest '/usr/ports/science/py-arch/work-py39/arch-6.1.0/arch/conftest.py'. HOT 3
- Probably bug in FIGARCH implementation with horizon > 1 HOT 1
- ModuleNotFoundError: No module named 'arch' when importing arch_model HOT 7
- add topic garch
- Clarification on `.simulated_variances` attribute of `ARCHModelForecast` object. HOT 3
- `arch_model` estimator is forecasting same value irrespective of the `horizon` parameter. HOT 2
- [DOC] Links to example notebooks for unit root tests and cointegration testing analysis HOT 1
- Are we using two-step approach for estimation? HOT 2
- Time series bootstrapping issues HOT 5
- volatility forecast in comparison with realized volatility HOT 3
- How to modify GARCH model to incorporate new terms ? HOT 1
- Source for Long Run Covariance Estimator
- There is no _version.py in arch.
- Details on Hansen's Skewed T
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arch.