Tuesday, March 10, 2009

Investing for Dummies

Is Botulism worth it?
As most of you have probably already noticed, we're officially in the midst of a recession. This probably explains why I have lost weight as we seem to be saving more for rainy days and spending less at the grocery counter.

So I was thinking of how I could make a bit more money to keep my grumbling tummy and wallet satisfied at the same time. One alternative would be to shop at the dollar store for meat but the closest thing that they have to offer is canned spam from the 80s.

After contemplating this for a moment, I decided to skip out on the fabulous idea of a botulism induced fatality and began to look at other alternatives.

ETFs

Many companies these days lack the financial appeal of attracting investors and who knows where your money is going to end up at the end of all this? Some Banks are undergoing partial nationalization, while some insurance companies are folding like players who can't call a 25 cent check raise.

With the help of some coworkers, I have discovered ETFs (Electronically Traded Funds) and more specifically 'Inverse Exchange Traded Funds', otherwise known as Bear ETFs. If you're going to lose your money anyways, why not do it with style?

ETFs are funds that trade on a stock market that track the performance of a particular index or benchmark, of whatever the fund is invested in. For instance,there are ETFs that track precious metals (Gold, Silver), financial indexes, Crude Oil, bond markets, natural gas, agricultural grains and so on. I haven't found it yet but I am sure that there is one that tracks the popularity of Chuck Norris quotes.

In normal (bull) ETFs, if the index which the fund is tracking goes up, so does the stock price of the ETF that you're invested in. In inverse (bear) ETFs, the price of the stock goes up if the index goes down. So essentially, you are shorting the stock but do not have to do explictly through a options or margin account. To further increase the voliatility, some funds are tracked at 200% (2x) the performance of the index.

In this market, it's better to bet on the bear than to ride the bull. So this is a strategy that you can use to offset/hedge against your medium/long term holds. Because let's be honest, you're still holding onto your Nortel shares with the hopes that it will emerge from Chapter 11 unscathed, right? =)

So here's where I post the disclaimer: Be careful and read all the fine print. I am not responsible for your losses. Practice safe investing and you could end up like me: with a full stomach and avoiding the mishaps of botulism.

As always, post any comments you have ... Till Next Time.

Read more...

Monday, March 09, 2009

SQL Server Exception Handling - Basketball Analogy

SQL Server 2005 has introduced a really cool way of handling exceptions through a TRY ... CATCH construct that should be familiar to most developers in this day and age. In my opinion this waslong overdue as it really was a pain to handle errors using previous versions of SQL Server.

Since I'm a firm believer in the "No pain, no gain" philosophy, let's remind ourselves how painfulthe old syntax really was using a sports analogy.

Old Way

So let's take a hypothetical situation and pretend that I am American Billionaire, Mark Cuban, owner of the Dallas Mavericks. I've decided to remove Dirk from the lineup because I recently found out that he is abig fan of the 'Hoff (whom Mark Cuban hates for obvious reasons). So he's influenced Rick Carlisle to remove Dirk from the lineup to insert Brandon Bass. Let's see what that code would like.

begin trans
delete from lineup where playerID = 41
if @@error <> 0
goto err1
insert into lineup values (32, 'Brandon Bass')
if @@error <> 0
goto err2
commit trans

err1: print 'Error occured removing player from lineup'
goto eend

err2: print 'Error occured adding player to the lineup'

:eend

So we have to check whether or not there was an error after each statement. Perhaps, Dirk wouldn't come off the floor. Or perhaps, Brandon Bass tripped on his shoelaces, fell over the gatorade and broke his ankle while checking into the game. And if we wanted customized error messages for each scenario, wewould have to have multiple labels to handle them (Rather unrealistic but it proves the point).

New Way

So now let's see a more elegant solution with the new TRY ... CATCH construct.

BEGIN TRY
insert into lineup values (32, 'Brandon Bass')
END TRY

BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage
END CATCH
GO

As you can see it is much more elegant than the old method and improves readability and robustness of the code. Anytime an error is encountered withinthe TRY block, control is directed to the CATCH block, where you could display or log the corresponding error. So I hope that anyone using SQL 2005+ will start to use this syntax if you aren't already.

Read more...