Saturday, March 23, 2013

Backtracking

Though over the past year, the indices I've worked with seem to all have a dominant period of 128 days, this period may not hold true for a longer period of time. After all, markets as a whole also undergo trends. Keeping this in mind, let's take a look at what happens when I analyze the 5 year historical price data of the Nasdaq Composite index...

As before, here's the graph of its prices, this time spanning a greater length of time:



And the graph of its frequency content:


But instead of getting a period of 128 days, the period of this data is actually closer to 341 days. Hmmm...



Friday, March 22, 2013

I'm Back!

Hello everyone, Lu's back! It's been a while. After a refreshing week indulging in sleep and food, I'm ready to return to work. Hopefully, for those of you who had them, your spring break was enjoyable, too.

To refresh all our minds, allow me to briefly summarize what I've blogged about in the last few weeks. After acquainting myself thoroughly with the Matlab software by using it to solve problems such as how to create magic matrices, I've acquired historical data for several stock indices, and again using Matlab, have determined that based on the last year, these indices' prices all varied with a period of about 128 days.

Now, while many people use these indices to help them make investment decisions and track the condition of the stock market, the ways in which such indices are derived are not necessarily common knowledge.

Let's take a look at how one such index, the Dow Jones Industrial Average, is calculated.

The Dow Jones Industrial Average is calculated from the prices of 30 of the largest and most held public companies in the United States. When the index was first created, the stock prices were simply added up and divided by the number of stocks included in the index. Today, the method is a little more complicated.

Today, the DJIA incorporates what's known as the Dow divisor, a constantly changing number that accounts for events like stock splits. To calculate the DJIA, one simply adds up the prices of the 30 companies and divides by the Dow divisor, thus getting a number reflective of how large corporations are performing in the stock market. Furthermore, to find how much changes in a specific stock affects the index, one can divide the change in stock value by the Dow divisor, yielding the percent change in the index that stock is responsible for.

Pretty cool, no?


Saturday, March 9, 2013

Twice Is A Coincidence, But What About Three Times?

Happy weekend, everyone. Are you excited for Spring Break next week? I know I am. I'm looking forward to a long, relaxing week with plenty of time for sleeping...even though I do a lot of that anyway nowadays. :) That's right, next week, I won't be updating this blog. But don't worry, I'll be back the following week!

Ahem. Ok, back to the point of this post. Yesterday, I showed that the price data for Nasdaq over the past year has a dominant period of about 128 days. That led me to wonder what the periods of other indices' prices were. So, over the course of the week, I analyzed two other indices: the Dow Jones Industrial Average, and the S&P 500, in the same manner.

First the Dow Jones, an index that measures how large, public U.S. companies have traded during a standard trading session. (Ticker Symbol: DJI) It is influenced not only by economic and corporate reports, but by domestic and foreign policy issues. Its components trade on both the NYSE Euronext and the NASDAQ OMX stock markets.

Here's the graph of its past year prices:


And from this data, I can find its period to be 128 days, just like Nasdaq's. Um, alright.

Moving on, I do the same for the S&P 500, which measures the market capitalizations of 500 leading companies publicly traded in U.S. stock markets. It covers about 75% of U.S. equities and is considered by many to be the best representation of the welfare of the U.S. economy. 

Its graph:


And its period turns out to be...128 days again! 

Hmm, so the Nasdaq Composite, DJ Industrial Average, and S&P 500 all have the same period? Coincidence? I think not!




Friday, March 8, 2013

Closer Approximation

Hello everyone!

To recap, last week I plotted the prices of the Nasdaq index against time and attempted to determine the period of these prices, which I approximated to 118 days. But after all the effort of plotting, detrending, and graphing dominant frequencies, it seemed silly to find just an approximation of the period. I decided to go ahead and find the (more or less) exact period for Nasdaq.

As you may recall, this is the graph of the Nasdaq's frequency content:


Now, instead of zooming in and finding an approximate value for the frequency, I'll include a bit of code in my m-file that finds the exact dominant frequency and period. Here it is:

And when I run the file in Matlab, in addition to the graphs, I get:

xmax =
    0.0078
dompdnasdaq =
   128


This means that the period of Nasdaq is actually much closer to 128 days than my previous guess of 118 days according to the data I used. It'd be interesting to see if this period remains consistent over a longer period of time, like 5 or 10 years...or what the period of other stock indices are...

Well, until next time! See you soon!

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!

Thursday, February 28, 2013

I've Been Plotting...

...to plot some plots! In Matlab!

Hello again. As alluded to in last week's post, I've been researching the stock market and its indices this week. In hopes of analyzing trends in index prices that might aid me in predicting their future, I've downloaded historical data for indices such as the Dow Jones Industrial Average and the Nasdaq Composite.

Also as promised, I've reunited with Matlab. Beyond programming and matrices, Matlab also has significant graphing and graph analysis capabilities. By converting the data I'd downloaded into text files, I was able to upload them into Matlab, where they could be graphed. Read ahead, and I'll show you how using Nasdaq Composite data as an example. :)

Before that, I'd like to start with a little background about the Nasdaq Composite. One of the most highly followed stock market indices in the United States, the Nasdaq Composite functions as an indicator of the performance of technology and growth companies. It includes common stocks and similar securities that appear on the NASDAQ stock market, amounting to over 3000 components. Its ticker symbol is IXIC.

Right then. Here's how I loaded its data into Matlab:


>> cd nasdaq
>> ls

.           ..          NASDAQ.txt

>> data=load('nasdaq.txt');

The historical data for the Nasdaq Composite appears in Matlab as a 248x1 matrix. I can then graph this data against time, t, with single day intervals, like so:


>> t=(1:248);
>> plot(t,data)
>> grid

and get the following figure:



Looking at the graph, it appears that Nasdaq Composite prices vary in a somewhat wavelike manner. Therefore, it might be analyzed as such. More about that in the next post!


Saturday, February 23, 2013

Darling, Let's Not See Each Other For A While


As you've probably noticed, I've spent the last several weeks working quite extensively with Matlab. In fact, I've been spending so much time with Matlab that I think the flames of our once passionate love have simmered and died away! Really, it's probably a good idea for Matlab and me to take a break from each other.

Don't get me wrong; we had a great run. I have learned many useful things and have had great fun playing around in Matlab, as evidenced by the previous post. It's just that I want to take a small break from the programming and mathematics to touch upon other subjects relevant to this project. And fear not! Matlab and I will surely be reunited. After all, I will be using him a lot more in the (near!) future. This separation is merely temporary. 

So what have I been doing during this brief hiatus? Well, I thought it would be a good idea to learn more about the data I will be analyzing. In other words, I’ve been reading a lot about the stock market and how it works. Though this knowledge may not be directly relevant to the analysis I’ll be doing, since that will mainly involve spotting and modeling trends, I do think it is worthwhile to have. Why not try to understand what the things I want to analyze actually are?

All right, that’s all I have for today.

See ya next week!