Friday, December 26, 2008

Friday, December 19, 2008

Of Madoff and Ponzi schemes

So, Madoff apparently ran a Ponzi scheme quite successfully for about 48 years. It is widely reported that he offered a 10% return regardless of the market conditions. In other words, assuming he ran this from the beginning, he would have managed to increase capital by about 100x.

I have a feeling that he might have designed the return rate so the scheme would blow up after he was dead, but that this latest crisis was too much for the cushion he had. He has been quoted as having trouble coming up with $7 billion to take care of redemptions a few days before he allegedly confessed. If he had not been forced by redemption requests, he'd be still going at it.

But what if he had offered a less attractive rate instead of 10%? Then the theoretical pile of capital would have grown slower, and so he might have had more of a chance to weather the storm. How much of a rate would that be? Particularly, what is the rate that would allow a modern Madoff to run a Ponzi scheme until after the creator's death, thus managing to walk off with a clean Louis XIV move?

Well let's see. 48 years at 10% gives us a factor of 97x or so. So now let's say we want to spread that factor over 60 years instead of 48. That gives us our Ponzi scheme return rate: 7.9%. In other words, if we start when we're say 35 years old, then running a Ponzi scheme Madoff style at 7.9% basically guarantees that the thing will explode after we die.

Now, Ponzi schemes are usually spotted by a ridiculous return. But what if they just don't do that? How could you tell the difference between a Ponzi scheme and a legitimate investment operation if you do not know the internals of how the money is invested first hand? And how many of you actually go through the due diligence? If anything, even professionals such as Banco Santander clearly did not and their customers (meaning us) lost upwards of $2 billion.

This means that any investment that offers us essentially 7.9% annualized return could, in theory, be a Ponzi scheme too --- simply because in practice we will not be able to tell the difference by looking at the return rate alone.

So let's be even more conservative and run our imaginary Ponzi scheme for 70 years. Our calculations show we should offer 6.75%. So basically, we conclude that the most conservative of Louis XIV Ponzi schemes could go ahead and attract investors with a return of 6.75%.

Of course, this is assuming the Ponzi scheme behaves too well and pretends to have gains all the time to prevent redemptions. But how could you tell the difference if the Ponzi scheme claimed losses that are not worse than everybody else's losses? In other words, how do you know for a fact that things like your retirement funds are not in a Ponzi scheme that is designed so that you do not take your money out? For example, such a scheme could a) claim to lose money when others do, b) put stiff penalties for redemptions (like the usual 10% on a 401k), c) make you wait until you're 59.5 years old...

... oh...

All of a sudden such things do not look good at all, do they? And it only gets worse. How much is the stock market usually said to return over time? 11%, right? Well, this means that, using Madoff's scheme as a ruler, we should borderline expect a full blown stock market crash at least once every 43 years, if not more frequently.

And this is where we're told to put our retirement in? You have to be kidding. This means that basically everybody's retirement will be affected by at least one major stock market crash.

Then you realize: banks also lend out more than what they have because we have a fractional reserve system. The idea is that this Ponzi scheme will not blow up because not everybody will withdraw their money at once. So why is this Ponzi scheme legal now? Says who?

But regardless. How many years could we expect the banks' Ponzi scheme to stay alive? If we assume the answer is 80 years (great depression to now), then the annualized rate of growth we get is about 5.9%. How does that compare to other investments?

Now we know that our setup is doomed to fail periodically. Guess who will bailout the banks when we cannot repay the loans back: that's right, us again. And if we cannot print money to pay for the mess because nobody cares for that, guess what: we pay in titles of interest such as real estate, or companies, etc.

The only winners in this game are those very few that set it up in the first place. Are we clever or what...

Saturday, December 13, 2008

Fundamentals update

Chapter 4 reached 100 pages. The draft is 216 pages long.

On debt

Sometime ago I met a guy that tried to sell me a debt reduction program. Basically, the deal was that I had to pay $3750 to get a computer program that would tell me how to allocate payments to serve any debt that I could have. Furthermore, he claimed this program was able to compress debt. He put himself as an example: he had 19 years to go in his mortgage, but he paid it in 6.

And you know why this works? Because the program has an algorithm. He even asked me if I knew what an algorithm was.

