You are on page 1of 6

Noise Removal of Trading Prices via Fourier Analysis

Aaron Ackbarali and Matthew McPartlon

Abstract
In this paper we present the MAMATH process for noise removal and demonstrate its validity when
applied to the stock market.

1. Introduction
Forecasting the stock market has been one of the great problems ever since the birth of the stock
market. One of the issues with predicting where a stocks trading price will be is that a great deal of the
data is simply noise induced by investor confidence, information asymmetries, market sector, and
trading volume.
We do not live in a world of perfect certainty, and the value of trading prices is often a
misrepresentation of the stocks current value. In order to paint a clearer picture of a stocks true value,
it is critical to reduce the distortion of ambiguous variables. In the world of trading, these variables are
identified as noise; the price data that distorts the picture of the underlying trend. A stocks price is
supposed to represent perfect information on that companies financial standing; however, things like
investor confidence, asymmetrical information, market sector, and trading volume are all external
factors that add noise to the price of a companies stock

2. The MAMATH Process


The Fourier transform has been the most widely used tool in signal analysis for the last century
and with good reason; it comes in many flavors each with something useful. For the MAMATH
process, the discrete Fourier cosine transform of the second kind(DCT-II)

1 #I
p 1
(1) F2 ({ur }rI ) =
#I
u
r =1
r cos
#I
r - ( s - 1)
2

and it's natural inverse (DCT-III)

1 n
p 1
( 3) F3 ({ur }rI ) = u
1
n
+ 2
r =2
ur cos ( r - 1) s -
n 2
( 4 ) F2 -1 = F3
are used. It is a well known fact that the DCT-II transform distributes the greatest amount of the signals
energy in each term. It is this fact and the discrete nature of the problem which are exploited.
The differential equation at the center of the MAMATH process,

n F3 {[ F2 ( S ) ] nI }
( 5) =0
n s n

may seem trivial and it is for a small number of data points. However it becomes extremely difficult to
solve when dealing with large data sets. The stock market moves in discrete units of one millisecond
thus the amount of data increases incredibly quickly. To actually perform noise removal in real time we
looked for a more computable solution. Interpolation over finite intervals by use of Lagrange
polynomials is just that solution. Lagrange polynomials were chosen because it is trivially simple to
compute their zeroes and they tend not to suffer from Runge's phenomenon, as Taylor polynomials do.

( 6) For distinct data points {( x0 , y0 ) ,K , ( x j , y j ) ,K , ( xk , yk )}


k
( 7 ) L ( x ) := y j l j ( x )
j =0

x - xm
(8)Where l j ( x ) :=
0 m< k x j - xm
m j

Figure 1. (left) The derivative of the Fourier series and the points used to generate the (center)
Lagrange polynomial and (right) the Taylor series

For n=1 the equation is


F3 {[ F2 ( S ) ] nI }
( 6) =0
s

For n=2 the equation is


2 F3 {[ F2 ( S ) ] nI } F3 {[ F2 ( S ) ] nI }
( 5) + =0
s 2 s

The two cases both reduce noise but differ in an interesting way. For low values of n it appears that the
amount of noise reduction increases as the number of derivatives taken increases. Our measure for
noise reduction is the variance measured in the data when the data is normalized against a 3rd degree
best fit polynomial calculated using a generalized least squares method. The following is a table
documenting the variance of several examples.

Data n=1 n=2 Data n=1 n=2


0.016306 0.013723 0.002634 0.695147 0.692049 0.661991
0.351998 0.337652 0.313789 0.771831 0.767788 0.743432
0.368998 0.35024 0.326789 1.09519 1.08348 1.06542
0.38579 0.355584 0.344283 1.5468 1.52975 1.51918

3. Data Analysis
The trading price for General Electric is in red, the noise reduction for n=1 is in blue, n=2 is in orange.
Figure 2: October 20th to November 11th of 2013

Figure 3. October 23rd to November 11th of 2012


Figure 4. October 22nd to November 20th of 2013

4. Conclusion
Although not investigated in this paper, an interesting case would be the alternative equation,
n F3 {[ F2 ( S )] nI }
( )
8 =0
n s n

Noise removal is one of the most important aspects of active trading. By employing noise-
removal techniques, traders can avoid false signals and get a clearer picture of an overall trend. With
high volatility in stock movements and a noisier market environment, formal technical analysis
indicators such as support and resistance levels can be misleading. To make more accurate stock
predictions, reducing noise in these markets is critical.

References
No references were used. Everything was constructed either from scratch or with the help of
Mathematica's help files.
5. Code

Data[a_,b_,g_,d_,e_,z_]:=Flatten[Delete[FinancialData["GE",{{a,b,g}, {d,e,z}}],Table[{n,1},
{n,1,Length[FinancialData["GE",{{a,b,g}, {d,e,z}}]],1}]]]

RegressionNormalized[DATA_]:=DATA-
With[{Len=Length[DATA],Lin=With[{F=DATA},Normal[NonlinearModelFit[F,a +b *x^2+c*x^3,
{a,b,c},x]]]},Table[Block[{x=n},Lin],{n,1,Len,1}]]

ApproximateNoiseReducedDataFull[DATA_]:=With[{B=Length[DATA]},With[{A=With[{S=Reverse[
With[{N=Block[{O=With[{data=FourierDCT[DATA]},
(Length[data]^(-1/2))*(First[data]+2*Sum[Part[data,r]*Cos[(p/Length[data])(r-1)(s-(1/2))],
{r,2,Length[data]}])]},
With[{h=With[{D=D[O,s]},
DeleteDuplicates[Round[Flatten[ParallelTable[Quiet[Select[x/.With[{f=InterpolatingPolynomial[Table
[{s,D},{s,n,n+.5,1/10}],x]},NSolve[f0,x,WorkingPrecision10]],n#n+.5&]],{n,0,B+1,.5}]],10.^-
10]]]},
Riffle[h,Block[{s=h},O]]]]},Block[{L=Length[N],K=Length[DATA]},With[{M=Flatten[Table[(Part[N
,2*n+2]-Part[N,2*n])/(Part[N,2*n+1]-Part[N,2*n-1])*(x-Part[N,2*n-1])+Part[N,2*n],{n,1,L/2-1,1}]]},
Union[{{Part[M,2],1x<Part[N,5]}},{{Last[M],Part[N,L-
2]xK}},Table[{Part[M,n],Part[N,2n-1]x<Part[N,2n+1]},{n,3,L/2-2,1}]]]]]
]},Piecewise[S]]},Table[Block[{x=n},A],{n,1,B}]]]

ApproximateNoiseReducedDataFull2[DATA_]:=With[{B=Length[DATA]},With[{A=With[{S=Revers
e[
With[{N=Block[{O=With[{data=FourierDCT[DATA]},
(Length[data]^(-1/2))*(First[data]+2*Sum[Part[data,r]*Cos[(p/Length[data])(r-1)(s-(1/2))],
{r,2,Length[data]}])]},
With[{h=With[{D=D[O,{s,2}]},
DeleteDuplicates[Round[Flatten[ParallelTable[Quiet[Select[x/.With[{f=InterpolatingPolynomial[Table
[{s,D},{s,n,n+.5,1/10}],x]},NSolve[f0,x,WorkingPrecision10]],n#n+.5&]],{n,0,B+1,.5}]],10.^-
10]]]},
Riffle[h,Block[{s=h},O]]]]},Block[{L=Length[N],K=Length[DATA]},With[{M=Flatten[Table[(Part[N
,2*n+2]-Part[N,2*n])/(Part[N,2*n+1]-Part[N,2*n-1])*(x-Part[N,2*n-1])+Part[N,2*n],{n,1,L/2-1,1}]]},
Union[{{Part[M,2],1x<Part[N,5]}},{{Last[M],Part[N,L-
2]xK}},Table[{Part[M,n],Part[N,2n-1]x<Part[N,2n+1]},{n,3,L/2-2,1}]]]]]
]},Piecewise[S]]},Table[Block[{x=n},A],{n,1,B}]]]

data[i_]:=Block[{m=Floor[12*Random[]]+1,n=Floor[28*Random[]]+1,o=Floor[12*Random[]]
+1,p=Floor[28*Random[]]+1},Data[2011,m,n,2012,o,p]]

Table[With[{H=data[1]},
{Variance[RegressionNormalized[H]],Variance[RegressionNormalized[ApproximateNoiseReducedDat
aFull[H]]],Variance[RegressionNormalized[ApproximateNoiseReducedDataFull2[H]]]}],{10}]