Saturday, September 10, 2016

Nanoblock Dratini

What better way to catch a Dratini than to make one yourself?


Thursday, August 25, 2016

Multiple Icons in gvisMaps

The googleVis package is a great way to produce interactive charts. It can be incorporated readily into R Markdown and Shiny apps.

While using the gvisMaps function to visualize locations on the map, I find that there is no argument to easily tweak to plot markers of different colors. This problem can be solved by using the plotGoogleMaps or Leaflet package. However, if for some reason you would like to stick to gvisMaps, below is one solution.

library(googleVis)

If you look at the Google Charts page, you’ll find that it is indeed possible to visualize different markers. Not only can you define the colors, you can also change their styles, simply by having a data column specifying the marker to plot for each entry.

The problem lies in that gvisMaps only takes in the locationvar and tipvar columns of the data. The html ouput of gvisMaps does not include any additional column. The workaround is to manually change this html output.

Select your favorite markers here. For this example, I chose a green and red marker. I did not set the markers to change upon click, but this can be done by choosing a different marker and specifying it under ‘selected’.

iconGreen=paste0("{",
                 "'green': {'normal':'http://icons.iconarchive.com/",
                 "icons/icons-land/vista-map-markers/32/",
                 "Map-Marker-Marker-Outside-Chartreuse-icon.png',",
                 "'selected': 'http://icons.iconarchive.com/",
                 "icons/icons-land/vista-map-markers/32/",
                 "Map-Marker-Marker-Outside-Chartreuse-icon.png'",
                 "},")
iconRed=paste0("'red': {'normal':'http://icons.iconarchive.com/",
                 "icons/icons-land/vista-map-markers/32/",
                 "Map-Marker-Marker-Outside-Pink-icon.png',",
                 "'selected': 'http://icons.iconarchive.com/",
                 "icons/icons-land/vista-map-markers/32/",
                 "Map-Marker-Marker-Outside-Pink-icon.png'",
                 "}}")
icon = paste0(iconGreen,iconRed)

The following function will be used to add the marker column in html.

makejs = function(df){
  jslist = rep(NA, nrow(df))
  for (i in 1:nrow(df)){
    latlong = paste0(df[i,c('Lat','Long')],collapse=',\n')
    tipmark = paste0('"',df[i,c('Tip','marker')],'"',collapse=',\n')
    jslist[i] = paste0('\\[\n ', paste(latlong,tipmark,sep=',\n'), ' \n\\]')
  }
  return(paste(jslist, collapse=',\n'))
}

Prepare the data for plotting.

Andrew$marker = c(rep('green',24), rep('red',23))
head(Andrew)
##         Date/Time UTC  Lat  Long Pressure_mb Speed_kt            Category
## 1 1992-08-16 18:00:00 10.8 -35.5        1010       25 Tropical Depression
## 2 1992-08-17 00:00:00 11.2 -37.4        1009       30 Tropical Depression
## 3 1992-08-17 06:00:00 11.7 -39.6        1008       30 Tropical Depression
## 4 1992-08-17 12:00:00 12.3 -42.0        1006       35      Tropical Storm
## 5 1992-08-17 18:00:00 13.1 -44.2        1003       35      Tropical Storm
## 6 1992-08-18 00:00:00 13.6 -46.2        1002       40      Tropical Storm
##      LatLong                                              Tip marker
## 1 10.8:-35.5 Tropical Depression<BR>Pressure=1010<BR>Speed=25  green
## 2 11.2:-37.4 Tropical Depression<BR>Pressure=1009<BR>Speed=30  green
## 3 11.7:-39.6 Tropical Depression<BR>Pressure=1008<BR>Speed=30  green
## 4   12.3:-42      Tropical Storm<BR>Pressure=1006<BR>Speed=35  green
## 5 13.1:-44.2      Tropical Storm<BR>Pressure=1003<BR>Speed=35  green
## 6 13.6:-46.2      Tropical Storm<BR>Pressure=1002<BR>Speed=40  green

Now for the last part…

map = gvisMap(Andrew, "LatLong" , "Tip", 
                     options=list(showTip=TRUE, 
                                  showLine=TRUE,
                                  icons=icon,
                                  enableScrollWheel=TRUE,
                                  mapType='terrain', 
                                  useMapTypeControl=TRUE))
