Example 10 - Problem Description
Nonparametric smoothing and extrapolation using
daily closing price of General Electric from 1/02/2003 to 1/17/2006
O-Matrix source code for example 10
# Nonparametric smoothing and extrapolation.
# 1 data series: daily closing price of General Electric from 1/02/2003 to 1/17/2006
# Read the data
N = 765.
ge = read("data\ge0306.prn","double",N,1)
# Perform smoothing and forecasting (trend extrapolation) using three different bandwidths and
# the local linear method. Nonparametric smoothing using local linear regression is better than
# simple smoothing using a moving average since it has better properties near the boundaries of
# the time series
# Hold-out the last "fs" observations to extrapolate
fs = 20
gex = ge(1::end-fs)
[fit1,res] = npsmooth(gex,0.025,"local linear",fs,0)
[fit2,res] = npsmooth(gex,0.050,"local linear",fs,0)
[fit3,res] = npsmooth(gex,0.150,"local linear",fs,0)
# Plot the original series and the smoothed series
fit = [fit1,fit2,fit3]
# Plot the hold-out "fs" observations and the trend forecasts
# Now perform a rolling forecasting evaluation using a window of 250 observations (about one year)
# to predict the next 10 observations (two weeks) using a bandwidth that tracks both the series
# (short term forecasting)and the general trend (longer term forecasting). You can experiment by
# changing the default value of 0.025 in the function below.
fs = 10
R = 250.
T = N-R+1
f = zeros(T-fs,fs)
for i = 0 to T-fs-1 begin
xi = ge(i+1::R+i)
[fit,res] = npsmooth(xi,0.085,"local linear",fs,0)
f(i+1,:) = fit(end-fs+1::end)'
# Compute the forecast errors and the forecast error variance
y1 = [ge(R+1::end-fs+1),ge(R+2::end-fs+2),ge(R+3::end-fs+3),ge(R+4::end-fs+4),ge(R+5::end-fs+5)]
y2 = [ge(R+6::end-fs+6),ge(R+7::end-fs+7),ge(R+8::end-fs+8),ge(R+9::end-fs+9),ge(R+10::end-fs+10)]
y = [y1,y2]
print "Extrapolation model -- RMSE of the forecasts from 1 to 10 days ahead = "
# Compare the forecasting performance with the random walk (no change model)
frw = fillcols(ge(R::end-fs),fs)
print "Random walk model -- RMSE of the forecasts from 1 to 10 days ahead = "
print "Its very difficult to beat the random walk model!!!"
Output from running example 10