Archive for September, 2008


Wall Street Meltdown

As someone with more than a passing interest in the finance/I-Banking sector it's hard not to take notice of the meltdown that has been happening on Wall Street over the past 12-18 months. The global credit crunch / subprime mortgage crisis is already and will continue to greatly affect - in a negative fashion - not just the US economy but many other institutions that have significant expose to the US debt and equity markets. So how exactly did this happen? Firstly you need to understand the flow of money that ensues, and the various entities involved, when a lending institution offers a home loan. Here's my admittedly-niaive analysis about how the money moves around gleemed from various newspaper reports, websites and information picked up from a great book I'm reading at the moment - Liar's Poker by Michael Lewis.

  1. US homebuyers with poor credit ratings (i.e. high risk) borrow money from retail banks to buy houses.  The retail banks lending the money are more generically referred to as loan originators because they may actually be a financial institution other than a bank, but that is neither here nor there in this discussion. The high-risk folks who they lent money too are referred to as subprime borrowers. But why would the banks lend money to people who are likely to default? In short, because (a) it was a large market they couldn't ignore [about 12 Trillion USD according to the New York Times], and (b) because they knew they could offload the credit default risk to other parties...

  2. The loan originators know that loans they originate (write) can be onsold to one of several government-sponsored enterprises (GSEs) like Fannie Mae and Fredie Mac - known as mortgage guarantors. These organisations were originally setup by the US governement to guarantee subprime loans provided by retail banks that met certain conditions - termed conforming loans. This effectively made the GSEs a secondary market for home mortgages which enables the loan originators to onsell the loans they originate thereby getting their funds back which gives them the necessary capital to go and write/offer more loans. Apart from reducing exposure to credit defaults, the presence of the GSE-provided secondary market is advantageous to the mortgage originators in that it represents a cheaper way of raising capital than other alternatives such as issuing bonds or stock, or taking out a loan from another bank. But why would the mortgage guarantors choose to take on and guarantee such risky loans? Because the government set them up exactly for that purpose in the belief that less creditworthy borrowers should have access to finance like everyone else, and by providing a secondary market the government believed the mortgage market would have greater liquidity and flexibilty.

  3. The mortgage guarantors also take measures to reduce their risk by re-packing the loans that they purchase from mortgage originators into mortgage backed securities (MBS) and onselling them in the open market. (Perhaps the most common form of MBSs is the Collateralized Mortgage obligation (CMO), the rise of which, and the massive Wall Street profits associated with their introduction is precisely the topic of Liars Poker.) The re-packaging of loans is done by pooling together large numbers of subprime loans that have similar qualities. The aggregration process is suppose to reduce the risk assoicated with individual loans. It's much the same process as that which actuaries use for life insurance risk pooling only it's much harder to predict homeloan default rates than it is to predict mortality tables. Like insurance companies, the mortgage guarantors received a fee from the buyers of their MBSs as compensation for taking on the credit risk associated with the mortgages they accept. In the finance world this repackaging and onselling is called securitization. It effectively means groups of individual loans from bank X to Mr and Mrs Smith and co. are transformed into completely impersonal financial instruments than can be horse traded in the market like other securities. Furthermore the pooling of the loans means the resulting MBSs themselves become more attractive to institutional investors since they can be sliced and diced even more...

  4. Wall Street firms then buy the MBS instruments and, based on the attributes of the MBSs, re-package them again into Collateral Debt Obligations (CDOs). CDOs are a synthetic financial instrument issued by an investment bank that entitles the buyer to recieve future cash flows, much like a corporate bond. The issuing investment bank is paid a fee on issuance and also earns a management fee over the life of the CDO. For the buyer of the CDO - according to Wikipedia, "an investment in a CDO is an investment in the cash flows of the assets, and the promises and mathematical models of this intermediary, rather than a direct investment in the underlying collateral. This differentiates a CDO from a mortgage or a mortgage-backed security (MBS)."  Interestingly CDOs offer the issuing investment bank the ability to move debts off their balance sheet and instead reporting them as assets once they had been pooled via a CDO.

  5. After construction these CDOs get a credit ratings from one of the credit rating firms, S&P, Moody's, or Fitch, and are then sold on the open market to institutional investors. In some cases they are held by the issuing investment bank due to the significant leverage and higher rates that they offer. It should be noted that, when evaluating CDO "tranches", the credit rating agencies receive a fee much greater than they do when evaluating ordinary corporate bonds. This would indicate that they are harder instruments to evaluate. The agencies used to use more complex assessment models including Binomial Expansion Techniques (BET) for rating CDOs. Such methods rewarded balanced portfolios and punished concentrations of assets via "diversity scores" however in 2004 Moody's dispensed with the components of their evaluation which focused on diversity of the debt assets underpinning the CDO. Questions are now being asked about how prudent the credit rating firms were in their rush to evaluate a large number of these new insturments as their popularity increased over the years which ironically saw many of themn given AAA ratings the vast majority of which have been drastically downgraded since. 

  6. So what about that other big company that was in the news, AIG? Well, apart from being a sponsor of the Red Devils, AIG provides insurance products intended to protect against credit defaults, in exchange for a premium or fee. They are required to post a certain amount of collateral (e.g., cash or other liquid assets) to be in a position to provide payments in the event of defaults. The amount of capital is based on the credit rating of the insurer. Effectively, AIG provided "CDO insurance" to the investment banks.

 So with the money flow diagram fleshed out let's now consider how this system went so very bad.  

  1. The decline starts by subprime borrowers defaulting on their loans in large numbers. As a result of this more houses are put on the market due to foreclosures and the subsequent firesales drive down the price of houses. With declining house prices it make it significantly harder for subprime borrowers to refinance loans they realise they can't afford to service once the honeymoon interest rate period is over. The net result: it's been said that it's the worst US housing slump since the Great Depression of the 1930s.

  2. This puts pressure on the mortgage guarantors, Fredie Mac and Fannie May, and everyone else who are holding MBSs since their prices are rapidly decreasing as buyers see them as more riskier investments. Both of these GSEs ultimately got into serious finanical trouble under the weight of debt obligations they couldn't meet which caused the US government to step in and bail them out, but not before massive writedowns took place.

  3. Holders of CDOs constructed from MBSs suffer the same fate of MBS holders - they see rapid price declines causing massive loses amongst investment banks and institutional investors holding them. In many cases these organisations were using borrowed funds to purchase already leveraged CDOs. i.e the inherit leverage of the CDOs were further leveraged. These organisations (Lehman Brothers was one) were legally allowed to use such high levels of leverage since US investment banks aren't subject to the same regulations as commercial banks.

  4. The decline in MBS and CDO prices is further exacerbated by (naked) short sellers who smell blood and want to extract some profits from an otherwise poorly performing market. The downward pressure on CDO prices is noticed by other investors who want to close out their positions before incurring further losses adding to the price freefall.

  5. With banks highly suspicious of other banks going under due to exposure to business partners who can't meet their payments market liquidity for interbank lending is greatly reduced. This is reflected in 3 clearly visible metrics:

    • the LIBOR - the London Interbank Offer Rate - is the interest rate in London as which one bank lends money to another.
    • the TED spread which is the difference betweek the LIBOR rate and the interest rate on 3-month US Treasury bills. This is a key measure of funding pressures and illiquidity and has broken 3 % in recent times.
    • the credit default swaps (CDS) prices. A CDS pays the buyer face value in exchange for the underlying securities, or the cash equivalent if the borrower fails to adhere to the debt agreements. As such they are used used to hedge against bond losses as well as speculate on corporate creditworthiness. In short they are a form of insurance contract against bond defaults. With significantly more defaults happening, the price of CDS naturally increas.

