Quantboy’s Weblog

Just another WordPress.com weblog

Patterns

Good writeup on patterns on wiki.

Wait a second. A flyweight factory is just a cache of common objects- with public methods which can do things for you. Instead of creating new objects each time, use the flyweight factory to get an instance of an object- which has some common attributes and which also has a method for use to return unique attributes.

Written by quantboy

March 9, 2008 at 1:27 am

Posted in Patterns

Perl Array Efficiency Questions Answered

I was wondering if it’s safe to use a shift on an array in Perl?  Wouldn’t Perl move all array items – taking just about forever on a large list?

The answer is- No.  Explained in detail on perlmonks.

It turns out the shift function is efficient to use in perl- an O(1) operation.

Written by quantboy

February 23, 2008 at 2:07 am

Posted in perl

Credit Default Swaps

Arcane Market Is Next to Face Big TestBy GRETCHEN MORGENSON Published: February 17, 2008

Few Americans have heard of credit default swaps, arcane financial instruments invented by Wall Street about a decade ago. But if the economy keeps slowing, credit default swaps, like subprime mortgages, may become a household term.

Credit default swaps form a large but obscure market that will be put to its first big test as a looming economic downturn strains companies’ finances. Like a homeowner’s policy that insures against a flood or fire, these instruments are intended to cover losses to banks and bondholders when companies fail to pay their debts.

The market for these securities is enormous. Since 2000, it has ballooned from $900 billion to more than $45.5 trillion — roughly twice the size of the entire United States stock market.

No one knows how troubled the credit swaps market is, because, like the now-distressed market for subprime mortgage securities, it is unregulated. But because swaps have proliferated so rapidly, experts say that a hiccup in this market could set off a chain reaction of losses at financial institutions, making it even harder for borrowers to get loans that grease economic activity.

It is entirely possible that this market can withstand a big jump in corporate defaults, if it comes. But an inkling of trouble emerged in a recent report from the Office of the Comptroller of the Currency, a federal banking regulator. It warned that a significant increase in trading in swaps during the third quarter of last year “put a strain on processing systems” used by banks to handle these trades and make sure they match up.

And last week, the American International Group said that it had incorrectly valued some of the swaps it had written and that sharp declines in some of these instruments had translated to $3.6 billion more in losses than the company had previously estimated. Its stock dropped 12 percent on the news but edged up in the days after.

A.I.G. says it expects to file its year-end financial statements on time by the end of this month with appropriate valuations.

Placing accurate values on these contracts is just one of the uncertainties facing the big banks, insurance companies and hedge funds that create and trade these instruments.

In a credit default swap, two parties enter a private contract in which the buyer of protection agrees to pay the seller premiums over a set period of time; the seller pays only if a particular credit crisis occurs, like a default. These instruments can be sold, on either end of the contract, by the insurer or the insured.

But during the credit market upheaval in August, 14 percent of trades in these contracts were unconfirmed, meaning one of the parties in the resale transaction was unidentified in trade documents and remained unknown 30 days later. In December, that number stood at 13 percent. Because these trades are unregulated, there is no requirement that all parties to a contract be told when it is sold.

As investors who have purchased such swaps try to cash them in, they may have trouble tracking down who is supposed to pay their claims.

“This is just a giant insurance industry that is underregulated and not very well reserved for and does not have very good standards as a result,” said Michael A. J. Farrell, chief executive of Annaly Capital Management in New York. “I think unregulated markets that overshadow, in terms of size, the regulated ones are a real question mark.”

Because these contracts are sold and resold among financial institutions, an original buyer may not know that a new, potentially weaker entity has taken over the obligation to pay a claim.

In late 2005, at the urging of the Federal Reserve Bank of New York, market participants agreed to advise their trading partners in a swap when they assigned contracts to others. But it is unclear how closely participants adhere to this practice.

It would be as if homeowners, facing losses after a hurricane, could not identify the insurance companies to pay on their claims. Or, if they could, they discovered that their insurer had transferred the policy to another company that could not cover the claim.

Credit default swaps were invented by major banks in the mid-1990s as a way to offset risk in their lending or bond portfolios. At the outset, each contract was different, volume in the market was small and participants knew whom they were dealing with.

