The Average Investor's Blog

A software developer view on the markets

Archive for June, 2011

The Weekly Update

Posted by The Average Investor on Jun 26, 2011

Another red week for the indexes. A loss of 1.18% in the US REIT index (VNQ) pushed this last index below its 20-week MA. As of Friday, all indexes are signalling out of the market based on the 20-week MA.

This week is also the last trading week for the month of June. S&P 500 has been in buy mode since Sep 30, 2010 with respect to its 10-month EMA. If S&P 500 closes the month of June below $1,265, this will move the index in neutral territory. We are in for an interesting week, considering that S&P 500 closed at $1,268.45 on Friday.

EMA Trigger Price
10-month $1,265
12-month $1,248

Posted in Market Timing, Trades | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Jun 19, 2011

Finally the markets managed to register a positive week, and with that, the US REIT index crossed over its 20-week moving average, thus, signalling a buy on the Friday’s close. That’s the only long position at the moment, regardless of the fact that most indexes seem to be oversold with respect to their moving average. Sit quiet and await developments.

Posted in Market Timing, Trades | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Jun 11, 2011

Stay out – that’s what all the 20-week EMA has been telling us over the last two weeks. Last week the US stock indexes caved in and at the end of this week the Emerging Markets and the US REIT gave a sell signal too.

The EEM position was short lived, yet another whipsaw, and resulted in a loss of -2.68%. The VNQ position on the other hand has been open for a while, since July 23, 2010, and have resulted in a 16.34% gain.

Markets seem to be getting in a grizzly mood as of late and it seems to be very hard to think of any positive event on the horizon. In my view we have been on a drinking binge since the beginning of 2009 orchestrated by the central banks. Now even the hardest participants are starting to give up and there is nothing, literally nothing left but a heavy, dark hangover.

Seriously though, what is there to show for all the money we destroyed by pouring them hopefully into the system? The housing in the US is officially in double dip, Greece is back in the same situation as a year ago. Shall we take pride in reducing the unemployment by a mere 1.4%? While that’s a significant number, was it worth the money? Japan, the third largest economy, is in a recession yet again largely as a result of the devastating quake, but also aided by the sick, debt-laden economy they have been running for a while now.

It does look ugly, not only from a technical perspective. The only bright spot in my mind is that despite of the six red weeks, the pullback has been relatively mild so far, less than 8% on the S&P 500. For comparison, in May 2010 the S&P 500 lost almost 16% in the matter of a few weeks. Let’s hope it turns out to be just that – a minor correction.

Posted in Market Timing, Strategies, Trades | Leave a Comment »

ARMA Models for Trading, Part V

Posted by The Average Investor on Jun 8, 2011

All posts in this series were combined into a single, extended tutorial and posted on my new blog.

Once back testing is done and the results of the trading system are convincingly positive, it’s time to move it to production. Now, how do we implement something like the ARMA techniques I described earlier in practice (assuming a retail brokerage account)?

In an earlier post I discussed the problems related to trading at the close and various solutions. Thus, in this post, I will discuss only the two obstacles I had to overcome for the ARMA methods.

My implementation was to compute a table of actions for each instrument I am interested in. Here is an example:

-0.99%, 1
-0.98%, 1
-0.97%, 1
-0.96%, 1
-0.95%, -1
-0.94%, -1
-0.93%, -1
-0.92%, -1
-0.91%, -1
-0.9%, -1

The above table tells me what position I am supposed to take at the close of the day for various changes (as a percentage) in the price. In the above example, anything up to and including -0.96% is a long position. In other words, if the instrument loses more than -0.96% – take long.

The first problem I found was the computational time. These computations are expensive! I had two choices – code everything in C or buy hardware. Obviously I went after the latter solution – no idea how long it would have taken to port everything successfully to C. For less than $900 I managed to assemble an i7 system which was running a few orders of magnitude faster than my laptop. Moreover it is able to run up to 8 workloads in parallel. If you are unfamiliar, i7 has four cores plus hyper-threading, which makes it sort of similar to an eight core machine and so far it has proved good enough to compute 4 to 5 maps in about 3 hours. All the computations are run in parallel as daily cron jobs in Linux. The results are sent to me in an email. 🙂 The scripts implementing the infrastructure are available on the quantscript project.

The bigger problem was that quite often the computations were not stable enough. In the above example there was a single switch between the long and the short position (at -0.95%). Thus, at 15:55, if the instrument is away from this point, one can take the position with confidence that it won’t cross the line in the last second. Of course, it’s not going to be perfectly on the close, but on average, you shouldn’t expect high negative impact from this type of slippage. Same holds if one is trading moving averages – there is a single prices that separates the long and short position and it can be even determined mathematically.

No such luck for my ARMA implementation, quite often the table of actions looks like:

0.75%, 1
0.76%, 1
0.77%, -1
0.78%, 1
0.79%, 1
0.8%, -1
0.81%, -1
0.82%, 1
0.83%, 1
0.84%, 1
0.85%, -1

If the price is within this range in the last few minutes, there is no guarantee whether it will stop on a long or on a short. So what to do? My solution was simply to not take a position if the price is within an unstable region nearby the close. The alternative is to take the position and be happy with it until at least the open on the next day. After the close we can compute the exact position and if we did the wrong thing, bought when we were supposed to sell, we can close the position at the next day open. Sometimes we will get lucky and it will move in the directions that benefits us regardless of what the system says.

This brings me to the last point – after the close is known, I compute the precise positions and check against the actual positions. If necessary I might take corrective actions during the next day.

My experience so far from a trading point of view is quite positive. What I described above is not too hard to follow in practice. I hope it proves worth the efforts. 😀

Posted in Market Timing, Strategies | Tagged: , , , | 8 Comments »

Computing Daily Returns and the R-bloggers portal

Posted by The Average Investor on Jun 7, 2011

The daily returns of a financial time series have some nice properties which make their use much more desirable than the use of the series itself (price for instance). There are two ways to compute them – as a percentage and by using logarithms. This article sheds more light on the details and discusses various R interfaces.

And if you are looking to expand your R knowledge and experience, R-bloggers is probably the best place to look for information. That’s where I usually go looking for an interesting read for a coffee break. If there’s nothing that catches the eye in the main page – dig in the archives.

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Jun 5, 2011

Another week in the red for the stock indexes. Early on Friday it looked as if all the indexes I follow will close below their 20-week EMA. However, things improved somewhat later in the day except for the US stock indexes. Thus, if we follow the 20-week EMA, we should have closed the positions both in S&P 500 and in the Nasdaq 100.

Asset Symbol Position Date In Gain
US REIT VNQ Long 2010-07-23 21.51%
Emerging Markets EEM Long 2011-05-27 0.25%

The Nasdaq 100 position was fairly recent, opened on March 25th. It would have resulted in less than 1% loss. Using QLD, the double bull ETF, it would have resulted in a bit more than 2% loss.

The S&P 500 position was much longer – since Sep 10th, 2010. It would have resulted in a 17% gain using the SPY ETF, and in 37% gain using SSO, the double bull ETF. The reason I am showing the performance of the double ETFs is not to suggest using them, but as an illustration of my belief that leveraged ETFs perform “as expected” with trend-following techniques.

One shouldn’t get too excited about this big gain in the S&P 500 either, a quick look at the chart below shows that we have caught quite long stretch of gains without a severe correction.

S&P 500 with 20-week EMA

S&P 500 with 20-week EMA

Posted in Market Timing, Trades | Leave a Comment »

Friday’s Game Plan (Moving Averages)

Posted by The Average Investor on Jun 3, 2011

After few weeks of declines, combined with the ugly unemployment news that came out today, there is a good chance that a few of the indexes I follow will penetrate their 20-week MA on the downside today. Here are the number to watch – a close below the EMA number means closing the long position:

Asset Symbol Thursday’s Close EMA
US REIT VNQ $60.44 $58.61
S&P 500 ^GSPC $1312.94 $1309.98
Nasdaq 100 ^NDX $2326.70 $2313.89
Emerging Markets EEM $48.11 $47.48

In fact, looking at the early trading it is likely that all the indexes will signal closing the positions at the close today.

As always, do your own DD and investment decisions and happy trading!

Posted in Market Timing, Trades | Leave a Comment »

%d bloggers like this: