EveryBlock.com

General No Comments »

The folks behind chicagocrime.org are at it again — this time with a broader focused site called EveryBlock.

Here’s Chicago’s EveryBlock page, here’s where I work (the Loop).

Geometric Annual Return In SQL

Finance, SQL No Comments »

Here is some quick-and-dirty SQL to calculate an geometric annual return (as a percent) from a column of monthly returns (in percents).

  1. /* Convert the annualized number back to a percent */
  2. SELECT (T3.AnnHPR - 1) * 100 AS GeomAnnRet
  3. FROM
  4.   (
  5.   /* Annualize the holding period return */
  6.   SELECT POWER(T2.HPR, 12.0 / T2.NumReturns) AS AnnHPR
  7.   FROM
  8.     (
  9.     /* Calculate the holding period return over the time
  10.         period.
  11.    
  12.        POWER(10, SUM(LOG10(n))) is a simulated PRODUCT(n)
  13.        aggregate function.
  14.    
  15.        The precision of POWER is determined by the precision
  16.        of the first argument, so use a lot of decimals. */
  17.     SELECT POWER(10.0000000000000000,
  18.                  SUM(LOG10(T.MonthReturn))) AS HPR,
  19.            COUNT(*) AS NumReturns
  20.     FROM
  21.       (
  22.       /* Convert all percent returns to multipliers (1% ->
  23.          1.01) */
  24.       SELECT 1 + MonthPctReturn / 100 AS MonthReturn
  25.       FROM
  26.       ) AS T
  27.     ) AS T2
  28.   ) AS T3</code>

Update 2008-01-30 10:52PM: Here’s the equivalent “one-liner”:

  1. SELECT 100 * (POWER(POWER(10.000000000000000,
  2.                           SUM(LOG10(1 + MonthPctReturn / 100))),
  3.                     12.0 / COUNT(*)) - 1)
  4. FROM

In Writing, Precision [Often] Harms Readability

General No Comments »

Raymond Chen wrote an article today about how he couches his writing to preempt “nitpicking”. This hit close to home.

In my first drafts, I frequently add phrases such as “I think …” and adverbs such as “often”; the title of this blog post is an allusion to such behavior. These changes add precision but cause dramatic harm to readability and authority. I now make conscious effort to minimize these types of phrases.

It’s too bad Raymond feels the need to shift the balance the other way.

The $1.4 Trillion Question

Political Economy 1 Comment »

James Fallows, a correspondent for the Atlantic, has written an article entitled “The $1.4 Trillion Question describing the tenuous economic relationship between China and the United States. Former Treasury Secretary Lawrence Summers has aptly described the relationship as the “balance of financial terror”.

The most shocking aspect of the relationship is the sheer size of China’s reserves — $1.4 trillion and counting. To provide perspective, $1.4 trillion is enough to purchase all of the following companies outright:

In 2007 alone, China added $461.9 billion to its reserves. This was nearly enough to buy Exxon-Mobil ($463.64 billion). Imagine China buying an Exxon-Mobile every year.

Other countries also have large supplies of foreign reserves (Japan, the United Arab Emirates, and Russia are the runners-up per Fallows). What they do with them will have profound effects on the American economy.

Asymmetric Behavior

Economics No Comments »

Looking at these policymakers’ reactions in their entirety leads to the conclusion that this Fed is willing to react to large falls in asset prices that it feels are unwarranted by fundamentals. This is a change that I applaud. I only hope that this new approach is not asymmetrical and that US central bankers will see the need to respond to large increases in equity, fixed-income, and housing prices when they inevitably come.

Cecchetti, Stephen. “Bernanke’s Fed shows that it can be nimble.” The Financial Times 24 January 2008.

I predict the Fed will take up a symmetric approach to monetary policy at the same time the BLS takes up a symmetric approach to quality adjustment1 when calculating CPI. In short, never.

For example, how much has inflation increased due to tasteless tomatoes or how much modern air travel resembles steerage?

I have no problem with quality adjustment in theory, but intellectual honesty demands both symmetry and, for proper comparison, a recalculation of past CPI numbers with quality adjustment taken into account. However, given the impracticality of the latter, any comparison of post-quality adjustment to pre-quality adjustment CPI figures should be performed with a giant asterisk.

And don’t get me started on intra-category substitution. Inflation should compare the price of beef to the price of beef, not the price of beef to the price of today’s cheapest meat.

1 To read more about how the BLS adjusts for quality when calculating CPI, see Adjusting for Changes in Quality in Explaining the Consumer Price Index.

Silverlight 1.0 Mandelbrot Set Generator

Silverlight 2 Comments »

While reading the Mandelbrot set chapter in Dewdney’s The New Turing Omnibus, I realized that this would be a great test application for Microsoft’s new interactive Web application framework Silverlight. Below is the component, its source code, and a few things I learned along the way.

Beware: the Mandelbrot set is computationally expensive and may appear to lock up your web browser. If a “Stop running this script?” dialog pops up, please click no to allow the calculations to finish.
Read the rest of this entry »

STL objects and module boundaries

STL, Win32 4 Comments »

Let’s say you have the following function:

  1. void AppendChar(std::string& s, char ch)
  2. {
  3.     s += ch;
  4. }

What happens if this function is exported as an ordinal function from a DLL (not an inlined piece of code inside a header) and you call it from an EXE?
Read the rest of this entry »

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in