jsData = map[['html']][['chart']][['jsData']]
jsDataNew = gsub("datajson =.*addColumn\\('number','Latitude'\\);",
                 paste("datajson =\n\\[\n", 
                       makejs(Andrew[,c('Lat','Long','Tip','marker')]),
                       "\n];\ndata\\.addColumn\\('number','Latitude'\\);"),
                 jsData)
jsDataNew = gsub("\ndata\\.addRows\\(datajson\\);",
                 "\ndata\\.addColumn\\('string','marker'\\);
                 \ndata\\.addRows\\(datajson\\);",
                 jsDataNew)
map[['html']][['chart']][['jsData']] = jsDataNew

Now you can visualize the map using plot(map) or use it in Shiny apps etc.

Tuesday, August 16, 2016

Xinweilai - platform for 100% cashback?

Is it realistic to buy things without paying?

As unrealistic as it seems, such a business model is being run in China. I was utterly surprised upon hearing about it from some relatives, and went ahead to conduct some research on the web. I found no information by running a Google search in English. Queries on Google and Baidu in Chinese returned some results, though most are posts and articles discussing the authenticity of the business.

Xinweilai (心未来) is an online platform that lets its members earn virtual E-coins by posting chicken soup messages on the website, playing puzzle games, recruiting more members etc. It is said to be the replica of another platform known as Wodeweilaiwang (我的未来网) which translates directly to My Future Web. Armed with these E-coins, consumers can then visit physical shops set up by the company to purchase goods. At the time of purchase, consumers need to pay with cash, and simultaneously their E-coin balances decrease at a 1RMB:1E-coin ratio. Around 15 days later, consumers will receive 100% cashback through a company portal. This can be cashed out to a bank account.

Xinweilai literally means Heart Future, with Heart being a homonym for New. It aims to foster a new shopping style that is supposedly beneficial for both consumers and suppliers. The general public can obtain daily necessities without spending any money eventually. Faced with the imminent increase in demand for goods, manufacturers profit.

Everything seems very rosy.

The obvious question which remains is: How does Xinweilai make money?

There are various speculations about the business model being one extensive Ponzi scheme in which cashbacks for earlier customers are paid for by later customers, or that it's just smart use of massive cash flows on the platform. The reality is unknown. It might even be a combination of both. I'm more inclined towards this theory, which I will elaborate on later.