So in short - the practice of lending money to people who really couldn't afford it combined with a plethora of mortgage-backed securities whose leverage couldn't be resisted by US investment banks in an environment with ineffective regulation on cash reserves ultimately led to a significant liquidity problem in the market place at a time when it was needed most. If you gamble large stakes you eventually get burned bad!


Design Guidelines Part.3: The Liskov Substitution Principle

LSP was defined way back in 1988 by Dr. Barbara Liskov, who incidently won the 2009 Turing Award, perhaps the most prestigious award in computer science. Her original definition was:

“If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.”

But Robert Martin offered a much more terse definition:

Subtypes must be substitutable for their base types

What this is saying is that a derived class should honor the contracts made by it's parent classes. In other words, if a method signature accepts a base class reference, then it should be able to accept an instance of any class derived from that base class without affecting the functioning of the method.

Object-oriented programmers will be familiar with the concepts of abstraction and polymorphism. In statically-typed O-O languages, like C++, Java and C#, the key mechanism to achieve polymorphism is inheritance. LSP is a guiding principle that restricts how inheritance is used such that the OCP is not violated.

Technically speaking, the type of polymorphism this principle addresses is inclusion polymorphism. Inclusion polymorphism occurs in languages that allow subtypes and inheritance whereby an instance of a subtype can be manipulated by the same functions that operate on instances of the supertype (parent class type). This implies a reference (or pointer) of the parent class type can also refer to any child object, meaning that the type of the object being referred to must be determined at runtime. Since the type of object cannot be determined until runtime, and virtual methods are defined per type, it implies that a method call may be executed either in the parent or the child class and this dispatch decision cannot be made until runtime.

The Liskov Substitution Principle helps to guarantee inclusion polymorphism, which is a good thing because inclusion polymorphism improves reuse. All code that references the superclass can be reused referencing a subclass.

Why Follow It?
By adopting the LSP, the correctness of a method accepting base class references is guaranteed under certain substitutability conditions. Furthermore, since LSP is actually a special case of the Open-Closed Principle, every time you violate the LSP, you violate the OCP as a result - but not the other way round. It is this relationship between OCP and LSP that makes it easier to spot since developers tend to understand OCP much more readily that they do with LSP.

Say you develop a class hierarchy using inheritance, and you have a method in your base class that accepts a base class reference, and when you pass in a derived class reference you get unexpected results, it's a strong sign that the inheritance chain and the object model is incorrect. You need to remember that a class must fulfill an "is-a" relationship in order for it to be able to inherit from another class. This relationship is about behavior not data! In this sense, LSP is good at exposing faulty abstractions.

LSP is the reason that it is hard to design and create good deep hierarchies of sub classes and the reason to consider using composition over inheritance. (The strategy pattern is a prototypical example of the flexibility of composition over inheritance.)

The whole point of the Liskov Substitution Principle is really to make you think clearly about the expected behavior and expectations of a class before you derive new classes from it.

Obligatory Example
Common examples for violation of LSP are Rectangle::Square, Circle::Ellipse, etc. Rather than reproduce those here, take a look at the examples in Robert Martin's paper.

Design By Contract
The Liskov Substitution Principle is closely related to the design by contract methodology, which provides rules telling us the conditions under which it is acceptable to substitute a derived class for a base class:

  • Preconditions cannot be strengthened in a subclass.
  • Postconditions cannot be weakened in a subclass.

In other words, a sub-type can only have weaker pre-conditions and stronger post-conditions than its base class. Put differently...derived methods should expect no more and provide no less.

Signs of LSP violations include:

  • A subclass that does not keep all the external observable behavior of it's parent class
  • A subclass modifies, rather than extends, the external observable behavior of it's parent class.
  • A subclass that throws exceptions in an effort to hide certain behavior defined in it's parent class
  • A subclass that overrides a virtual method defined in it's parent class using an empty implementation in order to hide certain behavior defined in it's parent class

Method overriding in derived classes is probably the biggest cause of LSP violations. All method overrides should be done with great impunity as to avoid these violations.

In addition, the principle implies that no new exceptions should be thrown by methods of the subclass, except where those exceptions are themselves subtypes of exceptions thrown by the methods of the superclass. (think: co-variance and contra-variance).

A function using a class hierarchy violating the principle uses a reference to a base class, yet must have knowledge of the subclasses. Such a function violates the open/closed principle because it must be modified whenever a new derivative of the base class is created, and that really sucks because the compiler or your existing unit tests won't find these cases for you - you have to become a UN weapons inspector, remember what things exactly you need to look for, and go hunt them down manually!

Final Advice
In the words of Robert Martin, Agile Principles, Patterns and Practices in C# (P.149):

"A good engineer learns when compromise is more profitable than perfection. However, conformance to LSP should not be surrendered lightly. The guarantee that a subclass will always work where its base classes are used is a powerful way to manage complexity. Once it is forsaken, we must consider each subclass individually."

Other Parts in the Series
Design Guidelines Part.1: Single Responsibility
Design Guidelines Part.2: Open-Closed Principle
Robert Martin's Original Paper