-
Notifications
You must be signed in to change notification settings - Fork 251
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
Rolling window forecast with rolling demean #633
Comments
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 If you use the 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
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)"
)
|
One final answer -- when using |
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. |
I saw in the documentation that rolling window forecast can be applied with parameter
first_obs
andlast_obs
, while I am looking for an approach with minimal runtime overhead toreturns[first_obs:last_obs] - mean(returns[first_obs:last_obs])
, andI wonder if the constant mean is applied on the rolling basis, or actually on the whole timeseries of argument
y
.I tried to look into the source code but could not conclude it in a glance. Could you help address it?
The text was updated successfully, but these errors were encountered: