{"id":2978,"date":"2011-12-29T15:14:10","date_gmt":"2011-12-29T20:14:10","guid":{"rendered":"http:\/\/www.decisionsciencenews.com\/?p=2978"},"modified":"2012-01-01T13:46:35","modified_gmt":"2012-01-01T18:46:35","slug":"youve-got-the-whole-world-in-your-portfolio","status":"publish","type":"post","link":"https:\/\/www.decisionsciencenews.com\/?p=2978","title":{"rendered":"You&#8217;ve got the whole world in your portfolio"},"content":{"rendered":"<p>LEARN HOW TO IMPORT WORLD BANK DATA AND INVEST IN THE WHOLE WORLD<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/MCPbyCountryw.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2979\" title=\"MCPbyCountry\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/MCPbyCountry.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><br \/>\n<em> Click to enlarge<br \/>\nThe market cap of the countries comprising 90% of the world&#8217;s market cap (end 2010)<\/em><\/p>\n<p>A famous finance professor once told us that good diversification meant holding everything in the world. Fine, but in what proportion?<\/p>\n<p>Suppose you <em>could<\/em> invest in every country in the world. How much would you invest in each? In a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Capitalization-weighted_index\">market-capitalization weighted index<\/a>, you&#8217;d invest in each country in proportion to the market value of its investments (its &#8220;market capitalization&#8221;). As seen above, the market-capitalization of the USA is about 30%, which would suggest investing 30% of one&#8217;s portfolio in the USA. Similarly, one would put 8% in China, and so on. All this data was pulled from the <a href=\"http:\/\/data.worldbank.org\/\">World Bank<\/a>, and at the end of this post we&#8217;ll show you how we did it.<\/p>\n<p>What makes life easy is that economists have grouped countries into regions and the market caps of each can be computed by summing the market caps of the constituent countries. See <a href=\"http:\/\/www.msci.com\/products\/indices\/tools\/\">this MSCI page<\/a> for the manner in which we&#8217;ve categorized countries in this post:<\/p>\n<p><strong>North America:<\/strong> USA, Canada<br \/>\n<strong>Emerging:<\/strong> Brazil, Chile, China, Colombia, Czech Republic, Egypt, Hungary, India, Indonesia, Korea, Malaysia, Mexico, Morocco, Peru, Philippines, Poland, Russia, South Africa, Taiwan, Thailand, Turkey<br \/>\n<strong>Asia:<\/strong> Japan, Australia, Hong Kong, New Zealand, Singapore<br \/>\n<strong>Europe:<\/strong> Austria, Belgium, Denmark, Finland, France, Germany, Greece, Ireland, Italy, Netherlands, Norway, Portugal, Spain, Sweden, Switzerland, United Kingdom<br \/>\n<strong>Other:<\/strong> Everybody else in the world<\/p>\n<p><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/MCPbyRegion.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2980\" title=\"MCPbyRegion\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/MCPbyRegion.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><\/p>\n<p>What makes life easier still is that one can purchase ETFs that work like indices tracking the various regions of the world. For example at Vangard one can purchase<\/p>\n<ul>\n<li>Vanguard Total Stock Market ETF (Ticker VTI), which basically covers North America<\/li>\n<li>Vanguard MSCI Emerging Marketing ETF (Ticker VWO), which covers emerging markets<\/li>\n<li>Vanguard MSCI Pacific ETF (Ticker VPL), which covers Asia (minus the Asian emerging markets countries)<\/li>\n<li>Vanguard MSCI Europe ETF (Ticker VGK), which covers Europe<\/li>\n<\/ul>\n<p>What makes life a bit more complicated is that not everybody agrees on market-cap weighting. Some favor Gross Domestic Product (GDP) weighting <a href=\"http:\/\/www.msci.com\/products\/indices\/strategy\/risk_premia\/gdp_weighted\/\">for the reasons given at this MSCI page<\/a>.<\/p>\n<blockquote>\n<ul>\n<li>GDP figures tend to be more stable over time compared to equity markets\u2019 performance-related peaks and troughs<\/li>\n<li>GDP weighted asset allocation tends to have higher exposure to countries with above average economic growth, such as emerging markets<\/li>\n<li>GDP weighted indices may underweight countries with relatively high valuation, compared to market-cap weight indices<\/li>\n<\/ul>\n<\/blockquote>\n<p>Here are the countries that make up 90% of the world&#8217;s GDP:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/GDPbyCountryw.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2986\" title=\"GDPbyCountry\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/GDPbyCountry.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><br \/>\n<em>Click to enlarge<br \/>\nThe GDP of the countries comprising 90% of the world&#8217;s GDP (end 2010)<\/em><\/p>\n<p>Because we love you, we&#8217;ve also computed how the classic market regions compare to one another in terms of GDP<\/p>\n<p><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/GDPbyRegion.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2987\" title=\"GDPbyRegion\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/12\/GDPbyRegion.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><\/p>\n<p>If you track changes in market cap from month to month as we do, you&#8217;ll appreciate the stability that GDP weighting provides. For example, the market cap data in this post, from 2010, is already way out of date.<\/p>\n<p>So, weight by market cap, or weight by GDP, or do what we do and weight by the average of market cap and GDP, but don&#8217;t wait to diversify your portfolio outside of a handful of investments you happen to own. Invest in the world.<\/p>\n<p>For those who love <a href=\"http:\/\/www.r-project.org\/\">R<\/a> and who want to learn how to pull down World Bank data, the code is provided here. I got started with this by borrowing code from <a href=\"http:\/\/lamages.blogspot.com\/2011\/09\/accessing-and-plotting-world-bank-data.html\">this very helpful blog post by Markus Gesmann<\/a> and tip my hat to its author. Thanks also to <a href=\"http:\/\/had.co.nz\/\">Hadley <\/a>for writing <a href=\"http:\/\/had.co.nz\/ggplot2\/\">ggplot2<\/a> (and for visiting us at Yahoo the other week. And thanks to <a href=\"http:\/\/yihui.name\/\">Yihui Xie<\/a> for his <a href=\"https:\/\/github.com\/yihui\/formatR\/wiki\">code formatter<\/a>.<\/p>\n<p>R CODE<br \/>\n<code><br \/>\nlibrary(ggplot2)<br \/>\nlibrary(car)<br \/>\nlibrary(RJSONIO)<br \/>\nftse=read.delim(\"201112_FTSE_Market_Caps.tsv\",sep=\"\\t\")<br \/>\n##See www.msci.com\/products\/indices\/tools\/index.html<br \/>\n##Emerging::Brazil, Chile, China, Colombia, Czech Republic, Egypt, Hungary,<br \/>\n#India, Indonesia, Korea, Malaysia, Mexico, Morocco, Peru, Philippines,<br \/>\n#Poland, Russia, South Africa, Taiwan, Thailand, Turkey<br \/>\n##Europe::Austria, Belgium, Denmark, Finland, France, Germany, Greece, Ireland, Italy,<br \/>\n#Netherlands, Norway, Portugal, Spain, Sweden, Switzerland, United Kingdom<br \/>\n##Asia::Japan, Australia, Hong Kong, New Zealand, Singapore<br \/>\nrecodestring=\"   c('USA','CAN')='North America';<br \/>\n                 c('BRA','CHL','CHN','COL','CZE','EGY','HUN','IND','IDN','KOR','MYS','MEX','MAR','PER','PHL','POL',<br \/>\n                  'RUS','ZAF','TWN','THA','TUR')= 'Emerging';<br \/>\n                 c('AUT','BEL','DNK','FIN','FRA','DEU','GRC','IRL','ITA',<br \/>\n                  'NLD','NOR','PRT','ESP','SWE','CHE','GBR')= 'Europe';<br \/>\n                  c('JPN','AUS','HKG','NZL','SGP')= 'Asia';<br \/>\n                  else='Other'\"<br \/>\n#How much of the world do we want to consider (to keep graphs manageable)<br \/>\nCUTOFF=.9<br \/>\n#Some code from internet to read world bank data. Adapted from<br \/>\n#http:\/\/www.r-bloggers.com\/accessing-and-plotting-world-bank-data-with-r\/<br \/>\n#See also http:\/\/data.worldbank.org\/indicator\/NY.GDP.MKTP.CD<br \/>\ngetWorldBankData = function(id='NY.GDP.MKTP.CD', date='2010:2011',<br \/>\n                            value=\"value\", per.page=12000){<br \/>\n  require(RJSONIO)<br \/>\n  url = paste(\"http:\/\/api.worldbank.org\/countries\/all\/indicators\/\", id,<br \/>\n              \"?date=\", date, \"&format=json&per_page=\", per.page,<br \/>\n              sep=\"\")<br \/>\n  wbData = fromJSON(url)[[2]]<br \/>\n  wbData = data.frame(<br \/>\n    year = as.numeric(sapply(wbData, \"[[\", \"date\")),<br \/>\n    value = as.numeric(sapply(wbData, function(x)<br \/>\n      ifelse(is.null(x[[\"value\"]]),NA, x[[\"value\"]]))),<br \/>\n    country.name = sapply(wbData, function(x) x[[\"country\"]]['value']),<br \/>\n    country.id = sapply(wbData, function(x) x[[\"country\"]]['id'])<br \/>\n    )<br \/>\n  names(wbData)[2] = value<br \/>\n  return(wbData)<br \/>\n}<br \/>\ngetWorldBankCountries = function(){<br \/>\n  require(RJSONIO)<br \/>\n  wbCountries =<br \/>\n    fromJSON(\"http:\/\/api.worldbank.org\/countries?per_page=12000&format=json\")<br \/>\n  wbCountries = data.frame(t(sapply(wbCountries[[2]], unlist)))<br \/>\n  levels(wbCountries$region.value) = gsub(\"\\\\(all income levels\\\\)\",<br \/>\n                                          \"\", levels(wbCountries$region.value))<br \/>\n  return(wbCountries)<br \/>\n}<br \/>\n### Get the most recent year with data<br \/>\ncurryear = as.numeric(format(Sys.Date(), \"%Y\"))<br \/>\nyears = paste(\"2010:\", curryear, sep=\"\")<br \/>\n##Get GDP for the countries (GDP in Current US Dollars)<br \/>\nGDP = getWorldBankData(id='NY.GDP.MKTP.CD',<br \/>\n                                date=years,<br \/>\n                                value=\"gdp\")<br \/>\n#If a year has > 60 NAs it is not ready<br \/>\nwhile(  sum(is.na(subset(GDP,year==curryear)$gdp)) > 60 )<br \/>\n  {curryear=curryear-1}<br \/>\n#Keep just the most current year<br \/>\nGDP=subset(GDP,year==curryear);<br \/>\n## Get country mappings<br \/>\nwbCountries = getWorldBankCountries()<br \/>\n## Add regional information<br \/>\nGDP = merge(GDP, wbCountries[c(\"iso2Code\", \"region.value\", \"id\")],<br \/>\n                by.x=\"country.id\", by.y=\"iso2Code\")<br \/>\n## Filter out the aggregates, NAs, and irrelevant columns<br \/>\nGDP = subset(GDP, !region.value %in% \"Aggregates\" & !is.na(gdp))<br \/>\nGDP=GDP[,c('year','gdp','country.name','region.value','id')]<br \/>\nGDP=GDP[order(-1*GDP[,2]),]<br \/>\nGDP$prop=with(GDP,gdp\/sum(gdp))<br \/>\nGDP$cumsum=cumsum(GDP$gdp)<br \/>\nGDP$cumprop=with(GDP,cumsum(gdp)\/sum(gdp))<br \/>\nGDP$market.region=recode(GDP$id,recodestring)<br \/>\nresize.win <- function(Width=6, Height=6)\n{\n  plot.new() \n  dev.off(); \n  #dev.new(width=6, height=6)\n  windows(record=TRUE, width=Width, height=Height)\n}\nslice=max(which(GDP$cumprop<=CUTOFF))\nsmGDP=GDP[1:slice,]\nsmGDP$country.name=factor(smGDP$country.name,levels=unique(smGDP$country.name))\nsmGDP$region.value=factor(smGDP$region.value,levels=unique(smGDP$region.value))\nsmGDP$market.region=factor(smGDP$market.region,levels=unique(smGDP$market.region))\ng=ggplot(smGDP,aes(x=as.factor(country.name),y=prop))\ng=g+geom_bar(aes(fill=market.region))\ng=g+opts(axis.text.x=theme_text(angle=90, hjust=1))+xlab(NULL)+\n  ylab( paste(\"Proportion of global GDP\\nTop \",CUTOFF*100,\"% countries\",sep=\"\"))\ng=g+opts(legend.position=c(.8,.8))\nresize.win(5,5) #might have to run this twice to get it to shift from the default window\ng\nggsave(\"GDPbyCountry.png\",g,dpi=600)\nsmGDPsum=ddply(GDP,.(market.region),function(x) {sum(x$gdp)})\nsmGDPsum$V1=smGDPsum$V1\/sum(smGDPsum$V1)\nsmGDPsum=smGDPsum[order(-1*smGDPsum[,2]),]\nsmGDPsum$market.region=factor(smGDPsum$market.region,levels=c(\"North America\",\"Emerging\",\"Asia\",\"Europe\",\"Other\"))\ng=ggplot(smGDPsum,aes(x=as.factor(market.region),y=V1))\ng=g+geom_bar(aes(fill=market.region))\ng=g+opts(axis.text.x=theme_text(angle=90, hjust=1))+xlab(NULL)+ylab(\"GDP of Countries by Market Region\\n\")\ng=g+opts(legend.position=\"none\")\nresize.win(5,5) #might have to run this twice to get it to shift from the default window\ng\nggsave(\"GDPbyRegion.png\",g,dpi=600)\n##Get Market Cap data from World Bank CM.MKT.LCAP.CD\n### Get the most recent year with data\ncurryear = as.numeric(format(Sys.Date(), \"%Y\"))\nyears = paste(\"2010:\", curryear, sep=\"\")\n##Get MarketCap for the countries (MCP in Current US Dollars)\nMCP = getWorldBankData(id='CM.MKT.LCAP.CD',\n                       date=years,\n                       value=\"mcp\")\n#If a year has > 60 NAs it is not ready<br \/>\nwhile(  sum(is.na(subset(MCP,year==curryear)$mcp)) > 150 )<br \/>\n{curryear=curryear-1}<br \/>\n#Keep just the most current year<br \/>\nMCP=subset(MCP,year==curryear);<br \/>\n## Add regional information<br \/>\nMCP=merge(MCP, wbCountries[c(\"iso2Code\", \"region.value\", \"id\")],<br \/>\n            by.x=\"country.id\", by.y=\"iso2Code\")<br \/>\n## Filter out the aggregates, NAs, and irrelevant columns<br \/>\nMCP = subset(MCP, !region.value %in% \"Aggregates\" & !is.na(mcp))<br \/>\nMCP=MCP[,c('year','mcp','country.name','region.value','id')]<br \/>\nMCP=MCP[order(-1*MCP[,2]),]<br \/>\nrow.names(MCP)=NULL<br \/>\nMCP$prop=with(MCP,mcp\/sum(mcp))<br \/>\nMCP$cumsum=cumsum(MCP$mcp)<br \/>\nMCP$cumprop=with(MCP,cumsum(mcp)\/sum(mcp))<br \/>\nMCP$market.region=recode(MCP$id, recodestring)<br \/>\nslice=max(which(MCP$cumprop<=CUTOFF))\nsmMCP=MCP[1:slice,]\nsmMCP$country.name=factor(smMCP$country.name,levels=unique(smMCP$country.name))\nsmMCP$region.value=factor(smMCP$region.value,levels=unique(smMCP$region.value))\nsmMCP$market.region=factor(smMCP$market.region,levels=unique(smMCP$market.region))\ng=ggplot(smMCP,aes(x=as.factor(country.name),y=prop))\ng=g+geom_bar(aes(fill=market.region))\ng=g+opts(axis.text.x=theme_text(angle=90, hjust=1))+xlab(NULL)+\n  ylab( paste(\"Proportion of global Market Cap\\nTop \",CUTOFF*100,\"% countries\",sep=\"\"))\ng=g+opts(legend.position=c(.8,.8))\nresize.win(5,5) #might have to run this twice to get it to shift from the default window\ng\nggsave(\"MCPbyCountry.png\",g,dpi=600)\nsmMCPsum=ddply(MCP,.(market.region),function(x) {sum(x$mcp)})\nsmMCPsum$V1=smMCPsum$V1\/sum(smMCPsum$V1)\nsmMCPsum=smMCPsum[order(-1*smMCPsum[,2]),]\nsmMCPsum$market.region=factor(smMCPsum$market.region,levels=c(\"North America\",\"Emerging\",\"Asia\",\"Europe\",\"Other\"))\ng=ggplot(smMCPsum,aes(x=as.factor(market.region),y=V1))\ng=g+geom_bar(aes(fill=market.region))\ng=g+opts(axis.text.x=theme_text(angle=90, hjust=1))+xlab(NULL)+ylab(\"Market Cap by Market Region\\n\")\ng=g+opts(legend.position=\"none\")\nresize.win(5,5) #might have to run this twice to get it to shift from the default window\ng\nggsave(\"MCPbyRegion.png\",g,dpi=600)\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A famous finance professor once told us that good diversification meant holding everything in the world. Fine, but in what proportion?<\/p>\n<p>Suppose you could invest in every country in the world. How much would you invest in each? In a market-capitalization weighted index, you&#8217;d invest in each country in proportion to the market value of its investments (its &#8220;market capitalization&#8221;). As seen above, the market-capitalization of the USA is about 30%, which would suggest investing 30% of one&#8217;s portfolio in the USA. Similarly, one would put 8% in China, and so on. All this data was pulled from the World Bank, and at the end of this post we&#8217;ll show you how we did it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4,74,15],"tags":[20,183,307,107,304,308,309,305,1208,306],"class_list":["post-2978","post","type-post","status-publish","format-standard","hentry","category-encyclopedia","category-r","category-tools","tag-decision-making","tag-finance","tag-gdp","tag-ggplot2","tag-investment","tag-market-cap","tag-market-capitalization","tag-portfolio","tag-r","tag-weighting"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4LKj-M2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2978"}],"version-history":[{"count":36,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2978\/revisions"}],"predecessor-version":[{"id":3022,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2978\/revisions\/3022"}],"wp:attachment":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}