Stocks Useless Stuff

Markowitz and Me

Setting the Stage

When I was graduating high school, my dad had a moment of genius. He gave me a small amount of money to open a brokerage account to start investing in the stock market. Even though the amount of money was small (maybe $1000), I was given a valuable opportunity to jump in and learn a lot about investing, without much at stake.

Back in 1998, I invested in a small number of stocks. I didn’t have a real strategy other than I wanted to invest in companies I liked and that I felt would continue to grow in the future. Most of my decisions were based on qualitative reasoning. For example, in the late 90’s, the internet was just emerging as the huge success it is today. I chose to invest in FedEx because I believed that more people were going to buy stuff online rather than traditional brick-and-mortar stores and all that stuff would need to be shipped by either UPS, FedEx, or the Post Office. The growth of China was also constantly in the news so I thought that Caterpillar (CAT) would prosper due to all the construction equipment they would be selling to China as the country developed its infrastructure. That was the degree of thought that led me to buy these particular stocks.

Around that time, I bought the following stocks. As I’ve always taken a buy-and-hold approach, I still own most of these stocks today. For the most part, I split my initial investment evenly between these five stocks.

Caterpillar, CAT
FedEx, FDX
Microsoft, MSFT
Barnes and Noble, BKS

For the past month or two, I’ve been taking an online course from the University of Washington titled Introduction to Computational Finance and Financial Econometrics. I’ve learned a ton in the past 9 weeks from both the lectures and the programming exercises in R. After taking this class on computational finance, I thought it would be interesting to compare the results of that initial portfolio with what could have been achieved using the Markowitz theory and the assumption of constant expected returns.  Essentially, the goal is to determine the optimal mix of a given set of stocks to minimize the amount of risk you are taking to achieve a given return. The crazy thing is that even after all this high-level analysis, there is no guarantee that you would be better than just dumping your money in an index fund or selecting some random mixture of the stocks.

How did the original portfolio perform over the past 16 years?

The following chart shows how much $1 invested in the summer of 1998 is worth today (end of October 2014). For example, $1 invested in CAT in 1998 is now worth approximately $5.75. Alternatively, 1$ invested in BKS is only worth about $1 today. With that $1000 investment split evenly between these 5 stocks, the current value of that portfolio would be $3969.  For comparison, the same money invested in the S&P 500 would be worth $2308. Ironically, this portfolio would have significantly outperformed the S&P500, although I am confident this was simple luck, nothing more.


If it was 1998, what would be the global minimum variance portfolio?

The minimum variance portfolio is the mixture of stocks that is predicted to be the least risky. To calculate the MVP, we need to figure out some statistics of the stocks. We will use the data from 1993-1998 to quantify the statistics. The average and variance of monthly returns for these five stocks are shown below.

Mean 0.0196 0.0145 0.0416 0.0152 0.0199
Variance 0.0046 0.0063 0.0065 0.0028 0.0096

Using these statistics, we can determine the global minimum variance portfolio – the mixture of stocks that have the lowest risk based on the statistics from the past five years. The weights of each stock in the global minimum variance portfolio are shown graphically below. The predicted performance of this portfolio was 1.7% per month with a standard deviation of 3.9% per month.

global_min_varWhat would be the efficient portfolio for these stocks?

The efficient frontier is the maximum expected return you can expect to achieve for a given risk level, as measured with the portfolio standard deviation. The global minimum variance portfolio is the left-most point on the efficient frontier shown below. As you can see, there are other options along the efficient frontier with greater potential returns but with greater risk (x-axis). The exact portfolio you choose is basically determined by your risk tolerance. If you don’t mind taking on more risk, you can potentially get much larger returns. When all said is done, because the stock returns are all over the place, even the efficient frontier has a lot of uncertainty.EfficientFrontierHow would the global minimum variance portfolio would have performed since 1998?

The global minimum variance portfolio would increase from $1000 to $4911, which is much better than both my equally weighted stock portfolio ($3970) and the S&P500 ($2308).  Recall that the global minimum variance portfolio was intended to represent the least risk although it did amazingly well over that 16 year time horizon. I admit that 16 year time horizon is probably longer than typical but these are definitely nice results. With that being said, I’m still going to be piling all my savings into index ETFs.



Finance Personal Finance

Savings Rate

YenI’m a personal finance junky. I have always been amazed by the power of compounding.  After starting my first real job, I’ve been trying to save a lot of money. I think my primary motivation is to gain financial independence. To me, financial independence means being able to work and pursue various dreams with no fear of living without a regular paycheck. Of course, it may be a while before I can actually become independent.

