2009 Cubs Predictions

Baseball No Comments »

image

Current Cubs team OBP: 0.333
Current Cubs team ERA: 4.60
This year’s prediction: 78-84 (Methodology)

Ugh, let’s hope I’m wrong.

Historic P/E Ratio for the S&P 500

Investing 5 Comments »
Historic P/E Ratio for the S&P 500

Historic P/E Ratio for the S&P 500

Time to buy yet?

Hat tip: Barry Ritholtz

Why The Economist Drives Me Nuts

Political Economy 2 Comments »

The Economist is a great magazine. They provide sophisticated analysis on numerous topics with unparalleled breadth and depth; their graphics design department is top-notch; and their consistent, anonymous editorial style is refreshing, even if irritatingly smug at times.  Because I know how excellent The Economist can be, it drives me insane when I see anything less.

I am particularly disappointed with their article The Frat Boy Ships Out.  Specifically, consider this graph from the article:

image

To me, this graph tells a clear story: In the past 8 years, the growth in unfunded liabilities in America’s entitlement programs is almost entirely caused by the growth in Medicare’s liabilities, including the introduction of Medicare Part D.  Social Security’s unfunded liabilities have grown modestly and are a small part of the government’s long-term financial troubles – less than 20%.

However, The Economist decided to play it rather differently in their analysis:

Mr Bush’s biggest failure, however, is on entitlements. The ageing of the population, coupled with rapidly rising health-care costs, means that in coming decades Social Security and Medicare benefits will outstrip workers’ payroll contributions by trillions of dollars. Both programmes presented Mr Bush with a political opportunity. To pry elderly voters away from the Democrats, he promised to add a prescription-drug benefit as part of any Medicare reform. He did so in 2003, winning the support of the AARP, the powerful pensioners’ lobby, which has long been seen as closer to the Democrats. But in the end he achieved few cost savings, while adding a staggering $8 trillion to Medicare’s unfunded liability (see chart).

Social Security, founded in the Depression to provide workers with a secure pension, has defied all recent attempts to make it solvent. Although such an attempt was part of Mr Bush’s first election campaign, it was not solvency that animated him, but the prospect of workers diverting some of their Social Security contributions to private investment accounts. Such accounts were intended as the centrepiece of the Republican Party’s “ownership society”.

Economists are divided on the merit of such accounts, but agree they do nothing to restore solvency: that requires slimmer benefits, higher taxes, or both. Because of the political peril of touching Social Security, broad reform demands bipartisan support. Yet David Walker, the federal government’s chief auditor from 1998 to 2008, says Mr Bush doomed his own effort, launched after his 2004 re-election, by seeking to shape its outcome from the start. He had appointed an advisory commission whose members first had to agree to support private accounts (which many Democrats oppose). He issued detailed proposals for private accounts while eschewing, until much later, solvency proposals. His administration staged some 200 “town hall” events attended by pre-screened participants, Mr Walker says, yet at the end of it all support for Mr Bush’s proposal was lower than when it began.

Between the Medicare drug benefit and the failure to restore solvency to Social Security, the long-term unfunded cost of America’s programmes for the elderly had last year reached a stratospheric $43 trillion, or 5% of future wages, compared with $13 trillion, or 3% of future wages, in 2000. Mr Obama and Congress may still be able to mend entitlements. But they start with a bigger and more imminent danger than Mr Bush did eight years ago, and one made even harder by the deep hole the current recession has created in the budget.

I count two whole paragraphs dedicated to discussing Social Security, and a few admonishments regarding Medicare Part D. The conclusion specifically reiterates that Medicare Part D and Social Security are the problem. They just barely mention “rapidly rising health-care costs”, even though these represent the vast majority of the growth in unfunded liabilities.

Why would The Economist devote two-thirds of their copy and half of their conclusion to a tiny part of the problem, and virtually ignore the real culprit?

Pseudoloc

Win32 No Comments »

I have released a pseudolocalization tool I wrote for 32-bit Windows resource DLLs here.

Google’s Wonderful PR

Software / Technology 1 Comment »

Today, Google is releasing a beta version of its new web browser, called Chrome. Apparently this event is big news; it merited a front-page article in the Wall Street Journal.

I’ve read a few blog posts about this announcement, such as Is Google Chrome an IE/Firefox/Opera/Safari killer?, and it really seems to me the hype is overdone. From the above blog post, the browser will be:

Open source, built from scratch

Not exactly. The most important piece of a web browser is its layout / rendering engine, and as the blog post later mentions, Google is not writing one from scratch; it is using WebKit.

Revolutionary use of tabs (the tabs will be at the top of the window rather than below the address bar)

This is revolutionary? Really?

Support multiple processes so each tab runs in isolation so bugs and slow-downs only hit a single tab (creating what’s called in the comic book a “sad tab”) rather than bring the browser crashing down

Internet Explorer 8 did this first.

I see nothing wrong with Google writing their own web browser, and I wish them luck in their endeavors, but I don’t understand the uproar over this event. It seems to me the only truly new piece of their browser may be their JavaScript engine, V8; the rest is reuse-and-recycle (probably as it should be).

Update 2008-09-02 7:40 PM: After playing with Chrome for a while, a thought occurred to me — maybe Chrome’s strength isn’t in its technology but in its execution. Chrome is fast, attractive, and minimalist.

Stitched Panorama Pictures

General 2 Comments »

Using Hugin (based on a recommendation from Keith) and some pictures I took last summer, I have created a few stitched panoramic pictures from last year’s Wisconsin vacation:

What I’m Reading

General 1 Comment »

Now that I have completed my degree in Computational Finance from DePaul University, I have far more time for leisurely activities such as reading books. Here’s what I’ve been reading recently:

How to Lie With Statistics How to Lie With Statistics by Darrell Huff and Irving Geis.
When Genius Failed When Genius Failed: The Rise and Fall of Long-Term Capital Management by Roger Lowenstein.
The Underpants The Underpants by Steve Martin.
The Intelligent Investor The Intelligent Investor: The Definitive Book on Value Investing (Revised Edition) by Benjamin Graham.

2008 Cubs Predictions: Take 4

Baseball No Comments »

Chicago Cubs Logo

Latest Cubs prediction: 110-54 (0.362 team OBP, 3.66 team ERA, underlying equation). (Previous predictions: 112-50, 113-49, 90-62)

We’ll have to see how Soriano’s broken finger affects the Cubs’ team OBP and thus the prediction.

Balloon Tooltips

Win32 2 Comments »

In the Windows XP login screen, the password text box will warn you with a balloon tooltip if you accidentally turn Caps Lock on:

Windows XP Caps Lock Warning Message

The balloon tooltip appears to be a Windows tooltip common control with the TTS_BALLOON style.

To replicate this functionality, I decided to write a function called ShowMsgBalloon() which, given a control and the various balloon tooltip parameters, creates and shows the balloon tooltip below the control.

The key insight to making ShowMsgBallon() work as intended was to use the TTF_TRACK option to create a tracking tooltip. This will immediately show the tooltip without requiring the user to position the mouse over the control. The main downside to using TTF_TRACK is that the tooltip will not move with the control if the window is moved; you need to manually move the tooltip using TTM_TRACKPOSITION as required. One could probably make this automatic by subclassing the tooltip’s parent control and handling WM_WINDOWPOSCHANGED messages.

Here is the source code to ShowMsgBalloon(). When you are done with the balloon, call DestroyWindow() on the returned HWND. Note: you may want your application to use comctl32.dll version 6 as it will lead to a nicer visual style, including a close button.

  1. #include <windows.h>
  2. #include <commctrl.h>
  3.  
  4. // Options to ShowMsgBallon() (see dwOpts parameter).  These are the
  5. // standard icon types for balloon tooltips.
  6. #define SMB_ICON_INFO    (1 << 0)
  7. #define SMB_ICON_WARNING (1 << 1)
  8. #define SMB_ICON_ERROR   (1 << 2)
  9.  
  10. // Given the options passed to ShowMsgBalloon(), determine what
  11. // parameter to send to TTM_SETTITLE for the balloon tooltip’s icon.
  12. static DWORD
  13. GetTitleIcon(DWORD dwOpts)
  14. {
  15.     if (dwOpts &amp; SMB_ICON_INFO)
  16.         return TTI_INFO;
  17.     else if (dwOpts &amp; SMB_ICON_WARNING)
  18.         return TTI_WARNING;
  19.     else if (dwOpts &amp; SMB_ICON_ERROR)
  20.         return TTI_ERROR;
  21.     else
  22.         return 0;
  23. }
  24.  
  25. // Create and show a balloon tooltip immediately below the control
  26. // hwndCtrl with the given title, message, and options.
  27. HWND
  28. ShowMsgBalloon(HWND hwndCtrl, LPCTSTR szTitle, LPCTSTR szMsg,
  29.                DWORD dwOpts)
  30. {
  31.     HWND hwndRet = NULL;
  32.     HWND hwndTT = NULL;
  33.     TOOLINFO ti = { 0 };
  34.     RECT rc;
  35.  
  36.     // Even though TTS_CLOSE is always specified, a close button will
  37.     // only be shown if your application has a manifest that requires
  38.     // comctl32.dll version 6.
  39.     hwndTT = CreateWindow
  40.         (
  41.         TOOLTIPS_CLASS,
  42.         TEXT(""),
  43.         WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
  44.         CW_USEDEFAULT, CW_USEDEFAULT,
  45.         CW_USEDEFAULT, CW_USEDEFAULT,
  46.         hwndCtrl,
  47.         NULL,
  48.         NULL,
  49.         NULL
  50.         );
  51.     if (hwndTT == NULL)
  52.         goto Cleanup;
  53.  
  54.     // By using TTTOOLINFO_V1_SIZE rather than sizeof(TOOLINFO),
  55.     // we don’t require users to be using comctl32 version 6.
  56.     ti.cbSize = TTTOOLINFO_V1_SIZE;
  57.     ti.uFlags = TTF_TRACK;
  58.     ti.hwnd = hwndCtrl;
  59.     ti.lpszText = const_cast<lptstr>(szMsg);
  60.     if (!SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) &amp;ti))
  61.         goto Cleanup;
  62.     if (!SendMessage(hwndTT, TTM_SETTITLE, GetTitleIcon(dwOpts),
  63.                      (LPARAM) szTitle))
  64.         goto Cleanup;
  65.  
  66.     // Position the tooltip below the control
  67.     if (!GetWindowRect(hwndCtrl, &amp;rc))
  68.         goto Cleanup;
  69.     SendMessage(hwndTT, TTM_TRACKPOSITION, 0,
  70.                 MAKELONG(rc.left + 10, rc.bottom));
  71.  
  72.     // Show the tooltip
  73.     if (!SendMessage(hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM) &amp;ti))
  74.         goto Cleanup;
  75.  
  76.     hwndRet = hwndTT;
  77.     hwndTT = NULL;
  78.  
  79. Cleanup:
  80.     if (hwndTT != NULL)
  81.         ::DestroyWindow(hwndTT);
  82.  
  83.     return hwndRet;
  84. }

Update 2008-11-01 3:08PM: If you are targeting comctl32.dll version 6 or later, I recommend using the EM_SHOWBALLOONTIP message.  Comctl32.dll version 6 or later also automatically shows the caps lock warning balloon for edit boxes with the ES_PASSWORD window style.

Escaping Strings in XPath 1.0

C++, XPath 1 Comment »

XPath is a language for selecting nodes from an XML document. XPath is used extensively in XSLT and other XML technologies. I also vastly prefer using XPath (e.g. with XPathNavigator) over the XML DOM when manipulating XML in a non-streaming fashion.

In XPath, strings must be delimited by either single or double quotes. Given a quote character used to delimit a string, one can’t represent that same quote character within the string. This means that if you decide to use single quotes to delimit your XPath string, you couldn’t represent the string O'Reilly; use double quotes, and you can’t represent "Hello".

However, given a quote delimiter, you can represent the other quote character. We can use this observation along with the concat XPath function to devise a general quoting rule for XPath strings. It’s easiest to show this via a series of examples:

Original String Quoted XPath String
a 'a' (or "a")
O'Reilly "O'Reilly"
"Hello" '"Hello"'
"Hello, Mr. O'Reilly" concat('"Hello, Mr. O', "'Reilly", '"')

Below is a piece of C++ code which implements these quotation rules:

  1. std::string
  2. QuoteXPathString(const std::string& xpath)
  3. {
  4.     // If we don’t have any single or double-quote characters, quote the
  5.     // expression in single quotes.
  6.     std::string::size_type pos = xpath.find_first_of("’\"");
  7.     if (pos == std::string::npos)
  8.         return "’" + xpath + "’";
  9.  
  10.     // If we cannot find the alternate quotation character, quote the
  11.     // expression in the alternate quotation character.
  12.     char chOther = (xpath[pos] == ‘"’ ? \’ : ‘"’);
  13.     pos = xpath.find(chOther, pos + 1);
  14.     if (pos == std::string::npos)
  15.         return chOther + xpath + chOther;
  16.  
  17.     // The string has both quotation characters.  We need to use concat()
  18.     // to form the string.
  19.     std::stringstream ss;
  20.     ss << "concat("
  21.        << chOther
  22.        << xpath.substr(0, pos)
  23.        << chOther;
  24.     do {
  25.         chOther = (xpath[pos] == ‘"’ ? \’ : ‘"’);
  26.         std::string::size_type pos2 = xpath.find(chOther, pos + 1);
  27.         ss << ‘,’
  28.            << chOther
  29.            << xpath.substr(pos, pos2 – pos)
  30.            << chOther;
  31.         pos = pos2;
  32.     } while (pos != std::string::npos);
  33.     ss << ")";
  34.  
  35.     return ss.str();
  36. }

Usage looks like:

  1. std::string lastName = …; // May come from user input
  2. std::string xpath = "//Customer[LastName = " +
  3.     QuoteXPathString(lastName) + "]";
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in