Now of course, since this works, I can recoup my $3750 by selling the program to a few other people that I know, and since I get $1000 every time I sell it... and so on... well, you get the idea. A typical multi-level marketing scheme.

He must have observed I wasn't too moved by his arguments, because then he suggested that I could buy the program used to do evaluations on people at $175, and still get the $1000 per customer I dupe into this.

So let's set the record straight, algorithm and everything.

The most important rule for debt reduction is simple. You can do whatever you want with the money you earn, but you are not allowed to increase your debt.

Let's say you want a camera today but you only have 40% of its price in available cash. Well, that's too bad: you get to save money month by month until you can buy it cash.

Or let's say that you want to buy a camera today, but you will have all the cash available in a few days. Fine, use the credit card. But when the statement comes, you are not allowed to let it go higher than before.

Now that things are not getting worse, we go to the second rule. This one is about scheduling payments. The debt dollars that cost you more in interest are those attached to higher interest rates. Therefore, you must pay those first. And yes, that means that if you owe $100 at 20% and $10k at 19%, you pay the $100 at 20% before you go after the chunk at 19%.

How do you pay the higher interest debt first? Simple. By allocating minimum payments to everything else, and then using as much as you can to go after the high interest debt.

For the sake of illustration, imagine you have $10k at 8%, $15k at 7%, and $20k at 9%. Assume you have $1000 to pay bills. Then, you make the minimum payments on the $10k and $15k, let's say those are $190. So you have $810 left, and that's what you pay on the $20k.

So now, rule 1 says you will not get worse. Rule 2 says you're paying in the most efficient manner. The third and last rule says that you must include every debt into this arrangement. In other words, your car and mortgage payments also count.

If you follow this strategy, then you will be out of debt in no time. And please, don't do stupid things like paying $3750 to have a program tell you how to allocate payments. Besides the fact that this would violate the first rule, you do not really need help to pay bills yourself. Also, you will avoid paying for the cruises these salespeople take.

Pfft... algorithm...

Finally, what do you do when you pay all your bills and have zero debt? Assume that your savings account needs money, and periodically drain any gross excess out of your checking account. You will be amazed at how quickly you can build up savings in this way. Then get yourself some goals and go after them.

PS: The fine folks at Debt Consolidation Connection left me the following comment.

Charge the $3750 to your credit cards. That would be a good start!

Not only this is spam: it is nonsense. Gee, you're so much in debt that you're looking for help, so how about you pile another $3750 on your credit card to start getting rid of your obligations? You have to be kidding --- or scamming people into giving you money for no good reason.

Oh, and by the way, multi level marketing schemes are a whisker away from being a pyramid / Ponzi scheme, which would make them illegal. And don't just take my word for it, see here.

Friday, December 12, 2008

Say hello to e^x: illustration

Look at this lady talking about her situation.

Ms. Leavitt said she recently discussed her investment with a friend who told her he was suspicious about the firm's ability to generate such profits amid the economic crisis. "I thought, 'He's probably just jealous,' " said Ms. Leavitt. "We've been with [Mr. Madoff] for 15 years, and it's grown every year at 10%."

Really. Mr. Madoff is currently out on bail because apparently he confessed to running a Ponzi scheme worth $50 billion dollars.

Ten percent yearly growth is clearly e^(ln 1.1)x, where x is time measured in years. You know that can't keep happening forever --- even if you wish with all your heart that it was possible. So sorry, but no.

Susan Leavitt of Tampa Bay, Fla., said she had several million dollars of inherited money invested in the firm and added $500,000 earlier this year. A stay-at-home mother with two children, the 46-year-old Ms. Leavitt says she is considering going back to work. "That was my nest egg for the children, and my future. I'll never see much back, I'm sure," she said.

What to say, right? Well, my friend, there you go. Next!

Thursday, December 11, 2008

Say hello to e^x

I had an interesting conversation today. We were discussing the auto industry mess, and what was the root cause of all of it.

Now, to me, in the end all of this is due to thinking that there will be exponential growth forever. It just doesn't work that way. We love it when we choose to believe it does, because we do well at the expense of somebody else that suffers the consequences. We never see those people, so everything is cool. But when we (meaning the people that happen to live in one of the countries that usually do well) do not do well, chances are nobody is doing well, and therefore we say things like "oh this is global", "everybody is in the same boat" etc. In other words, we have no real incentive to look at our behavior.