Starting a few months ago, I took steps to make my savings more automatic: (1) I increased my 401(k) contribution and (2) setup direct deposit to send a percentage of my paycheck to my savings account. These two automatic methods insure I save at least 32%. With all savings contributed the past two months, I am averaging a 39% savings rate based on my pre-tax salary. As I was paying for some trips during this time (Montana and Virginia), I believe I can do better if I should travel less. With two more trips planned in October, there’s no sign of abating travel expenditures.

Programming Stocks

Downloading Stock Data in C#

I wanted to access stock price data in C#. As I typically use Yahoo Finance for my stock research, the obvious answer was to use the historical prices available on the Yahoo Finance site. If you look in the screenshot below, Yahoo provides a link to a comma-separated value file with date, open, high, low, close, and adjusted close.


If you look closely at the actual hyper-link, you will notice several attributes we can adjust. These attributes are highlighted for clarity:

  • Purple indicates the stock ticker. In this example, the stock ticker is the S&P500 index (^GSPC). %5E represents the carrot character.
  • Red indicates the start date of the stock price data.
  • Blue is the end date of the stock price data.
  • Green indicates the frequency of data (d=daily, w=weekly, and m=monthly)

In this example, we would get daily (d) stock data for the S&P500 between January 3, 1950 (Month:0, Day:3, Year:1950) and August 28, 2009 (Month: 7, Day: 28, Year:2009). One thing to notice is the month is zero-based – that is, January is 0, February is 1, etc.

Now to the C# code. The first step is to generate the link as shown. I created the following group of controls on a form.

I first get the values from the controls:
// Import IVV Price Data
string ticker = this.tbTicker.Text;
DateTime startDate = this.dtpStart.Value;
DateTime endDate = this.dtpEnd.Value;

The next step is to build the URL string. The value of the start and end months are reduced by 1 to account for the zero based month required by the Yahoo Finance URL.
int startMonth = startDate.Month - 1;
int endMonth = endDate.Month - 1;
string theURL = @"" + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

The next step is to create an HttpWebRequest and HttpWebResponse to download the data from Yahoo Finance.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

We build a string using the StringBuilder class from the HttpWebResponse.

Stream resStream = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
string tempString = null;
int count = 0;

count = resStream.Read(buf, 0, buf.Length);

if (count != 0)
tempString = Encoding.ASCII.GetString(buf, 0, count);



while(count > 0);

Now we have all the data in a string format. The following code dumps the data in the StringBuilder sb into a long data string. We then split that string at every newline character (/n) resulting in an array of strings called data2. We then create a variety of arrays for all of the downloaded data. We set the length of each array based on the number of strings in the data2 array. The data2.Length-2 accounts for the header and end of file strings that are in the data2 array.

string data = sb.ToString();
String[] data2 = data.Split('n');
int iteration = 0;
dates = new DateTime[data2.Length - 2];
open = new double[data2.Length - 2];
high = new double[data2.Length - 2];
low = new double[data2.Length - 2];
close = new double[data2.Length - 2];
volume = new double[data2.Length - 2];
adjClose = new double[data2.Length - 2];

For the next step, we iterate through the data2 array. We split each string by the commas and populate the arrays.

foreach (string strLine in data2)
String[] entries = strLine.Split(',');
if ((iteration != 0) && (entries[0] != ""))
dates[iteration - 1] = System.Convert.ToDateTime(entries[0]);
open[iteration - 1] = System.Convert.ToDouble(entries[1]);
high[iteration - 1] = System.Convert.ToDouble(entries[2]);
low[iteration - 1] = System.Convert.ToDouble(entries[3]);
close[iteration - 1] = System.Convert.ToDouble(entries[4]);
volume[iteration - 1] = System.Convert.ToDouble(entries[5]);
adjClose[iteration - 1] = System.Convert.ToDouble(entries[6]);
iteration = iteration + 1;

And that’s it! We now have a whole bunch of price stock data ripe for analysis – thanks to Yahoo Finance.


Mint – An Awesome Online Financial Tool

About 10 months ago I created an account on Mint is free online software for:

(1) Tracking your expenses
(2) Creating a budget
(3) Monitoring your investments (stocks, IRAs, etc)

Mint tracks your expenses by logging into to all of your online accounts and recording all of the data. If you are worried about the security of your accounts, Mint gives excellent descriptions on their website on how your data is secure. After accessing your data, Mint attempts to classify each transaction. In general, this classification is really accurate. If it sees a transaction called “Chipotle”, it classifies that transaction as “Fast Food.” Sometimes you have to classify the transactions yourself but Mint also allows you to make specific rules such that everytime a transaction says “City of Tucson” it knows to classify that as “Utilities”.

