Thursday, April 25, 2013

Visualization tools, Python, Ruby, Web Frameworks and more

Today I came across a tweet mentioning about Rega. Rega is an experimental project of Ruby wrapper for Vega.  Vega is a Visualization Grammar.  You can read more on Vega in this documentation.  Vega is strongly influenced by Protovis and d3.  By the way, d3 is the successor of Protovis - developed by Mike Bobstock et. al.

d3 is a javascript library for Visualization.  Some examples exhibiting the capabilities of d3 are in this Github Gallery I worked a little in d3.  Working with d3 is fun and the visualization that can be created are very cool.

Coming back to Vega, which is a Visualization Grammar - other similar grammars are Grammar of Graphics, ggplot2, Tableau's VizQL.  Tableau is a proprietary visualization software. Also there is Google Chart Tools.  You can play with these charts in Google Code's  Code Playground.  Google Chart is offered as R package googleVis which can be directly integrated from R programming language.

Recently, I had a chance to try Python.  Though, I have been a regular in Pycon talks in Chennai, I never used it much.  Perl has been my favorite for many years.  Now, I have started liking Python.  Also, I tried a few things in django, a web framework in Python - it is very powerful.  There are other web development frameworks available - Pylons (more a content management system), BottlePy, CherryPy, WebPy. Complete list here. 

And, there is a way you can bring in the power of d3 visualization from the django framework itself. You can explore the django-nvd3 package (which is still in beta).  D3, Vega, GoogleVis etc are relatively very new technologies.  

Also, had a chance to look into Ruby and Ruby-on-Rails.  It can one-on-one be compared to Python and Django.  There are some interesting discussions in StackOverflow discussing the pros-and-cons.  See here for a comprehensive list of Ruby web frameworks. 

Ruby (1995) interestingly is inspired by Perl, Lisp, Python etc. I am yet to try something in Ruby. The designer of Ruby Yukhiro Matsumoto works with Heroku (a PaaS - Platform as a Service company).  Probably, since Pe(a)rl was already there, some discussion went on naming the new programming language Coral or Ruby, and finally settled on Ruby. Interesting! 

Ruby site is generated by a site-generator called Jekyll, the author of Jekyll talks more about it here.

In exploring all these, came across something called CoffeeScript, which is a ease-to-program script which is compiled into a javascript. See this left to right translations of CoffeeScript and JavaScript code to see the simplicity of CoffeeScript.
With indentation for the control, iteration and function blocks, instead of the traditional braces, this looks very similar to Python. An additional info: Dropbox which initially had JavaScript code now uses CoffeeScript.

Thursday, April 11, 2013

Margin of Wins in IPL

Just got curious how the winning margins were in the all 5 editions of IPL combined (from 2008 to 2012).  So, I drew the frequency pattern (statistically speaking - histogram) for the margins in terms of both runs and wickets.  This is how it looks like:


As people expect and want, most of the matches are close contests - with the teams winning by 1-20 runs. 
In this analysis - I have not taken the tied matches into account.  And, in the chasing wins, most do so comfortably by 4 to 7 wickets to spare.

Interesting to look these completely different distributions!

Thursday, March 28, 2013

A Geometric Puzzle







Find the area enclosed by the 4 arcs in the figure (shaded in grey)

The figure is drawn as below

1. A square is drawn with side "a'

2. With the side of square as radius, 4 quadrants are drawn with centre at each of the vertices.


Wednesday, January 23, 2013

Gold Import Duty Raised!

This was the news of the day.  Import duty on gold raised from 4% to 6%.  And, just a day after that announcement, Govt. followed with another one, raising the import duty of raw gold (called Dore, an alloy of gold and silver) from 2% to 5%.   News Item in Live Mint: http://goo.gl/JWQmh

Reason: Controlling the Current Account Deficit.

What is Current Account Deficit? 
It is the amount by which the total imports exceed the total exports.  A country having current account deficit imports more (goods and services) than what it exports and owe the rest of the world from revenues generated within the country.

Why increase import duty on gold?
India imports approximately 900 tonnes of gold per year.  That is approximately 20% of Annual Gold Demand of around 4500 tonnes. (Data: World Gold Council, Demand Trends http://www.gold.org/investment/research/regular_reports/gold_demand_trends/ ).  As quoted from this article (http://goo.gl/7KXaA) of Live Mint Gold imports constituted 11.5% in India's total imports basket in 2011-12 in value terms, growing from 6.9% in 2008-9.\
This means there is a drastic increasing trend in gold consumption.  Gold does not contribute greatly to the real economy of the country - as most of gold imports are for jewelry and coins which get promptly stored in households and safety lockers.  See this article by Nilesh Shah on Indian consumers crazy appetite for gold http://goo.gl/lZA2z  He warns that if Indians stop buying gold, the gold bullion market may crash (and such a price correction may in fact be welcome)

Can I do something as a retail investor?
Yes, one can reduce the consumption of gold.  Or to put in better words - look for investment opportunities other than gold.  Because, the gold investment habit of Indian housholds is costing the country dearly in terms of widening the current account deficit.  And, Govt. of India, at this point is signalling the same to the investors.  It is up to the individual investors to take cue and act accordingly.

Wednesday, May 16, 2012

KXIP v CSK Preview

With a win against MI, now KKR is also into the final four!

Tomorrow's KXIP v CSK match may produce a third semifinalist in CSK. But, if KXIP wins, then CSK will join RCB, RR and KXIP in 20+ % chance of making it to semi-finals.  A loss for KXIP and their semi-final spot is gone for sure!

MI, RR, RCB, KXIP - all want CSK to lose!


Team Current Chance   KXIP v CSK  
    KXIP wins CSK wins No Result
DD 100.00 100.00 100.00 100.00
CSK 64.06 28.13 100.00 81.25
DC 0.00 0.00 0.00 0.00
RCB 18.75 25.00 12.50 25.00
MI 81.25 93.75 68.75 68.75
RR 21.88 25.00 18.75 25.00
KXIP 14.06 28.13 0.00 0.00
KKR 100.00 100.00 100.00 100.00
PWI 0.00 0.00 0.00 0.00

MI v KKR Preview

It is clear that CSK and RCB are least bothered about this match!  Though RCB may hope for a rare "no result" for this match, as that boost its chances of getting a semi-final spot.

RR wants KKR to win.

KXIP wants MI to win.

Team Current Chance   MI v KKR  
    MI wins KKR wins No Result
DD 100.00 100.00 100.00 100.00
CSK 64.06 64.06 64.06 64.06
DC 0.00 0.00 0.00 0.00
RCB 18.75 18.75 18.75 21.88
MI 90.63 100.00 81.25 96.88
RR 18.75 15.63 21.88 9.38
KXIP 16.41 18.75 14.06 14.06
KKR 91.41 82.81 100.00 93.75
PWI 0.00 0.00 0.00 0.00


Tuesday, May 15, 2012

DD v KXIP Preview

DD wins and they are through to the play-offs.  But, what happens to other teams with a Delhi win?

The table below looks at different results of this match and how that affects the chances of other teams to make to the semi finals.

Semifinal Chance %

Team Current Chance   DD v KXIP  
    DD wins KXIP wins No Result
DD 96.88 100.00 93.75 100.00
CSK 57.03 64.06 50.00 64.06
DC 00.00 0.00 0.00 0.00
RCB 20.31 18.75 21.88 18.75
MI 89.06 90.63 87.50 87.50
RR 17.58 18.75 16.41 16.41
KXIP 30.66 16.41 44.92 21.88
KKR 88.48 91.41 85.55 91.41
PWI 00.00 0.00 0.00 0.00

DD win improves the chances of CSK, MI, RR and KKR to get a semi-final berth.  Also, it is clear that only RCB will hope for a Kings XI's win in this match.

Monday, May 14, 2012

MI v RCB Preview

This blog post is updated, as there was an error in my calculation earlier.  Today's win will not take MI to semi-finals. Thanks to @rajeshstats for pointing out.

Mumbai Indians have their match against Bangalore today.  If MI wins this match, they are through to the play-offs!

Surprisingly, the other contenders for the play-off slots look forward to an MI win!

Here is the chance table.  This is based on the current points that the teams have gathered and on an assumption that the relative position of NRR does not change.

Team Current Chance RCB v MI
RCB wins MI wins No Result
DD 97.85 98.44 97.27 97.27
CSK 36.04 33.01 39.06 33.01
DC 0.00 0.00 0.00 0.00
RCB 50.68 76.37 25.00 58.59
MI 74.46 56.74 92.19 76.17
RR 19.97 20.21 19.73 19.73
KXIP 28.61 24.71 32.52 24.71
KKR 92.38 90.53 94.24 90.53
PWI 0 0 0 0

Team Current Chance RCB v MI
RCB wins MI wins No Result
DD97.85 94.53 96.09 96.09
CSK 36.04 27.34 39.06 27.34
DC 0.00 0.00 0.00 0.00
RCB 50.68 68.75 23.83 52.34
MI 74.46 85.94 100.00 98.83
RR 19.97 12.30 14.26 14.26
KXIP 28.61 20.61 32.52 20.61
KKR 92.38 90.53 94.24 90.53
PWI 0.00 0.00 0.00 0.00