But unfortunately I couldn't advance this argument on the guy because I was sure he'd look at me funny if I invoked the presence of one of my dear friends, e^x. So what to do?

I decided to put in these approximate terms. I told him I was the Federal Reserve, and that he represented all the people in this country. Furthermore, I set the rules saying that I was the only entity able to create money. Then I told him that at the beginning of the game, he has no money. So what would he do?

Of course he asked me for money. "Ok", I said, "I am going to give you $1 trillion dollars". And, giving him four packets of sugar, I told him that I would charge him interest and so he would eventually have to pay me back five packets of sugar.

At this point he said "well but if I do not make money, then I do not pay you back and then you lose money". My answer: "and even if you do well, where do you think you're going to get the money from?... remember, I am the only person that can give you money".

In other words, I could not care less if everybody goes bankrupt. They still owe me, and I know because a) I gave them the money in the first place, b) I am the only person that can do that, c) I charged them interest so they owe me more than what they have. Besides, in the real world, he guarantees the money I decide to print, so I know for a fact that this cannot go wrong.

He agreed to these ridiculous terms.

Eventually he realized he'd have to come back to me to get more money so he could pay me back the interest on the $1 trillion. I told him I'd charge him 5%, and so he needs $50 billion. Then I picked up two more packets of sugar and gave those to him. Of course I'd charge him interest on that too, and so I decided that although he had 6 packets of sugar, he owed me more like 8.

At this point he realized the whole exercise was absurd, and gave me back all the sugar saying "here, take your money back, I do not want to play this game". I answered with "sure, but you still owe me, so what I am going to do after you run out of money is to print myself a little more money and buy everything you have for $1". After all, he owes me, he doesn't have the money to pay, and so I can wait any amount of time necessary for him to get so indebted that I can pay him whatever I feel like --- even $1.

He didn't like the consequences. So after a moment of reflection he goes "but well, in the end all this money is worthless... why do you (meaning the Fed) play this game?". So I said "it gives me power to do whatever I want --- for example, since I managed to get you to believe these pieces of paper are worth something, I can give these to you and then I can have whatever I want in exchange". Puzzled face. "In other words, since I own everything, then you are my slave because remember, you still owe me". Silence. "Have you ever seen a bank manager such as myself go to jail, do badly, or suffer any kind of hardship, here or in any country?". More silence. "See?".

Now, back to my tea.

Wednesday, December 10, 2008

Smalltalks 2008 --- Trip to Tigre

On Sunday, after the conference, the organization committee treated Alan Knight, James Foster, June and Monty Williams, and Victor Koosh to a rowing trip. James Foster just posted his set of photos of the event at the Buenos Aires Rowing Club. Enjoy!

Sunday, December 07, 2008

Implicit receivers, v3.0

It seems to me that what I said in my original post has taken a life of its own and is now evolving into something that I do not think I ever meant to say. So I thought I'd offer the following clarification.

What I do not like of implicit receivers, as implemented in a number of languages, is that their design is guided by a desire to have an economy of writing. This dislike, personal and subjective as it is, comes from my own experience: pushing too strongly to write less will lead to code that becomes unnecessarily hard to read as time goes by. So, over the years I've changed my style and choice of wording with reading speed in mind.

In other words, given the usual statistic is that programmers spend something like 90% of their time reading code, then I'd rather optimize that instead of the fraction of a second that I will need to type "self" every so often.

This is the whole point of what I wrote in the first place. A matter of writing code designed with some specific reading goals in mind, and nothing else.

Now, given this, what I have read and heard gives me the impression that it is perceived that what I've gone after is the whole idea of having a receiver other than self or something like that. If I understand correctly, what Newspeak uses the possibility of implicit receivers other than self for is to access behavior from an enclosing class. As far as I can see, that would be roughly equivalent to using super, but since the idea of super does not seem totally adequate for the purposes of Newspeak (or Self... what does super mean when you don't have a class hierarchy?), then we have implicit receivers so that messages can naturally flow to either self or outer.

Again, as far as I can see, this arrangement is used for the sake of modularity in Newspeak. I certainly sympathize with Gilad's take on modularity. Globals, singletons and the whole lot can be an invitation to poorly written code, and I've also seen more than my fair share of that. This was evidently clear to me back at the keynote presentation at Smalltalk Solutions 2008 when I heard Gilad's opinions first hand, so I think any perceived disagreement of goals regarding this matter should be disabused from existing.

This does not mean that I do not still think that the current implicit receiver arrangement favors economy of writing over what I'd describe as more explicit expression of intention. This may be a matter of taste, and I also hope it is clear that this may just amount to a personal opinion.

So, now the question becomes: is this assessment not reasonable? Is it unfair to state that Newspeak's implicit receiver grammar is designed with code size in mind? I think not, because Vassili's latest post points to a paper by Gilad in which the matter of implicit receiver design is explained. And as it turns out, the way in which implicit receivers are implemented has a lot to do with brevity.

Page 6 of Gilad's paper has a section entitled Unambiguous Interpretations, and in it there is a list of four choices for implicit receiver design. The first item describes the pros and cons of using Smalltalk's approach, which is to require an explicit receiver for every message send. This is said to solve the problem of ambiguity, however,

[...] Newspeak (unlike Smalltalk) is an entirely message-based language. It would be unduly burdensome to have to specify an explicit receiver for every message send in a language where everything is a message send. While mandating an explicit receiver may be a reasonable approach in some languages, it is not appropriate for Newspeak.

It is clear that this decision is at least influenced by the sake of being terse. Not that I dislike this per se, as I also try to write code that is not unnecessarily long. Nevertheless, my observation is that the use of implicit receivers (probably) makes determining the receiver of a message more difficult because now the first "word" in a "statement" has to be scanned to the end to see if it ends with $: or '::', thus allowing to decide whether it is a receiver or not.

It so happens to be that I prefer prefixes rather than suffixes in this case, and thus my concern with making the grammar more complex for the sake of writing less.

Now, of course a prefix/suffix problem also occurs in Smalltalk when one has to determine the meaning of a string of "words". Is it a unary message chain or a keyword message? However, at this point the receiver has already been read because its position is fixed in a sentence, so what is being seen past that can be assumed to be a message of some sort.

Thus, since my experience has been that attempting to aggresively optimize how programs are written so they are shorter is counterproductive in the long run, I tend not to like this as much at least at first sight.

But what is the definition of aggressively, and what constitutes too much of it? Good question. I wish I knew how to unequivocally quantify this in general, or at least for this case in particular. Alas, other than a somewhat mild suggestion to consider the consequences of terseness from the point of view of the 7 +/- 2 guideline, I do not have a good answer to offer.

Finally, I would like to make it clear that I do not have experience with Newspeak nor Self. Please point out any technical inaccuracies in the discussion above so I can fix them. Thanks in advance.

Wednesday, December 03, 2008

Class name size in large scale application

This is a data set I ended up not using, but I might as well share it in case it helps others. It's a set of code metrics for a large scale financial application (no, not that one... the data comes from XTrade). In this case, the information provided refers to the sizes of class names. Here are the results*.

  • 13318 classes.
  • Arithmetic mean name size:
  • Harmonic mean name size: 10.04.
* Full data in array format. An integer j at position k means class name k occurred j times. #(9 18 2370 1072 1708 1488 1333 1490 1862 1906 2053 2317 2429 2330 2456 2361 2399 2347 2206 2093 2041 1960 1924 1792 1564 1592 1393 1374 1160 1055 1001 957 840 761 748 615 634 563 467 448 421 396 318 306 289 231 246 206 187 156 168 141 115 96 83 85 75 70 60 61 40 44 38 44 27 36 32 22 21 12 17 11 15 13 10 6 7 7 4 4 5 3 3 5 3 2 0 3 1 0 1 0 0 1 0 0 0 2 0 2 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 2)

Tuesday, December 02, 2008

Keyword size in large scale application

Ah, here we go. Here are the results for a large scale financial application. No, not the one you are thinking about. This one has 12.5k classes and 750k LOC. The results are as follows*.

  1. 191466 keywords in total. Arithmetic mean keyword size 18.08, harmonic mean 12.05.
  2. 96490 keywords, about 50%, occur with these 12 most frequent sizes (in order): 11, 9, 13, 14, 12, 15, 16, 17, 10, 18, 5 and 19. For this subset, arithmetic mean keyword size 13.11, harmonic mean 11.64.
