Philadelphia Reflections

The musings of a physician who has served the community for over six decades

Related Topics

George (3)
It's often desirable to get live financial data and everyone knows. XML is the thing to use but actually writing programs that work takes a bit of trouble. Plus, once you've got the data you need to display it.

Financial Graphing using PHP

The Financial Strategy

The problem to be solved in December 2012 was to fund a 30-year inflation-adjusted after-tax immediate annuity with the money in an equity portfolio located in a combination of 401(k)s, IRAs and taxable brokerage accounts.

After considerable analysis and consideration we settled on a 30-year bond ladder. The composition of such a thing could be the subject of another blog, but suffice it for here that a collection of bond ladders was the objective. The alternatives were to continue to harvest capital gains via judicious portfolio rebalancing but in this instance, the risk no longer seemed warranted, and commercial annuities but the loss of control was unpalatable and the costs were very high.

The problem was that a number of the bonds would be long-dated coupon bonds held to maturity and nobody wanted to buy such things when interest rates were at the lowest level in two generations.

{December 2012 Treasury Rates}

The Macro Situation

Whither the economy, the equity market, and interest rates? December 2012 was 44 months, nearly 4 years, from the bottom of the recession/market in March 2009. The previous cycle had its low in November 2003 and its peak in mid-2007... 3 1/2 years. This was the heart of the Bear case: these things move in cycles and this cycle was getting long in the tooth. Bear markets hurt equity portfolios and bring lower rates. Add to that the fact that with Obama's re-election Ben Bernanke seemed likely to be at the Fed for a while longer and Chairman Bernanke had promised us low-interest rates until 2015.

The Bull case was that this recession had been much worse than the previous one and so the recovery would be longer, too. After 4 years of recovery, unemployment was still officially 8% and actually more like double that; corporate profits were doing well but there was a lot of capacity and retained earnings were being warehoused rather than invested or returned; real estate had come back strongly and looked like continuing to improve, and the Euro crisis seemed to be subsiding. Plus, the re-elected Democrats seemed more stimulative than the Republicans might have been, possibly except for tax rates which might have been overemphasized in terms of their economic impact. Finally, there seemed to be a chance that the politicians would act to avoid the fiscal cliff and after a national debate on the debt and deficit going back to the 2010 mid-terms there seemed to be some, albeit small, chance that they might even go further and do something useful for the economy.

The Plan

So we agreed on the Bull case and decided to hold equities into 2013 and also hold some TLT (20+ Treasury ETF) as an insurance policy in case of hiccups. As for when to buy bonds, we looked at rates going back to the end of the last recession in 2009 and found that the highest rates of that period had been in April 2010.

{April 2010 Treasury Rates}

We decided to leg into the ladders: we would buy in four steps ... 25% of the bonds when rates got 25% of the way to the levels of April 2010 and so on. By so doing we could substantially reduce the cost of the ladder (said another way, we could have more money left over after the ladder was in place). We would adopt the approach as events unfolded.

The Technical Implementation of Visual Trigger Points

Although we were focused on this subject now, rates wouldn't move for quite a while and our attention would turn to other things. What we needed was something to quickly remind ourselves of where we stood viz-a-viz our plan.

We used two technologies to build the picture below which shows the rate levels of the four steps with fixed dashed lines and an updating solid line for the current level of Treasury rates. When the solid line moved up to touch a dotted line, it would be time to buy.

The first technology we used was the PHP function I had written to pull the current yield curve levels from the Treasury website to update the solid line. That function is shown here.

The second technology is an absolutely superb graphing package for use with PHP called pChart. I want to tell you that it works right out of the can exactly as promised and as long as you write your programs in a sub-folder to the installation root folder, it will. I cannot recommend it highly enough. From initial installation to producing the chart below took me maybe two hours but I think less.

{Yield Curve Graph}

Originally published: Tuesday, December 04, 2012; most-recently modified: Friday, May 17, 2019