Saturday, 31 May 2014

Gini Sim

The Gini Index is a measure of wealth distribution.

GiniSim is a simple Javascript program which demonstrates, in simple terms, flaws in free market economics, by showing that trading freely will lead to gross inequality. Copy the program into a .html file; save it and then open it in a browser: you can stop it by pressing the Stop button. Alternatively, you can download and run a simple Java version, GiniSim.jar from here.

Each bar is the wealth of a person, and the simulation starts with everyone having $10 (or £10, or 10€).

Each step simulates a free trade transaction, two monetary notes are picked at random and the person the first one belongs to pays the person the second one belongs to. Intuitively, you’d think this would average out: sometimes some people win and sometimes others would.

In reality what happens is that whenever a person accumulates wealth, it makes it more likely that someone poorer will give money to them. This is due to the fact that the chances of being paid in a transaction is proportional to their wealth - so if someone loses money from a transaction, they become less likely to gain in a future transaction.

How does this correspond to an idealism of the free market? It corresponds, because exchanges take place on the basis of being indifferent towards cash. Therefore when people gain wealth, their wealth acts as a bigger wealth footprint and people (who want to buy things) notice the cash more. If you’re poorer, that doesn’t happen, you’re not noticed, because your visible presence is the cash you hold - you literally disappear.

The important thing to note is that GiniSim demonstrates inequality without the agents involved behaving maliciously. All it does is play fairly towards cash (rather than people). It's a demonstration of a power law.

How does GiniSim1 not correspond to classical economics? GiniSim1 correspond to free trade under mercantilism, which is a zero-sum economic theory.

Here’s GiniSim, copy everything in yellow:

<!DOCTYPE html>
<button onclick="clearInterval(timer)">Stop</button>
<canvas id="myCanvas" width="800" height="600" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.

  var c=document.getElementById("myCanvas");
  var ctx=c.getContext("2d");
  var timer;
  var rects=0;
  var cash=[0],people=[0];
  var kStartCash=10;
  var kNumPeople=100;
  function initGini() {
    var ix,iy;
    for(ix=0;ix<kNumPeople;ix++) {
      people[ix]=kStartCash; // everyone starts with $10.
      for(iy=0;iy<kStartCash;iy++) {
        cash[ix*kStartCash+iy]=ix; // each $1 is owned by a person.
  function incomeSwap(from,too) {
    var ix;
    for(ix=0;ix<kNumPeople*kStartCash;ix++) {
      else if(cash[ix]==too)
  function exchange() {
    var aNote=Math.floor(Math.random()*kStartCash*kNumPeople);
    var aOwner=cash[aNote];
    var aNewNote=Math.floor(Math.random()*kStartCash*kNumPeople);
    var aNewOwner=cash[aNewNote];
    if(people[aOwner]>0 ) {
      // can't take cash from people who have nothing.
      while(aOwner>0 && people[aOwner]<people[aOwner-1]) {
      while(aNewOwner<kNumPeople-1 && people[aNewOwner]>people[aNewOwner+1]) {
  function drawImage() {
    var ix;
    for(ix=0;ix<kNumPeople;ix++) {

[Edit: Added link to GiniSim.jar on 20150321. Edit: I knew from the simulations that wealth always gravitates to the rich, but my reasoning for the mechanism was incorrect, because I was trying to derive it from the probabilities of a single transaction. In reality, the mechanism is due to how the probabilities change between one transaction and the next. 20150626.]


sobrevive said...

Very pretty program, but it's possible to make a redistribution such as said Levitico 25, each 49 years, in 50 year all properties come to original proprietors. Also the 1% are depending on government to make their business and to accelerate accumulation. Accumulation is realized more on countries in peripheral and by direct action political or indirect action by speculators. And other peripheral countries live in misery yet they work hard, but technology is voided for them.
I think that you must to include tendencies to diminish inequality in your model to make it more as reality, and to put the international actions that suck money in peripheral countries.
Excuse me for the critics.

Snial said...

Hi Sobrevive,

Thanks for the comment. I understand what you mean by Levitico 25; in an English Bible it's Leviticus 25, which talks about the concept of "Jubilee", that debts are canceled every 50 years.

However, the purpose of GiniSim isn't to simulate a means of compensating for free market trends but to demonstrate what happens if you don't compensate for them, i.e. GiniSim is a refutation of "Trickle-down economics". GiniSim is a good demonstration in that sense, because it doesn't simulate greed (the players are not greedy), nor does it explicitly simulate a number of other classical economic ideas such as "price signals", or "market forces", or "marginal utility". By demonstrating that random trade leads to massive wealth inequality, GiniSim also demonstrates that the principle of "pricing signals" is no different to "random trade"; which is to argue that pricing signals do not exist.