The glass seems half full on the side of more than 10 characters...

* Full data in array format. The array has 133 entries. The first one corresponds to size zero. #(1 45 349 4881 3125 7181 5133 5519 6140 9286 7472 9678 8331 8616 8406 8086 7807 7652 7255 6720 6290 5910 5397 4966 4517 3985 3806 3304 3075 2690 2401 2199 2073 1761 1660 1559 1297 1310 1144 978 945 883 782 705 652 614 514 523 414 379 330 341 283 259 206 200 181 158 135 135 118 99 92 83 77 42 43 37 29 31 15 20 15 21 14 13 7 8 8 5 4 6 3 3 6 3 2 0 3 1 1 1 0 0 1 0 0 0 2 0 2 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 2)

Comment moderation policy

It has come to my attention that at least one of you posted a comment for which I received no notification. Furthermore, I cannot find the comment provided, so I cannot approve it for moderation purposes.

However, the email I got regarding this missing comment was written under the assumption that I had rejected the comment during moderation. Clearly, that is the impression the apparent behavior of the blog gives. So I thought I'd outline the policy I use to moderate comments.

  1. comment isSpam ifTrue: [self reject: comment. ^self].
  2. comment isGrosslyOffensive ifTrue: [self reject: comment. ^self].
  3. self publish: comment.
Therefore, if you have not seen one of your comments, and you do not think it was spam or grossly offensive, then chances are I didn't even see it. Hopefully this makes things a bit more clear.

Monday, December 01, 2008

On implicit self, v2.1 --- size of keywords

Vassili commented that most of the time, things like keywords are small enough so that the $: (or '::') fits within the bounds of our fovea and so we recognize words at a glance as opposed to scanning them.

A word is taken in at once in one saccade, and a terminating colon is perceived immediately. You don't have to "scan to the end" to see if a word is an identifier or a keyword, you just see it. Even if you don't believe it. Exception are words too long to fit in the fovea (more than 10 characters or so for the usual reading conditions), but even so a colon falls in the right parafoveal area and is still recognizable thanks to its distinctive shape (some typefaces can make it easier or harder than others).

So I decided to run an experiment. Evaluating the following code (sorry for the nasty variable names)

(ByteSymbol allInstances collect: [:x | x keywords]) inject: Bag new into: [:t :x | x do: [:y | t add: y size]. t yourself]


and then digging through the bag's dictionary reveals the following.

  • There were 73408 keywords in 62107 symbols.
  • Sorting the keywords by size frequency (to see which keyword sizes occur more often) reveals that 36789 keywords (about 50% of the keywords in the following 11 sizes: 11, 10, 12, 14, 9, 13, 15, 16, 17, 5 and 8, in that order) have an arithmetic mean size of 11.85 characters. The corresponding harmonic mean keyword size is 10.63.
  • The arithmetic mean keyword size for all keywords is 16.94 characters. The corresponding harmonic mean keyword size is 10.79 characters.
So it seems that at least half of the time we're pushing keyword sizes past 10 characters. Even taking out outliers with the harmonic mean results in 10.79 characters per keyword*.

It seems reasonable to suspect that most of the words we use when programming do not fit the fovea (usual reading conditions)**. What are the implications for reading the code in which these words appear? What should be concluded here?

* In the sampled image. Your mileage may vary. I wish I could run the stats in large scale applications to see what numbers occur in the field. From my direct experience, I would not be surprised to see harmonic mean values of 15 or larger.

** Full data in array format. An integer j at index k says keyword size k occurred j times. All sizes from 1 to 78 occurred at least once. Consequently, the array has 78 integers. #(261 388 2112 1389 2992 2210 2536 2944 3471 3561 3756 3536 3410 3510 3372 3185 3052 2740 2436 2423 2016 1733 1652 1319 1154 1050 855 842 721 631 607 576 562 547 468 445 466 439 382 381 352 323 334 266 277 238 210 181 182 136 122 112 84 65 39 54 35 32 33 35 27 16 16 15 9 16 15 12 7 6 11 6 2 4 2 1 2 1)