Minimal variance asset allocation for Stocks ISA

With interest rate in the UK so pathetically low, I thought I might take some chance by making use of a Stocks ISA account in the UK. The problem though, is that I have no knowledge about the London stock market nor do I have the time to follow it. So I wrote a program to pick some Exchange Traded Funds (ETFs) with a primary goal to minimise risk and opportunity costs.

Here are what I wanted to achieve:

  • only a few trades at most a year
  • less risk than FTSE100
  • more yield than a laddered government bonds portfolio
  • require less than an hour per month of maintenance

Basically, this is a computer-assisted passive investment portfolio.

The first step is to scrape all the ETF symbols from London Stock Exchange on these pages. I use getNodeSet from XML package in R to select the relevant data from the HTML page with XPath.

page <- getURL(url, curl=curl)
tree <- htmlTreeParse(page, useInternalNodes=TRUE)
xpath <- "//table[@class = 'table_dati']/tbody"
node <- getNodeSet(tree, xpath)

This program only considers ETF because this portfolio is to diversify risk and not pick winning stocks. ETFs provide convenient exposure to various asset classes such as equities, bonds, and commodities at low costs.

Next is to scrape profile information for each symbol from Yahoo. We want data such as the fund's expense ratio and asset class category.

url <- paste("", symbol, "+Profile", sep="")
tree <- htmlTreeParse(url, useInternalNodes=TRUE)
xpath <- "//table[contains(concat(' ', @class, ' '), ' yfnc_datamodoutline1 ')]/tr/td/table"
node <- getNodeSet(tree, xpath)

operation <- tryCatch(readHTMLTable(node[[2]]), error = function(e) NA)
overview <- tryCatch(readHTMLTable(node[[1]]), error = function(e) NA)

Once the funds' fundamental data are fetched, we can do a preliminary screening. I am filtering for:

  1. Actively traded funds,
  2. Sufficient age (3 years), and
  3. Only the best 3 expense ratio efficiency from each class

That last point is particularly important as illustrated in this plot.

London funds expense by category

The above plot couldn't fit in this frame but it shows that expense ratios are all over the place. What matters is that the raw data is available for use.

The plot below is clearer. It shows expense ratio by the fund's issuer. You can see that Vanguard funds generally have the best expense ratio as is commonly known.

London funds expense by issuer

The initial ETF list has 667 funds in 104 categories. The screened list narrows it down to 20 funds in 18 categories. Most that were screened are niche funds such as Islamic Global Equity and regional real estate funds.

Out of that 20 funds, I apply the popular Modern Portfolio Theory to minimise risk using historical quotes data with quantmod's Yahoo data fetcher. Given the expected returns of each asset, er and their covariance matrix, cov.mat, a long-only efficient portfolio weighting of those assets can be solved with quadratic programming like so.

Dmat <- 2*cov.mat
dvec <-, N)
Amat <- cbind(rep(1,N), er, diag(1,N))
bvec <- c(1, target.return, rep(0,N))
result <- solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=2)

To get these weightings,

0.603023 0.122829 0.116879 0.084122 0.037906 0.017975 0.014051 0.003215

But here's the catch, this mean-variance optimisation approach which I'm using does not work in the real-world. The problem is that it optimises for historical data under simplistic assumptions. For potential improvements on this model, start with this Q&A on StackExchange but be warned that it's a rabbit hole to go down in.

Knowing that I shouldn't trust this model much, I do this a couple times under different scenarios on the efficient frontier and union the top weighted assets from each run as a compensation by sampling.

The result is a suggestion of six ETFs.

Symbol            Name                   category
BRIC.L    ISHARESII 50                BRIC Equity
EQQQ.L   POWERSHS EQQQ US Large-Cap Growth Equity
IGLS.L ISHARESIII 0-5£        GBP Government Bond
INXG.L GBP IDX-LNK GLT  GBP Inflation-Linked Bond
MIDD.L  ISHARESFTSE250          UK Mid-Cap Equity
SLXX.L ISHSIII IBX £CB         GBP Corporate Bond

Out of these I hand picked IGLS.L and MIDD.L for a conservative 80% bonds and 20% equity portfolio. This plot below shows the annualised return versus risk of ISF (FTSE100), an equal-weighted portfolio of the pre-screened 20 ETFs, and this final portfolio of two ETFs. Notice the historic risk of this final portfolio is a third of FTSE100.

Return vs risk

Not surprisingly, what my program derived from scratch is similar to the commonly suggested portfolio balance of bonds, local equities, and emerging market blend. What this program offers is picking out the specific ETFs from the hundreds of ETFs traded on London Stock Exchange for a balanced asset allocation.

The complete R source code for this project is available on Github.

Posted 31 January 2013 in stocks.

Bought 1000 PMV.VN @ 0.62

Update January 26: The share price of PMV.V crossed my mental stop yesterday so I had to reassess the position. I sold my shares at \$0.56 for a loss of (\$0.56 - \$0.62) * 1000 = \$70 + \$19.90 commission = \$89.90 = 0.9% of account. Gold is falling while USD tanked this week. The lack of volume on today's goldminers rally is also uncharacteristic of the recent uptrend. The long term uptrend of gold and gold miners is unmistakable on both fundamental and technical basis. I am taking a dabble in this junior gold miner as its share price is making a gap fill on a recent breakout (Fig. 1), amongst other things. Intraday chart (Fig. 2) is also showing signs of life at this support level. What's going to happen to gold as it breaks below 1350 (first time since November) from worries about Chinese inflation, which led to strength in USD (on fear of further Chinese tightening) as EURUSD dropped 60 pips in 2 hours. See FT: Fears grow that China is overheating. Couple that with political and economic uncertainty, we have a short term uncertainty in gold's direction. However, all these is in line with the underlying gold-bug case that money is becoming more worthless as governments pump in money to their respective economies. Another point to note is that as the Shanghai Composite and Bombay Stock Exchange (i.e. growth markets) are making 3-month lows in recent weeks, people will start to look for other assets to diversify their wealth. This is all conjectures anyway. I can't predict the future.I am merely placing my bet as the stars seem to have aligned for me to increase the probability of this good reward/risk trade. Mental stop is \$0.55. Hard stop is \$0.48, however, I'll give it some margin and say 0.40 is my stop as liquidity is thin in this junior. Thus, risk is (\$0.62 - \$0.40) * 1000 = \$220 + \$9.95 commission = \$229.95 = 2.4% of account. Note: You might have noticed that my trade log style has changed for 2011. I am trying to jot down my thought process rather than the data analysis and numerical logic to better capture my thinking for the record.

[caption id="" align="aligncenter" width="570" caption="PMI Gold Corp. (PMV.V)"][][][/caption] [caption id="" align="aligncenter" width="570" caption="PMI Gold Corp. (PMV.V) intraday"][]1[/caption]

Posted 20 January 2011 in stocks.

I didn't miss a boat. I missed a freakin rocket!

The purpose of this post is not to bang my head over this wonder. There are always other opportunities in the market. The purpose of this post is to remind myself that:

  1. my analysis can be so right, sometimes; but more importantly
  2. my entries and exits timing are still terrible

I can't use the same techniques I use totrade forex and large caps in these junior miners. I'm used to riding waves on a boat. I need to adapt and figure out ways to ride rockets (a friendly reminder that most rockets will fail to launch), as Uberlu suggested in a comment. Here's what happened. I lamented about my missed opportunity in establishing a position in Ventana Gold (VEN.TO) last week. VEN.TO is a company in which I've been very bullish and took numerous dabs at for months. This is the picture of VEN.TO last Monday. It already propelled to \$11. [caption id="" align="aligncenter" width="570" caption="Ventana Gold (VEN.TO) on November 8"][][][/caption] Now this is VEN.TO today. [caption id="" align="aligncenter" width="570" caption="Ventana Gold (VEN.TO)"][]1[/caption] VEN.TO closed at \$10.03 on Tuesday. It opened at 13.61 on Wednesday on news of a takeover bid.

Sold 200 LLL.TO @ 48.00, Profit +1.9%

I'm out of my Lululemon position minutes prior to the close. Holding time was just a day. I would have liked to hold this position for longer but the market is directionless. In addition, the stop hunt on the shorts in LLL.TO is unmistakable as seen in Figure 1. Option expiration is this Friday. So I'm taking my profit now prior to expected volatility. A reward/risk of 2 to 1 is too tempting to let go. However, LLL.TO is pushing higher into the close. So perhaps this is yet another lack of patience on my part. Update Nov 18: Yes, I was too early indeed. LLL.TO gapped upward the day after my exit. Option pain is pegged at \$45 on the American shares (NASDAQ:LULU). LULU is trading just above \$47 as I close my position. [caption id="" align="aligncenter" width="570" caption="Lululemon (LLL.TO)"][][][/caption] Profit is (\$48.00 - \$47.04) * 200 = \$192 - \$9.90 commission = \$182.1 = 1.9% of account. It's fortunate that I'm able to bounce right back to regain most of my losses in my worst trade this year within a week.

continue   →