hit counter

Timeline

My development logbook

Dysfunctional Market?

In an ABC’s podcast, Dr Paul Woolley gave an speech on Financial Sector Dysfunctionality. Indeed, witnessing series of financial stuff-up’s in last centuries, one bigger than the other, shouldn’t we slow down and take a good look at this interesting business sector?

Paul used his personal experience in the adoption of momentum trading to illustrate some recent worrying changes in the financial market. I don’t think I can paraphrase very well, so please read full transcript here.

These days, financial sector is growing faster and larger, and taking increasing bigger share in GDP. It is, however, not entirely a result of the sector doing a better job as an intermediary between investor and borrower. Instead, especially after the rise of hedge funds, more and more financial operations are making profit from market volatility or other speculative behaviors. The money changed hand in the process has far exceeded the actual value of the annual global output. Does it make sense at all?

We can always reduce the phenomena to human greed and fear. In the other word, a financial market is for speculators to speculate, just like what Las Vegas is for gamblers.

But, could it be something more? If we know it is wrong and yet we fail for it decades after decades, could it be something more hideous that’s lurking in our collective psychology?

Could it be similar to the construction of the Pyramids in Ancient Egypt? When a society make a collective economic choice and believe that a certain non-productive, expensive activities, conducted by a handful of elites, should be handsomely rewarded by the general public at large, is it a social/organizational problem?

For argument sake, let’s assume it is. Then what purpose it serves? Could it be just a natural device to stabilize human population (e.g. to creating a underclass who either died of starvation or illness), or an essential mechanism to hold a society together (akin to a common religious experience)?

Actually the religious analogy can be further developed.

  • The various indexes are like the Oracle. It may or may not tell the future direction of the economy.
  • The big financial houses are like Temples. High priests are there to talk to the Gods.
  • Their royal servants, me included, dutifully takes up the responsibility of all daily housekeeping activities and, most important of all, money collection. We highlight the blessing one will receive if they sacrifice all their income to our product, and unconceivable suffering if they do not put away their for investment.
  • Occasionally we have good news to the people: “Rejoice, the Oracle of Gods hath spoken. A new era has come. Sell all your belonging and buy the stocks of these websites!”
Well, I think you have got the idea.

But seriously this topic deserves a more systematic, in-depth treatment.

Why I Choose to Learn Erlang?

Just think it may be worthwhile to commit it in writing for sharing.

In summary, my decision is only partially based on the technical merit or language features.

First take a look back at year 2001. Motivated by the desire to find a better, more reliable way to develop software, I learned and switched to Linux platform in this year. For anyone serious in learning unix family OS, bash, awk, sed and perl scripting are literally the “basic dance steps”.

Then I moved on to Python (see my first blog if you have plenty of time to waste :–) ).

Now fast forward a few years. From Python, I soon learn about these big names such as Guido van Rossum and Peter Norvig etc, and for some reasons, stumbled upon Paul Graham and his famous essays.

One of his famous idea on computer language is: there are reasons why some languages are superior than other languages, and Lisp is the most powerful among them. (Alright, I made the assertion for him, he probably never really put it exactly this way. Did he?)

So, convinced by the argument that a language is key to a programmer’s productivity, I decided to give Lisp a try. The syntax, or the lack of it, is indeed a challenge, but the concept of “code is data, data is code” is very powerful. Macros and CLOS are effective techniques in Lisp programming.

Fortunately there are a lot of resource.

Actually I should put it this way: “too much resource”.

Indeed, if you look at variety in the implementations of mainstream Lisp, and its derivative, Scheme, you will find these choices: Common lisp (clisp), CMUCL (CMU lisp), Kawa (Scheme on JVM), PLT Scheme, Scheme 48 etc… The list goes on and on.

It is the common phenomena of *nix world: the Fragmentation.

As a result, for any partitioner in commercial software world, it becomes a hard problem: given limited free time for self-study, we are confronted with these choices:

  • which language (Lisp or Scheme)?
  • which version (R5RS or R6RS or some subset, in the case of Scheme)?
  • which implementation of the language (the usual portability vs power/library issue)?
It makes my research long and tedious. If I bet on a wrong horse, I will lose a lot of valuable time, right? What if I am in a middle of a project and encounter a bug in the lisp/scheme interpreter I am using, will there be adequate community support? What if…

Does the risks justify the potential gain from the use of Lisp/Scheme?

Then I discovered Erlang.

The following reasons make me think, form my particular situation and career need, Erlang is probably the safest bet (or most cost-effective investment):

  • It has all the beauty and expressiveness of a functional language
  • You gain concurrency for free (built-in support in syntax and kernel)
  • You gain fault tolerance for free
  • You gain distributed processing for free
  • The language and library are robust and battle-tested in demanding Telecom industry.
  • It does not suffer from the implementation fragmentation of Lisp/Scheme.
  • The language evolution is well controlled (by Ericsson)
It is a pragmatic choice from a software builder’s point of view.

Little Erlang Exercise 6

Problem Definition: Euler Problem 6

This problem is very straight-forward.


“”“
The sum of the squares of the first ten natural numbers is,
1+ 22 + … + 102 = 385

The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)2 = 55 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 – 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
”“”

if name == “main”:
Max = 100
SumOfSquare = sum([pow(X, 2) for X in xrange(1, Max + 1)])
SquareOfSum = pow(sum([X for X in xrange(1, Max + 1)]), 2)
print “%d” % (SquareOfSum – SumOfSquare)




Here is the corresponding erlang version.


-module(p6).
-export([find_diff/1]).

find_diff(Max)–>
SumOfSq = lists:foldl(fun (X, Y) –> X + Y end, 0, [X*X || X <– lists:seq(1, Max)]),
SqOfSum = math:pow(
lists:foldl(fun (X, Y) –> X + Y end, 0, [X || X <– lists:seq(1, Max)]),
2),
SqOfSum – SumOfSq.



Basically, both python and erlang offer very powerful list comprehension syntax.