The platform started in 2014. Without registering for an account, I can only see a simple website (http://www.xinweilai.hk/) which interestingly has a .hk domain. The legitimacy of the company is unknown or perhaps even irrelevant due to the loosely regulated Chinese market. Multi-level marketing is illegal in Mainland China, but apparently still prevalent. While researching, I found out, to my alarm, the Ezubao incident uncovered earlier this year - a Ponzi scheme involving a lender-to-lender online platform. The peculiarity of the scandal is that many victims used the platform thinking that it was backed by the government, due to successful media maneuvers such as commercials right before the news on state television. Xinweilai is definitely comparable in terms of its marketing coverage, for instance through promotional videos on WeChat, physical events at local sites, and especially by encouraging its 30 million members to develop their downline.

What makes me uneasy about Xinweilai is the exorbitant prices it charges for goods sold in the stores. All prices are set by the company and they are in general 5 to 10 times that of prices elsewhere. Depending on a member's rank, he or she can only purchase items below a certain price cap (max 50000RMB), but there is no limit placed on the number of products purchased. Moreover some forums claim that expensive items such as cars and houses can be paid for by installments. This makes me wonder what will happen if the company one day stops giving rebates. The consumer's loss would be at least 4 times the cost of the products he or she bought in the last two weeks, not to mention that the products may be totally unnecessary but were purchased since they were 'free' anyway.

I can see the idealistic future in which Xinweilai is able to sustain its mode of operation using profits from advertising on its platform.

Before going there, let's have a brief look at its revenue and expenditure. Xinweilai's main sources of revenue include product sales, advertising, investments, commission from manufacturers and franchisees, and fees. Expenditure consists cashback (same amount as sales), merchandise costs (approx 10-20% of sales), maintenance of stores, events and logistics. Due to the lack of a financial report, exact numbers are unobtainable. We assume for now that revenue from advertising and investments need to be comparable to merchandise costs in order for the company to break even. The exorbitant product prices hints that advertising revenue currently cannot totally cover expenditure. In actual fact, I'm not aware how much, if any, advertising is done on the online platform since surprisingly it is not one of the ways to earn E-coins. Then, we are left with the question if it is possible for investments using the cash flow on the platform to have a profit margin of at least 10-20%.

We all know that greater profits come with greater risks, but how comfortable would consumers be upon knowing that their money were put in high risk investments and that they risk not getting their money back. The possibilities now are that this is either a Ponzi scheme or that Xinweilai is dealing with high risk high return investments. Speculations that Xinweilai is giving rebates using deposit interests are impractical. The highest deposit interest rate in China is 3.75% at the Bank of Communications for a 5-year time deposit. Even if there is a special package for Xinweilai, would the rate go that much higher? The world's largest banks earn a profit margin between ICBC's 29% and BNP Paribas' 5% in 2014, so Xinweilai's investments have to be comparable to the best amongst the best financial institutions if these investments should be at the same risk level as the banks'.

I do not think that it is impossible for a company to earn that much profit to sustain a business model like Xinweilai's. For a platform with widespread usage, advertising is the obvious outlet as demonstrated by Alibaba and Baidu's over-40% profit margins. Furthermore, Xinweilai's platform is well-suited for this purpose as it can encourage people to consume commercials in exchange for E-coins, and earn according the cost-per-click and cost-per-view rates.

Should we embrace Xinweilai or wait and see? Use it at your own risk, literally. Treat it as an investment where you get merchandise as dividend, but do not be unprepared for a day when you may lose your capital. And if advertisements do not start popping up like wildfire, be very suspicious.

Sunday, January 3, 2016

《老炮儿》观后感

圣诞节的纽约,比平时更拥挤。电影院也不例外,连自动贩票机都被’挤‘得发生故障了。终于在圣诞节的第二天买到了《老炮儿》将近半夜才放映的票。前几天才在同一家电影院看了《The Big Short》。再看完这一部,着实觉得在纽约看这种偏写实的片子稍显不太现实。看完08年金融危机,走出去就是喧闹繁荣的时代广场。再看完人情冷暖,走出去又是人头窜动的街。

言归正传,不谈电影中一些逻辑不通的桥段,《老炮儿》还是比较有内涵的。主人公六爷不仅让我想起了我爷爷。年轻的时候谁没风光过?而如今社会变迁太快,六爷曾经的风光跟宣武一样只剩回忆和故事了。昔日的兄弟们也都一一老去。混的好的当上了公司老板,混的不好的在街边摆摊。

电影的前几分钟塑造了六爷威严的形象,就连警察都怕他三分。不过我们渐渐发现,就像他自己说的,他现在就是一个胡同里的普通老百姓,没事儿逗逗鸟,在附近闲逛溜达。所以,这是一个关于你或我或擦肩而过的任何一个人的故事,所以,它如此深刻。

六爷最讲究‘理’。自己在理的时候讲理不难,难的是自己理亏的时候也能讲理。灯罩儿无照摆摊就得交摊儿,儿子蓄意刮车就得赔钱道歉。对方蛮横虽然有错,但事儿一码归一码。错儿不是不追究,而是得一个一个追究。我们无法奢求对方也讲理。小飞这群小炮儿们仗着年轻人多势众,对年长的六爷没有半点儿尊重,说话咄咄逼人。 有时候真着急, 让三儿带着小弟跟这帮小混混干一架多过瘾。六爷却一直沉着冷静,不想伤及无辜。到头来,像小飞一样,挺佩服他的。

也说说六爷的不好。自己为儿子筹钱连做修自行车匠的朋友都问了,六爷也不向做到公司老板的洋火儿开口借钱。人家没有要赶他的意思,六爷却生了无名火。这情绪不难理解。我们有时难免对混得好的朋友有些抵触,怀疑别人是不是看不起我们,只会用钱衡量友谊。也许。但也许我们多虑了。

再说说一些不起眼却很碍眼的情节。 见有人跳楼,围观起哄的人多。见一老头儿倒在街头,疑心诈骗的人多。见有权有钱之人,帮腔作势的人多。见违法的事儿,装没看见的人多。但我们也不是没有希望。六爷收到了救助的女孩的回信,在危难时所有兄弟都愿两肋插刀,贪污违法者收到了法律的制裁。

这部游走于商业与文艺片之间的《老炮儿》在给我们提醒儿。社会风气将如何变换,在于每个人的生活原则和对人处事的态度。就算没有能飞的翅膀,我们也不是圈中的鸵鸟。再说,连鸵鸟最后都逃出来了。