Years of a healthy economy and few corporate defaults led many banks to write more credit insurance, finding it a low-risk way to earn income because failures were few. Speculators have also flooded into the credit insurance market recently because these securities make it easier to bet on the health of a company than using corporate bonds.

Both factors have resulted in a market of credit swaps that now far exceeds the face value of corporate bonds underlying it. Commercial banks are among the biggest participants — at the end of the third quarter of 2007, the top 25 banks held credit default swaps, both as insurers and insured, worth $14 trillion, the currency office said, up $2 trillion from the previous quarter.

JPMorgan Chase, with $7.8 trillion, is the largest player; Citibank and Bank of America are behind it with $3 trillion and $1.6 trillion respectively.

But many speculators, particularly hedge funds, have flocked to these instruments to bet on a company failure easily. Before the insurance was developed, such a bet would require selling short a corporation’s bond and going into the market to borrow it to supply to the buyer.

The market’s popularity raises the possibility that undercapitalized participants could have trouble paying their obligations.

“The theme had been that derivatives are an instrument that helps diversify risk and stabilize risk-taking,” said Henry Kaufman, the economist at Henry Kaufman & Company in New York and an authority on the ways of Wall Street. “My own view of that has always been highly questionable — those instruments also encourage significant risk-taking and looking at risk modestly rather than incisively.”

Officials at the International Swaps and Derivatives Association, a trade group, say they are confident that the market will stand up, even under stress.

“During the volatility we have seen in the last eight months, credit default swaps continue to trade, unlike other parts of the credit market that have shut down,” said Robert G. Pickel, chief executive of the association. “Even if we have a series of credit events at the same time, we have the processes in place to enable the market to deliver.”

Such credit problems have been rare recently. The default rate among high-yield junk bonds fell to 0.9 percent in December, a record low.

But financial history is rife with examples of market breakdowns that followed the creation of complex securities. Financial innovation often gets ahead of the mechanics necessary to track trades or regulators’ ability to monitor the market for safety and soundness.

The market for default insurance, like the subprime mortgage securities market, is a product of good economic times and has boomed in recent years. In 2000, $900 billion of credit insurance contracts changed hands. Since then, the face value of the contracts outstanding has doubled every year as new contracts have been written. In the first six months of 2007, the figure rose 75 percent; the market now dwarfs the value of United States Treasuries outstanding.

Roughly one-third of the credit default swaps provided insurance against a default by a specific corporate debt issuer in 2006, according to the British Bankers’ Association. Around 30 percent of the contracts were written against indexes representing baskets of debt from numerous issuers.

But 16 percent were created to protect holders of collateralized debt obligations, complex pools of bonds that have recently experienced problems because of mortgage holdings.

There is no exchange where these insurance contracts trade, and their prices are not reported to the public. Because of this, institutions typically value them based on computer models rather than prices set by the market.

Neither are the participants overseen by regulators verifying that the parties to the transactions can meet their obligations.

The potential for problems in sizing up the financial health of buyers of these securities leads to questions about how these insurance contracts are being valued on banks’ books. A bank that has bought protection to cover its corporate bond exposure thinks it is hedged and therefore does not write off paper losses it may incur on those bond holdings. If the party who sold the insurance cannot pay on its claim in the event of a default, however, the bank’s losses would have to be reflected on its books.

Investors are already reeling from the recognition that major banks inaccurately estimated losses from the mortgage debacle. If further write-downs emerge as a result of hedges that did not work, investor confidence could take another dive.

To be sure, the $45 trillion in credit default swaps is not an exact reflection of what would be lost or won if all the underlying securities defaulted. That figure is impossible to pinpoint since the amounts that are recovered in default situations vary.

But one of the challenges facing participants in the credit default swap market is that the market value amount of the contracts outstanding far exceeds the $5.7 trillion of the corporate bonds whose defaults the swaps were created to protect against.

To the uninitiated trying to understand this complex market, its size might initially seem a comfort, as if there were far more insurance covering the bonds than could ever be needed. But because each contract must be settled between buyer and seller if a default occurs, this imbalance can present a problem.

Typically, settling the agreements has required the delivery of defaulted bonds if the insurance buyer wants to be fully covered. If the insurance contracts exceed the bonds that are available for delivery, problems arise.

For example, when Delphi, the auto parts maker, filed for bankruptcy in October 2005, the credit default swaps on the company’s debt exceeded the value of underlying bonds tenfold. Buyers of credit insurance scrambled to buy the bonds, driving up their price to around 70 cents on the dollar, a startlingly high value for defaulted debt.

Market participants worked out an auction system where settlements of Delphi contracts could be made even if the bonds could not be physically delivered. This arrangement was done at just over 36 cents on the dollar; so buyers of protection on Delphi who did not have the bonds received $366.25 for every $1,000 in coverage they had bought. Had they been valuing their Delphi insurance coverage at $1,000 per bond, they would have had to write off that position by $633.75 per $1,000 bond.

That is why the valuation of these contracts is of such concern to some participants.

As with other securities that trade privately and by appointment, assigning values to credit default swaps is highly subjective. So some on Wall Street wonder how much of the paper gains generated in these instruments by firms and hedge funds last year will turn out to be illusory when they try to cash them in.

“The insurance business is very difficult to quantify risk in,” said Mr. Farrell of Annaly Capital Management. “You have to really read the contract to make sure you are covered. That is going to be the test of the market this year. As defaults kick in and as these events unfold, you are going to find out who has managed this well.”

And who hasn’t.

Written by quantboy

February 18, 2008 at 3:35 am

Posted in Finance

Setting up a LAMP server in Ubuntu

Without installing a headless Ubuntu server-

Instructions on howtoforge.com.

Written by quantboy

January 26, 2008 at 2:43 am

Posted in Linux

Ugly Chinese Fonts in Gutsy Gibbon Ubuntu

Ever since installing Gutsy, I’ve noticed the Chinese fonts in FireFox look exceptionally ugly- like this:

Ugly Chinese Fonts
Using Google, I found the solution posted here. Essentially, it’s a four-step solution:

  1. fontconfig-voodoo -f -s zh_CN
  2. sudo vi /usr/share/language-selector/fontconfig/zh_CN
  • move the western font above the Chinese fonts
  • move the “AR PL ZenKai Uni” font above the other Chinese fonts
  • lower the use of ugly aliased fonts below a certain pixel size- look for the keyword “pixelsize“ in the file

Written by quantboy

December 31, 2007 at 2:08 am

Posted in Log, Ubuntu

Samba Notes

  • Add a new shared folder: sudo vi /etc/samba/smb.conf
  • Restart samba service: sudo /etc/init.d/samba restart

Written by quantboy

December 29, 2007 at 10:56 pm

Posted in Linux, Samba, Ubuntu

Setting up a blank partition for use in Linux

Formatting a partition in Linux

  • sudo mkfs -V -t ext3 /dev/hda6
    • -V = verbose
    • -t = file system type

Mount the partition to an existing node in the file directory

  • sudo mount -o rw /dev/hda6 /media/cda

Change the owner of the file directory so it can be written

  • sudo chown -R [userid] /media/cda

Written by quantboy

December 22, 2007 at 3:25 am

Posted in Linux, Ubuntu

Mulberry Street

Written by quantboy

December 19, 2007 at 11:37 pm

Posted in Log

“Permission denied” on file system

Strangest thing happened just today.  On my Ubuntu laptop, I have 2 ext3 partitions and 3 ntfs partitions.  Even though all ntfs 3 partitions were mounted with the read-write option, I couldn’t write to them.  I used a simple “touch hello” test and even that command failed.

A search on the ubuntu forums found that I have to use the chown command to grant myself permission to use the file system.

sudo chown (userid) /media/disk

Immediately afterwards I had write permission to the disk.

Written by quantboy

December 19, 2007 at 11:24 pm

Posted in Log, Ubuntu

Converting from Xubuntu to Ubuntu

sudo apt-get install ubuntu-desktop

Written by quantboy

December 15, 2007 at 8:11 pm

Posted in Linux, Ubuntu

Follow

Get every new post delivered to your Inbox.