Friday, October 26, 2012

Goodbye Mortgage

American culture could stand to be more open about personal finances.  Doing so would give us all an opportunity to learn from one another and avoid common pitfalls.  To that end, I want to describe how our family recently paid off our mortgage.

The pie chart above (click to enlarge) shows a breakdown of which factors contributed to paying off the mortgage.  According to the National Association of Home Builders, a home our size sells for $310,000 on average.  That amount represents the entire pie.

The largest slice, 71%, is attributable to savings we realized by purchasing a home in a depressed, rural housing market.  When coal mines in Hanna closed in the late 1990s, the town lost 13% of its population.  That left dozens of quality houses for sale at excellent prices.  We arrived a couple years late, so we actually paid twice as much for our house as any of our neighbors paid for theirs.

At 11%, the next largest contributor is a frugal lifestyle.  By going without some luxuries (TV, travel, prepared grocery items, low-deductible health insurance, etc.), we were able to make additional principal payments on our mortgage each month.  I'm astonished how quickly they added up.

The third largest contributor was a simple family rule: save a windfall.  If we received any unexpected income, large or small, we put it toward the house.  Before establishing this rule, such windfalls increased our standard of living. That caused financial stress as we inevitably grew accustomed to a standard of living we couldn't afford.

At 5%, Bitcoin investments made a valuable contribution.  In December 2010, during the WikiLeaks payment blockade, I become interested in Bitcoin and subsequently acquired some.  Those assets appreciated rapidly.  At one point, an opportunity arose to sell some Bitcoins and pay down our mortgage.  (Off topic: Bitcoins will change how the world thinks about money)

The smallest contribution, as expected, was the minimum, mandatory mortgage payments the bank required each month.  I personally attribute all but this last component to Providence.  I'd be glad to discuss that aspect further in the comments below.

Friday, June 22, 2012

Puns in Programming Language Design

Henri Bergson defined a pun as a text in which "two different sets of ideas are expressed, and we are confronted with only one series of words."  In natural language, puns are often used for comedy, but a skilled author can also use them for powerful literary effect.  For example, the opening lines of Richard III: "Now is the winter of our discontent / Made glorious summer by this sun of York" which has three relevant meanings.  Or John's pun as he recounts Jesus's words, "Except a man be born again, he cannot see the kingdom of God" in which "again" is a Greek word meaning both "again" and "from above."  In both cases, a pun allows the author to convey his full meaning with fewer words than otherwise possible.

Puns require both a talented author (to create the pun) and a talented reader (to understand the pun).  I admit to missing one of Shakespeare's meanings the first several times I read Richard III's opening lines.  As with all linguistic constructs, it offers benefits and costs.  Those must be weighed in each potential use case.

Puns are not unique to natural language.  They exist in optical illusions such as the Necker Cube.  Many programming languages allow sufficient, intentional ambiguity for productive puns.

Dynamic Type

Consider the following JavaScript function which adds elements of a list to an initial value.

One can invoke the function with integer, float or string values and obtain useful results. Dynamic types and an overloaded + operator provide the necessary ambiguity.  This single function definition gives three useful procedures as a result.  Most statically typed languages prohibit this pun by requiring type annotations on variables and parameters.

A talented JavaScript engine might compile the above code into completely different machine language depending on the context in which it's used, the values available at runtime and the processor architecture on which the code is running.  Just as natural language puns require a talented reader, programming language puns require a talented compiler.

Dynamic languages like Erlang and Dart embrace the ambiguity of dynamic types by adopting smart tools like dialyzer and dart_analyzer, respectively.

Parametric Polymorphism

Most functional languages let one write a generic map function like this:

The function is a pun with meaning across all list types.  The compiler infers types where necessary to ensure safety.  The absence of type annotations provides the necessary ambiguity, so dynamic languages support similar puns, although without compile-time type safety assurances.

Java and C# allow similar puns with generics.

Logic Programming

Languages like Prolog and Mercury offer puns through ambiguity in constructors and pattern matching.  For example, a single append definition creates procedures for combining two lists to make a third, removing a list prefix, removing a list suffix and generating all combinations of two lists which, when combined, produce a third:

One can use similar constructs to create punning predicates that split/join strings, parse/serialize data structures, etc.

In Mercury, goal order is unimportant which allows further puns in which the compiler reorders goals to achieve higher performance, lower memory usage or automatic parallelism.  In each case, a single textual definition provides multiple procedural meanings.

Futures and Laziness

There's a related class of puns in which meaning is the same but a programmer is intentionally ambiguous about an important implementation detail.  For example, Alice ML provides futures for the results of concurrent computations.  In Alice, a future is syntactically identical to a variable.  When one writes a function of a variable, it works on values, completed futures and incomplete futures.  This lets APIs change their internal implementation with respect to concurrency without breaking encapsulation and gives the compiler freedom to schedule concurrent threads as it sees fit.

Haskell's pervasive laziness is in a similar vein.  A variable could represent a value or a thunk which, when needed, computes a value.  A single function definition handles both.  Mailing list threads about overcoming Haskell's laziness remind us that in some cases ambiguity is a pun too far.

Psychology of Puns

Most software developers have strong aesthetic preferences about their languages and tools.  Witness the vi-emacs wars, endless debates about semicolons or brace placement and arguments about static vs dynamic typing.  In these scenarios, there is no right answer.  There are only programmers more or less comfortable with various constructs.

Programming language puns and their linguistic ambiguity are no different.  In this case, psychologists even have a name for it: ambiguity tolerance.  Some people want firm rules and an environment that resolves into clear, precise answers (One True Way).  Others thrive on uncertainty and broad choices (TMTOWTDI).  Programmers bring this psychology with them when they design and choose languages.

Fortunately, I think there's room for compromise.  By making certain language constructs optional and relying on smart compilers, programmers can either be ambiguous or precise, depending on their preference.  The language can stay with them as their preferences evolve.  There's a lot of interest in optional static typing (Perl 6, Python, Newspeak, Dart, Erlang, etc).  I'd like to see further exploration of optional annotations and compilers that can usefully resolve programming puns.

Monday, January 02, 2012

Investment Principles

A few days ago, a friend emailed me with some questions about an investment he planned to make.  During the discussion, I wrote down for the first time, some of the principles I use to guide my personal investments.  I decided to create this document as a more thorough reference for myself and a point of discussion so others can offer correction where I'm wrong.

I'll start with a list of high-level principles, follow with my rough algorithm for asset allocation and conclude by explaining how the latter relates to the former.


The following five principles guide my investment decisions.  I try to evaluate each of them before buying a security.

  1. Hard work and frugality are the foundation of prosperity
  2. I'm not as smart as I think I am
  3. Greed and impatience will ruin the best laid schemes
  4. Emotional attachment prevents sound decisions
  5. Gold is the best cash
Incidentally, these correlate fairly well with some of the seven heavenly virtues, respectively diligence, temperance, humility, charity, patience.  If I can make up principles corresponding to chastity and kindness, I'll have a best selling book on my hands, Seven Virtues of Highly Effective Investors?


When I have some money to invest, I typically follow this algorithm to decide where it should be invested.  I invest in a security corresponding to the first question to which I answer yes.
  1. Could I be working or reducing my personal expenses right now?
  2. Have you found an undervalued stock by spending hours reading annual reports, assessing asset values and calculating cash flows?
  3. Is the stock market relatively undervalued?
  4. Is the bond market relatively undervalued?
  5. Is real estate relatively undervalued?
  6. Did Rumpelstilzchen turn straw into gold?
Deriving an Algorithm from Principles

The first principle is the most important.  Fundamentally, wealth represents someone's previous hard work.  Investment is not a way to get rich.  It's a way to modestly grow wealth that has been obtained through honest labor and sacrifice.  As usual, XKCD applies: "compound interest isn't some magical force"  Thus algorithm step 1 is to try working harder and giving up luxuries.  Investing is like electricity conservation, the most effective method is to decrease consumption.

The first principle has also lead me to value investing.  There are dozens of systems for making investment decisions.  Some people swear by various day trading methods or by technical analysis.  At the end of the day, those techniques are far too easy to be successful in the long run.  If an investment claims to offer wealth without effort, it's a lie; the piper must be paid.  The best exposition I've found on value investing is the book Value Investing: From Graham to Buffett and Beyond or in Buffett's words, "other guys read Playboy. I read annual reports"  The first principle suggests that only that sort of work can bring substantial returns; as embodied in algorithm step 2.

When I get tired of the hard work required by principle one, I'm tempted to substitute vain confidence in my truly dizzying intellect.  The second principle is there to save me from myself.  No matter how much I deceive myself, I'm not smart enough to discern a single winning company based on a few contemporary trends.  The goal of algorithm steps 3, 4 and 5 is to trade substantial investment gains requiring my hard work for small gains requiring hard work from others.  Since I'm not smart enough to pick a single winning company, I restrict myself to choosing from one of three asset classes (stocks, bonds, real estate).  Index funds with very low expense ratios are a cheap way to invest in an entire asset class.  It's also hard to become emotionally attached to an index fund (principle 4).

Of course, deciding whether an asset class is undervalued also requires a fair amount of work.  Since the US Dollar is a highly inflationary measuring stick, I'm partial to long term (100+ years) ratios as a start: 10 year trailing P/E, DJIA in gold, historic bond yields, Shiller's home price index in gold, etc.

Algorithm step 6 is a fall through decision to hold cash, in the form of gold, waiting for better investments to arise.  Gold provides no yield and is only the best among a losing team of currencies.  About all it has going for it is a long history and a predictable supply; neither of which other currencies possess.

It's at this point that principle 3 becomes important.  For the last two decades, I think the general stock market has been overpriced.  For the last two years, bonds have been overpriced.  For much of the last two decades, a lot of real estate has been overpriced. It's not much fun to be holding gold, earning nothing in real terms (although 0 is better than negative!).  It's like sitting on the bench at the big game.  "Come on coach, I want to play!"  In these lulls, the only way to invest profitably is to revisit the principles of hard work, frugality and patience.

In honor of principle 2, please enlighten me in the comments below.