The Average Investor's Blog

A software developer view on the markets

Archive for the ‘Uncategorized’ Category

Moving the blog to www.quintuitive.com

Posted by The Average Investor on Oct 20, 2012

It has been a while I must say, but I haven’t been idle. I wanted a little bit more from my blogging platform, so I decided to move the blog to a new, self-hosted home – http://www.quintuitive.com. See you there!

Posted in Uncategorized | Leave a Comment »

Configuring R via .Rprofile

Posted by The Average Investor on Oct 2, 2011

For a while I have been looking for a way to load stuff automatically in R on each start (quantmod package, some options, etc). I had given up on solving it in a straightforward way, so I was delighted to find this post on R-bloggers!

Currently my .Rprofile is a two-liner:

library( quantmod )
options( width=120 )

Posted in Uncategorized | Leave a Comment »

When the Music Stops …

Posted by The Average Investor on Aug 9, 2011

About a year ago, quantitative easing 2 (QE2) was all over the news. The ever-fighting deflation, almighty Federal Reserve flexed its muscles and promised a dump worth of $600 billion to inflate asset prices. And asset prices did get inflated, including stock markets, reaching a new top in the bull run that started in March 2009.

S&P 500 during QE2

Then the music stopped. Reality took over. The S&P 500 went back again where it was before QE2 and the free fall momentum seems to be getting only stronger. Unemployment went up again. Housing market dipped again. The US lost its AAA rating. But that’s just another $600 billion righteously-spent based on the ideology set by Mr. Keynes. Still far away from what’s necessary according to prominent economists. Many of them saying in recent interviews that the economy needs more stimulus in the (ever-lasting) short term, and some of them agreeing that, of course, medium to long-term a cleaning of the deficits is needed. Of course, they didn’t mention when the short-term ends (a minor detail, since it seems to me that this short term goes back at least to 2008, probably to 2002 and likely even before). Huh?!

Can’t help but wonder: If we ask an average person on the street what would have he expected the economic situation to be after 15 years of reckless spending, debt accumulation and money printing, how often the answer will be closer to the mess we are in than to the prosperity naturally following Keynesian interventions (links needed;)?

Back in the real world, the S&P 500 is extremely oversold by any metric. I took the difference between the S&P 500 and its 50-day EMA:

linrary( quantmod )
getSymbols( "^GSPC", from="1900-01-01" )

dd = round( coredata( Ad( GSPC ) ) / EMA( coredata( Ad( GSPC ) ), 50 ) - 1, 4 )
ecdf( dd )( last( dd ) )