Mint can then use this data to do some nifty things. For example, Mint monitors various aspects of your expenses and creates suggestions for ways to save more money. For example, Mint may suggest switching to a credit card with a lower interest rate (I believe this is one of the ways Mint makes money). You can compare your monthly grocery bill to the average bill in a specific U.S. city. Although Mint pretty much calculates everything you would want to know, you can also export all your data into an excel compatible file (.csv).


A cure to the housing woes

Downsizing the American Home

In this Yahoo! Finance article, Shawn Tulley describes how first time homebuyers were priced out of the market during the housing boom. Homebuilders started catering to people who wanted larger and fancier houses. At some point, the houses became so expensive it just made sense for potential first time home buyers to simply rent.

Then the bubble burst. Less people were willing to buy these super-sized houses (often called McMansions) from the housing bubble. Homebuilders recognized this and have started to build small and simple homes that would appeal to the first-time homebuyers who could not afford a house during the bubble.

Three factors are driving the New Affordability: housing prices, house size, and the government’s expanding role in the mortgage market.

Finance Photos

A Trip Through Southern Utah

For Christmas, I joined my family in Estes Park, Colorado. This is a little mountain town just outside the entrance to the Rocky Mountain National Park. For the ride back to Tucson, I traveled through Southern Utah and stopped at Arches National Park. The Delicate Arch, pictured below, is one of the most photographed landscapes in Utah. I did the 3 mile hike with my huge tripod and snapped several pictures. It was beautiful and I got to photograph the Arch will no crowds.

The Delicate Arch


Caterpillar Valuation

Back in February, I performed an analysis of Caterpillar stock. Nine months ago, I felt that Caterpillar was relatively undervalued. Wall Street was concerned with the slowdown in housing, construction, and truck engines. Today, I am going to go through the valuation numbers again to see how Caterpillar stacks up.

First, let’s look at the historical PE ratio. The following numbers were taken from Morningstar. These PE ratios are also compared to the CAT stock price in the chart below.


















In what seems somewhat counter-intuitive, the PE ratio has often decreased as the price of the stock increased. You would think that as price increased, the PE would also increase. However, this seems to suggest that when the price grew in 2005 and 2006, CATs earnings per share grew even faster driving down the PE ratio. That is, the price (numerator) increased but the earnings (denominator) increased even more resulting in a smaller PE ratio.

Why is this happening? Are earnings really growing? Could the earnings per share be artificially lower due to stock buybacks? If the company buys back its stock, there’s less stocks so the earnings per share increases, which decreases the price to earnings ratio. Let’s check that out. Two graphs are shown below that show the net income and total number of shares.

As you can see, there are less shares in 2006 and 2007. From 2005 to 2006, the number of shares decreased by 3.1%. If the 2005 and 2006 earnings were the same, this share buyback should reduce the PE ratio by 3.1%. The PE ratio for 2006 was much smaller than this 3.1% decrease suggesting that the improvement in PE ratio was primarily associated with increases in the net income.

Similarly, for 2006 and the past twelve trailing months (labeled 2007), the number of stocks decreased by 0.4%. The PE ratio should decrease by the same amount. However, the PE ratio actually increased from 11.9 to 15.8. As you can see in the net income chart, a part of this increase is associated with a drop in earnings (net income).

I need to look into these numbers a little further. Why this decrease in net income? Can CAT expect greater earnings in the remaining months of this year? Is the greater PE ratio a big concern? Does it indicate that CAT is finally becoming overvalued? There’s much more analysis to do. Particularly, I would like to get an estimate EPS for 2007 and base the PE ratio off of that number. Second, I would like to compare CAT’s valuation to its nearest competitors. Tune in for that analysis later.


More Research

I’ve been doing more research on I was impressed this morning when a prosper employee called to give me an introduction to the website including how to search for listings and set standing orders.

With that being said, I’ve also been looking into what other people are saying about Prosper. I can’t get a particular feel for how many lenders are pro-prosper and how many are anti-prosper. There was some buzz regarding an advertisement Propser created saying it outperformed the S&P500. An analysis by Mike at Prosperous Land showed that this was questionable advertising. In fact, the S&P500 significantly outperformed the given Prosper data. This blog entry tells a story of fraud of a Prosper borrower. I want to continue doing some research but I am losing confidence. My money might be better in an index fund.


Today, I’ve spent a few hours researching a loan service provided by The goal of this company is to create a community where lenders can be matched to borrowers. I am interested in the lending service of the website. Although the website calls you a lender, what you really do is purchase the loan from is the actual entity that loans the money to the borrower. Here’s a Washington Post article and a Wall Street Journal article about

So how do you lend money on The website has some excellent tutorials on how you lend money. Like any other online account, you transfer money from your checking or savings account to Once the money is in your account, you can then bid on potential borrowers based on their credit histories and other related measures such as their debt-to-income (DTI) ratio. If the interest you bid is one of the lowest, you win and purchase your portion of the loan. The borrower gets the money and pays you back plus interest, just like a normal loan. The standard length is a 3-year loan. The only catch is extracts 0.5-1.0% in the form of servicing fees and there’s an inherent risk that the borrower will not pay you back. Another risk worth mentioning is fraud. As this is a new technology, many experts are worried about the potential for fraud. However, will buy back loans that were taken due to identity fraud.

The nice thing is that you don’t have to risk all of your money on one borrower. Instead, you can diversify and reduce your risk by purchasing small portions of loans from many people. I believe the minimum purchase amount is $50.

The rate of returns are decent too. Here’s a breakdown of return on investment after accounting for the service fee and defaults. These were from the website (as of August 26, 2007)

Borrowers with

  • AA credit scores: 9.39%
  • A credit scores: 10.23%
  • B credit scores: 10.81%
  • C credit scores: 11.13%
  • D credit scores: 10.79%
  • E credit scores: 13.19%
  • HR credit scores: not enough data

I’m going to try out this service with a small initial investment. With new investments, my strategy is to spend an amount of money that I am comfortable losing. From my perspective, if everything goes wrong, an investment of $1000 would be equivalent to buying a HDTV or some other gadget whose value depreciate rapidly after purchase. Of course, I don’t think that is going to happen but that’s how I prepare myself before trying any investment. I’ll add updates to the blog as I start using

If this service is catching your attention, either as a borrower or as a lender, please check out the website. Although my intention is not to promote or advertise for the site, if you want to try, they have a referral service. By going to this link,, or clicking the image below, both you and I can get $25 if you sign up as a lender.

Great Rates, No Banks. Borrow. Lend. Prosper.


Good Online Financial Reading

Four tips for riding a seesaw market by Laura Rowley
One of the best ways to handle market volatility is to have a good investment strategy – to understand that successful investing is based on the long-term gains of the market. Remaining focused on this idea, you should be less susceptible to irrational fear.

I just don’t want to be one of those people who buy stocks with unbridled enthusiasm when the stock market is doing well but sell out when stock prices decline. Logically, that’s the worst thing you could do. The slogan is not buy high and sell low – it’s buy low and sell high. Smart people can be stupid investors when they let irrational emotions rather than intelligence guide their decisions.

Nobody knows what’s going to happen in the future, but studies based on the past performance of the S&P 500 have found that since 1925, the chance of losing money over a year is 28 percent; over 5 years, 10 percent; over 10 years, 3 percent; and over 20 years, 0 percent.

Get off the spending treadmill by MP Dunleavey
Living below your means seems to be a crucial element in accumulating investments. If you spend so much money that you can’t invest, you will never have money work for you via the mechanism of compounding. In this article, Dunleavey discusses the temptation to spend money to keep up appearances with your peers. As mentioned in this article, several people have taken frugality to the extreme to break out of this spending spree.

Some of her suggestions are fairly obvious. Don’t be greedy and jealous. Don’t be superficial and let what other’s think of you guide your spending patterns. I am probably being a little more harsh than Dunleavey. Yet, it seems that a lot of the overspending mentioned in this paper is based on insecurity and greed.

Sadly, as retro and pathetic as keeping up with those mythical Joneses may seem, more people get themselves into financial hot water by coveting their neighbors’ flat screen (hello!) or fully loaded Mini Cooper than most of us are willing to admit.

The best financial advice ever by Liz Pulliam Weston

In this article on MSN, Liz Pulliam Weston shares the best financial advice from experts and readers alike. The one I really liked was… “Keep living like a broke college student for as long as you can.”

Maybe its because I am still in graduate school and still living like I did in undergrad. But as I think about this advice, it makes a lot of sense. I am comfortable living like a college student because I am used to this lifestyle. Once I get a taste of luxury, I would probably be disgusted with the way I live – my dinky rental house, my small TV, my 14 year old car. But since I am used to these things, I am satisfied with my current standard of living.

When I do get a job, maybe my goal should be to maintain my current grad school standard of living.