Author: Marcelo Scherer Perlin.
UFRGS – University of Rio Grande do Sul, Brazil.
Graduate Business School, Department of Finance.
1. Description of the Nearest Neighbor Algorithm.
The nearest neighbor method is defined as a non-parametric class of regression. Its main idea
is that the series copies its own behavior along the time. In other words, past pieces of
information on the series have symmetry with the last information available before the
observation on t+1. Such way of capturing the pattern on the times series behavior is the main
argument for the similarity between NN algorithm and the graphical part of technical analysis,
charting.
The way the NN works is very different than the popular ARIMA model. The ARIMA
modeling philosophy is to capture a statistical pattern between the locations of the
observations in time. For the NN, such location is not important, since the objective of the
algorithm is to locate similar pieces of information, independently of their location in time.
Behind all the mathematical formality, the main idea of the NN approach is to capture a non-
linear dynamic of self-similarity on the series, which is similar to the fractal dynamic of a
chaotic time series.
Next will be described the way the NN works. For a detailed view of the process, the papers
of Farmer e Sidorowich (1987) and Fernández-Rodríguez et al (1997) are indicated.
1.1 The Univariate Nearest Neighbor (method=correlation)
The univariate case for the NN algorithm works with the following steps:
1) The first step is to define a starting training period and divide such period on different
vectors (pieces)
m
t
y
of size m, where
,...,
t m T
=
. The value of T is the number of
observation on the training period. The term m is also defined as the embedding
dimension of the time series. For notation purposes, the last vector available before the
observation to be forecasted will be called
m
T
y
, and the other pieces will be addressed as
m
i
y
.
2) The second step is to select k pieces most similar to
m
T
y
. For the method of correlation, in a
formal notation, it is searched the k pieces with the highest value of
ρ
, which represents
the absolute (euclidian) correlation between
m
i
y
and
m
T
y
. The only difference between the
univariate and the multivariate case is on this step: the way that is going to be searched for
the k pieces with highest symmetry with
m
T
y
.
3) With the k pieces on hand, each one with m observations, is necessary to understand in
which way the k vectors can be used to construct the forecast on t+1. Several ways can be
employed here, including the use of an average or of a tricube function, Fernández-
Rodríguez et al (2002). The method chosen for this case of the function is the one used on