aa = dd[ !is.na( dd ) ]
length( aa[ aa < last( aa ) ]

plot(dd, type="l", col="blue", main="S&P 500 deviation from 50-day EMA", ylab="Deviation")
ll = rep(last(dd), length(dd))
lines(ll, col="green")

The ecdf statement gives us the percentile – 0.3624361. Ouch. The last three lines produce an easy to understand chart:

S&P 500 Deviation from 50-day EMA

While the S&P 500 has been in more oversold state on 55 other occasions (the length line in the above code) in its 61 year history, 30 of them were in the 2007/2009 crisis, and there are only 6 other distinctive events in time. Ouch.

A typical liquidation panic seems to be under way, more often associated with bear market bottoms. Ouch.

Unfortunately, when the music stops … the reality settles in.

Posted in Uncategorized | Leave a Comment »

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 May 29, 2011

The US markets continued their slow but persistent descent. Nothing spectacular, just four consecutive weeks of relatively small (in total about 2.3% on the S&P500 and about 2.8% on the Nasdaq 100) loses. At the same time, the US REIT increased for a second week in a row. More importantly, the Emerging Markets gave a buy signal last Friday after advancing for a second week in a row.

Asset Symbol Position Date In Gain
US REIT VNQ Long 2010-07-23 23.55%
S&P 500 ^GSPC Long 2010-09-30 16.64%
Nasdaq 100 ^NDX Long 2011-03-25 0.85%
Emerging Markets EEM Long 2011-05-27 0%

The month ends on Tuesday, while Monday is a holiday in the US. One of the indexes, the S&P 500, is monitored using the 10 month EMA, thus, a natural question is whether the four weeks of declines will trigger a change in the position. The answer is an affirmative No, barring calamitous events on Tuesday of course. For a sell to get triggered, the S&P 500 needs to drop down below $1247, which is 6.3% lower than the current price of $1331.1. And that needs to happen in a single day.

The only position “in danger” in near term is in fact the Nasdaq 100. The Friday’s close was less than 1% above the EMA (weekly, 20 for this instrument), thus, a drop this week may trigger an exit on Friday. For this to materialize next Friday’s close need to be $2313.89 or lower (the last Friday’s close was $2336.90).

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on May 23, 2011

Another week in the red, but no new sell signals yet, mostly due to the significant profits the indexes delivered over the past few months. In other words, there is no reason to think this is more than a long-overdue correction.

Asset Symbol Position Date In Gain
US REIT VNQ Long 2010-07-23 21.55%
S&P 500 ^GSPC Long 2010-09-30 16.83%
Nasdaq 100 ^NDX Long 2011-03-25 1.72%

The economy is probably not too bad anywhere in the world, but the excessive amounts of debt keep people and governments hostage. A small turbulence can easily escalate into a major disaster for the same reason. Pneumonia is not too dangerous on its own, but it can be terminal if ones immune system is already weakened for whatever reason.

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on May 14, 2011

Another red week across the board and after being battered badly for about three weeks now, the Emerging Markets index gave a sell signal at the close on Friday. This trade should have been opened on March 3, 2011 and would have resulted in a 0.89% loss, a loss as the previous two trades in this ETF.

Asset Symbol Position Date In Gain
US REIT VNQ Long 2010-07-23 21.21%
S&P 500 ^GSPC Long 2010-09-30 17.22%
Nasdaq 100 ^NDX Long 2011-03-25 2.71%

To me looking at past performance is an invaluable exercise helping you prepare psychological for the real thing. For instance, if you have started trading EEM using 20 week MA in March 2010 (the first buy signal for the year), currently you would be sitting at about 3.15% losses, which doesn’t seem much, but how easy is to swallow and be persistent after sitting on a loss for more than a year? What if the loss was 20%? 40%? Definitely a reality check.

The markets can teach one a lot. I am not alone in this opinion – Nassim Taleb shares similar thoughts in his exceptional book The Black Swan.

The most important lesson that I have learned from studying the markets is that it is very hard, if not impossible, to beat just inflation, forget about excessive returns. Here I am discussing pure trading gains, excluding fees charged (by a well-known money manager for instance) and taxes. Take a look at the inflation adjusted returns of the S&P 500 since 2000. Amazing isn’t it – 30% off the peak in 2000 (30% on the way down is equivalent to about 42% on the way up) and that’s after the central banks and politicians were congratulating themselves twice for saving the world, first after 2002 and recently for the second time!

Looking at this charts another sinister thought creeps up in my mind – probably this is the explanation why republicans (or conservatives in general) have been adamant against raising taxes – people who have money (not debt) have been taxed at an exceptional rate already since 2000 simply by the operational logistics of central banks! They might be right (until now I have been seriously disgruntled by their reluctance to raise taxes), certainly some food for thought here …

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Apr 30, 2011

All is good in the world markets. Last week most indexes surpassed their recent heights thus confirming the upwards trend.

Asset Symbol Position Date In Gain
US REIT VNQ Long 2010-07-23 23.81%
S&P 500 ^GSPC Long 2010-09-30 19.49%
Emerging Markets EEM Long 2011-03-25 5.62%
Nasdaq 100 ^NDX Long 2011-03-25 3.79%

One can’t help but notice the advance of anything in dollar terms. Most currencies, most socks, most commodities, etc. Right or wrong, I do see a trend – all currencies are losing their value (buying power for real stuff), the worst among the bad being the US dollar. So we have replaced deflation in nominal terms with inflation. Right now we see the inflation only in non-Fed watched goods, but I bet, it’s coming to the US (it is already roaring around the world).

Make no mistake, in real terms there is no difference – the large middle class who has mostly nothing (but debt) is again being financed by the people who did nothing wrong and lived within their means. So much about the great society we have build.

In real terms however the story is quite different. Ignoring the details I mentioned above, we have avoided the Great Depression, we have broken the neck of deflation which devastated the world in the 30s, we are back to business as usual. Big political success!

Only time will tell, but I promise to keep the political and fundamental rants on this blog to a minimum – this blog is all about technical trading and investing. Nothing else. I guess it’s the election bug that got me …

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Mar 13, 2011

Considering what’s happening around the globe, the markets seem to be holding quite well. A little pullback, but still long on all major indexes. With the exception of S&P 500, everything else is getting pretty close (within 5%) to their moving average – finally some excitement after this long lasting trend.

Asset Symbol Position Date In Gain
Nasdaq 100 ^NDX Long 2010-09-03 22.93%
US REIT VNQ Long 2010-07-23 15.82%
S&P 500 ^GSPC Long 2010-09-30 14.29%
Emerging Markets EEM Long 2011-03-04 -1.86%

 

Volatility has also been picking up lately, but nothing out of the ordinary so far:

library( quantmod )
getSymbols( "^GSPC", from="1900-01-01" )
GSPC.rets = diff( log( Cl( GSPC ) ) )
index( GSPC.rets ) = as.Date( index( GSPC.rets ) )
lineChart( theme="white", GSPC.rets["2010/"], name="S&P 500 Volatility" )

 

S&P 500 Volatility

S&P 500 Volatility

Posted in Uncategorized | Leave a Comment »

The Weekly Update

Posted by The Average Investor on Feb 21, 2011

Looking at the market as of late, I can’t help but wonder what is it trying to tell us. Most likely (tongue in chick) it’s seeing some prosperous times at the horizon. Following the market, the gains in the long-term trend-following positions have increased yet again.

Asset Symbol Position Date In Gain
Nasdaq 100 ^NDX Long 2010-09-03 27.92%
US REIT VNQ Long 2010-07-23 17.60%
S&P 500 ^GSPC Long 2010-09-30 17.68%
Emerging Markets EEM Long 2011-02-18 0%

The Emerging Markets gave another buy signal on Friday. Let’s see whether it will be another short term whipsaw like the previous one.

One more thing, the S&P 500 is 14.71% above its 10-month moving average. According to my R code (which is not necessarily correct;)) this index is in the 98th quantile with respect to it’s 10-month moving average and in 97th quantile with respect to it’s 20-week moving average. In other words, for the past 60 years, the situation foreseen by the market was better than what it’s seeing right now in only two percent of the cases!

Don’t get excited yet, this is not such a rare event – it has happened on 397 days in the past since 1950 (15,383 days of history). 🙂 The last time it happened was on several occasions (on 106 days in total to be precise) between November 1996 and April 1999. Here is the month list:

1951: Jan, Feb
1954: Sep-Dec
1955: Jan-Feb, Jun-Dec
1958: Dec
1961: Apr
1971: Apr
1975: Jun
1976: Jan
1980: Sep-Nov
1982: Oct-Dec
1983: Jan-Jun
1986: Feb-May
1987: Jan-Apr, Jun-Aug
1989: Jul, Aug
1996: Nov
1997: Feb, May-Oct
1998: Feb-Apr, Jul, Dec
1999: Jan, Apr

Some of the months on the list are just before some really scaring events (Aug 1987, Apr 1999, etc). Keep the printing press, oops the economy, rolling and let’s be optimists – this time it’s going to be all different.

Posted in Uncategorized | 1 Comment »

 
%d bloggers like this: