Saturday, March 2, 2013

Wavy Shenanigans

Hello, it's me again. In the last post, I mentioned that the plot of Nasdaq prices against time appeared rather wave-like.

Here's that graph again, just to recap. :)


Looking at the graph, it appears that the Nasdaq prices crest and dip at regular intervals and thus possess  frequency and period like a wave. In fact, just by eyeballing it, I can guess that Nasdaq prices peak about every 100 days.

Using a Matlab function called "fft," which produces a one dimensional fast Fourier transform, I can determine if my guess is correct. Using this function, I can determine the dominant frequencies of the data, and thus, its periods. But before I employ the fft function, I need to "detrend" my data by subtracting its average from every point, thus centering my new graph at y=0. 

Here's a comparison of what the data looks like before and after detrending:


Now, we can use fft:


And get this graph:


After zooming in, it becomes apparent that the dominant frequency in the Nasdaq data is about 0.0085, which means its period (1/frequency), is about 118 days. This means that on average, the price of Nasdaq dips and peaks every 118 days. How exciting!

It's fascinating how periodic these prices are. I wonder why this is the case...

Well, that's all for now. See you next time!

3 comments: