Jan 26, 2017

On Hacking Out a (Really) Rough Asset Allocation Optimizer by Using Backward Induction and Dynamic Stochastic Programming.

This post marks the near-completion of a three leg journey into retirement finance and other financial math that I started several years ago after I finally woke up to the risks of early retirement -- of which I had not been sufficiently aware and that I was also a bit slow to acknowledge.  There were many steps along the way, of course, and lots of other retirement math between the "here and there" but the three math legs -- or "projects" -- I'm thinking about in particular here were: 1) use mean variance optimization (or, in my case, less optimization than ex-post "mapping") to contextualize my systematic alt-risk strategy, 2) create a highly customized forward financial simulation tool, and 3) the topic of this post: attempt to calculate optimal asset allocations using dynamic stochastic programming and backward induction.  I'll synthesize what I think about all three legs some other day.  This post is just an attempt at a quick summary about what I did on number three and some thoughts on whether I learned anything along the way.

I don't know all that much about game theory.  We did not study it in college or my grad school.  I had been vaguely aware of it from what I saw in the financial literature that passes by me every week and I had learned some general principles when taking several MOOC courses in financial and game theory online over the last couple years.  What nudged me into my current project was my running into AAcalc.com which uses the technique for helping retirees with allocation and risk as well as a paper by AAcalc creator, Gordon Irlam, in the Journal of Personal Finance Vol 13 Issue 2: Portfolio Size Matters.    In the article, Mr. Irlam went way out of his way to spell out exactly how he did backward induction to estimate optimal allocations and when I read it, I thought: "hey, I could do that."  Keep in mind here, though, that my goal was less a real immediate need for an optimized asset allocation and more simple curiosity to see if I could actually do it while also maybe building some tech skills and learning something new about the world.  And...(spoiler alert) I did.  At this point I think I need to be pretty careful to acknowledge, though, that without the exact steps spelled out in the article and some helpful and timely and friendly correspondence from Mr. Irlam I probably could not have pulled it off -- if in fact we can agree that I really did pull it off which is not necessarily in the bag yet.  

I won't tutorialize you on backward induction or game theory since I don't have a command of the subject area and even if I did I wouldn't anyway. You can read background at Wikipedia and elsewhere.   These intro wiki paragraphs give a good short cover of the basic idea :  
Backward induction is the process of reasoning backwards in time, from the end of a problem or situation, to determine a sequence of optimal actions. It proceeds by first considering the last time a decision might be made and choosing what to do in any situation at that time. Using this information, one can then determine what to do at the second-to-last time of decision. This process continues backwards until one has determined the best action for every possible situation (i.e. for every possible information set) at every point in time.  
In the mathematical optimization method of dynamic programming, backward induction is one of the main methods for solving the Bellman equation.[1][2] In game theory, backward induction is a method used to compute subgame perfect equilibria in sequential games.[3] The only difference is that optimization involves just one decision maker, who chooses what to do at each point of time, whereas game theory analyzes how the decisions of several players interact. That is, by anticipating what the last player will do in each situation, it is possible to determine what the second-to-last player will do, and so on. In the related fields of automated planning and scheduling and automated theorem proving, the method is called backward search or backward chaining. In chess it is called retrograde analysis.  
Backward induction has been used to solve games as long as the field of game theory has existed. John von Neumann and Oskar Morgenstern suggested solving zero-sum, two-person games by backward induction in their Theory of Games and Economic Behavior (1944), the book which established game theory as a field of study.[4][5]
In Irlam's article in the Journal of Personal Finance he starts by pointing out some of the past history of research into asset allocation including mean variance optimization and various simulation approaches along with some of the pros and cons of each of those. He then goes on to discuss a third approach: asset allocation as an optimization problem that is well fit to the wiki description above. Contra the simulation approach, for example, he states: "it [his allocation optimizer] does not perform these simulations with pre-determined asset allocations…the approach works backward by determining optimal strategies at each stage in life so that earlier decisions will be optimized after accounting for what later optimal behaviors will be."  Pretty slick.  Plus it simplifies the ability to deal with the extreme number of combinations of years and allocations involved if one were doing it in forward-time. 

Then he helpfully, for me, articulated the steps necessary to do it which I'll try to paraphrase here -- and I'll also boldly assume that I am reporting this correctly. I might have to go back to my code to make sure I'm saying it right:   

  • Start with the last year of the plan and, for an array of portfolio values, go thru the 101 asset allocation choices (for two assets in 1% increments)
  • For each allocation, use historical returns to simulate outcomes
  • Calculate the fail rate for each sim-allocation
  • Figure out the best allocation and probability of success for each portfolio value and tuck that away
  • Now move backward one step in time and again for each portfolio value in the array of portfolios go thru the allocation choices again and perform the mini-sim
  • For the portfolio end value at the end of each historical sim for a given return scenario within a given allocation pair, use that end-value to look up the probability from what you tucked away before 
  • For the given portfolio value and specific allocation you are working on combine the probabilities
  • For the portfolio value in this (T-1) year go back through all the allocation-pairs and pick the best allocation and probability (or utility I hear is also a way to do it) and then tuck that away and move back again another year…rinse and repeat this process until you get to the beginning and: behold your optimal allocation for whatever portfolio value you need to evaluate.
He then goes on to talk about the input data, results, variations of the analysis for random longevity, some sensitivity analysis, and discussion points for financial professionals. His main thrust is that portfolio size at any given stage influences, and sometimes counterintuitively so, the allocation that would theoretically be best.   I won't regurgitate the article since you can read it via the link above. 

This was my step-off point and I decided to dive in to see if I could pull it off on my own.  Using R-script it took me maybe a week or a week and a half to get the meat of it down.  It probably would have taken longer but I had some pieces of code from a past project that could be used to bootstrap this one.  I maybe used some different market data (88 years of return data from the Stern School) and different portfolio values and increments for my test run but I used the same 101 asset allocation choices between a risk and safe asset (100/0, 99/1, 98/2, etc.) among other things. With all of that in hand I tried to turn the previous bullet points into real code that worked even if it was at a "pre-school" level of capability given my amateur background.   What did I discover? Let's see:

1. It evidently can be done since I now have a version that at least looks like it works.

2. I think I might have errors in concept or in coding or in over-simplification or in shortcuts taken to make it more efficient…but I'll ignore all these because my interest, again, was less in what it could do and more in me building skills and learning something new. The stakes are low, my only client is me. 

3. At some points in the process it was a little bit of a mind bender and was it was harder than I thought it would be.  For one thing it has, in my version, four loops within loops.  It's like that movie called Inception about dreams within dreams; it's pretty easy to get lost sometimes.

4. It is a lot slower than I thought it would be.  For a small, rudimentary set of test-data portfolios with 10-15 different values, 30 years of back-steps, 101 allocations and 88 years of return data it can take 30-60 minutes -- or even up to three hours if I have a bunch of debugging tables turned on.  Mr. Irlam said he went from an initial version in one language to Python to Java in order to eke out a more efficient use of processors.  Not a path for me but I can see why.  

5. My results don't look much like his but that could be for a lot of reasons. See point 2 for starters.

6. I probably won't take this project too much further since the benefits to me are relatively low and the effort is high though the topic still interests me. I just wanted to see what it looked like and I'm mostly there.  

Here is what my output looked like, for better or worse, right or wrong.  This is for test data that had portfolios ranging from 50k to $1M while using an inflation adjusted consumption of $40k (or 4% against that $1M).  The first chart below is a contour chart of optimal(?) allocations (the colors) for given plan years and levels of test-data wealth.  The second chart traces asset allocations for selected levels of wealth across plan years.  If I have this right, I need to be careful here because these are not really "individual portfolios" being traced but each point on the line is just the allocation suggested in a given year if you happen to be at that level at that time -- except in this chart the dots are connected across years wealth-level to wealth-level, if that makes sense. 



Can we make anything of these charts? I'm not so sure. First I'm a little concerned about the rudimentary nature of my beginner code, all the possible errors[1], the rough use of preliminary test data and the over-use of simplifying assumptions to get it all done. I don't think we can lean too much on these charts at this point. Second, the charts and any conclusions made from them can't even begin to touch the excellence of the original work done by Mr. Irlam where the depth and precision of his work along with a comprehensive and wide view gives a much better platform for making conclusions (which he already did). So let's turn it around here and piggyback off his comments and then we'll come back to look and see if they can help us make sense of my own stuff.  I'm not going to be too thorough on this, though, here are some of the cherry-picked comments I liked the best:

-         "…for [a low portfolio value] stocks dominate.  This is easy to understand. A client might not have a very high chance of portfolio success, but the best chance is to gamble everything on stocks, for stocks produce a higher return and thus a better expected outcome than any of the alternatives… Betting on either stocks or bonds the client is likely to fail, but betting on stocks on average will provide the client with a longer period during which the portfolio meets the client’s income needs. In the real world, for such circumstances, a better strategy than betting everything on stocks might be to advise the client to reduce their expenditures or gain additional income." P12 JPF Vol 13 Issue2

-         "Above a [moderate portfolio level in his example] a balanced bond-dominant portfolio makes the most sense. Success is highly likely, and it becomes more likely the more we can reduce the variance of returns in order to prevent a catastrophic outcome. Bonds should dominate, and for later ages if all that matters is the success probability, a 100% bond portfolio appears appropriate. Again, in such circumstances, an alternative strategy might be to understand clearly about the client’s spending and legacy goals, and then potentially advising to fund retirement spending with a bond ladder and devote the remainder to stocks." P15 JPF Vol 13 Issue2

-         "First, the asset poor need to focus on reducing their retirement expenditures, but once these clients have reached their limits with spending reductions, investing in stocks is the best available alternative. This does not simply apply to minimizing the chance of portfolio failure, but also to minimizing the time spent insolvent. When investing in stocks, portfolios may lose value, but this is more than offset by the likelihood of improved successful outcomes." P15 JPF Vol 13 Issue2 

I think these are wise quotes even beyond the discussion at hand.  The one I like the most, the third, especially the first half of the first sentence, has less to do with dynamic programming than the other two but it highlights the importance of spending control vs allocation as a necessary, essential first-effort.  The question for us at this point is: do the quotes help inform the view of my own charts.  Yeah, I think so if I step back and squint hard enough.  For example, just as in the first quote above, asset poor portfolios in my optimizer chart 1 and 2 seem to want to wager on equities as well in order to try to mitigate the intensity of failure and its duration.  Also the asset "rich" levels in these charts, as in the second quote above, seem to want to lean towards a bond heavy portfolio, at least in the later years.  I think I knew some of this intuitively already but I guess the chart and the article helped confirm it.  I think I can also take some comfort that my results don't totally disrespect the conclusions of someone that knows this stuff way better than I do.  

In the end, I think that while asset allocation is an interesting and important topic I'm not sure how useful this tool will be for me on an ongoing basis. Never say never but while asset allocation and portfolio design can certainly -- when done well and correctly and even optimally -- make a portfolio more efficient in relative terms and explain an awful lot more about returns than stock selection alone, two points need to be made: a) in and of itself asset allocation will not create new wealth out of thin air that many other portfolios could not probably also do just as well; that, for what it's worth, is what human capital in its various forms is for (work, working longer, entrepreneurialism, etc etc), and b) reasonably funded retirement strategies (not to mention the underfunded ones) shouldn't expect to be saved by asset allocation from excessive consumption; that’s what cost cutting is for.  Also, I have convinced myself from personal experience, personal research, and the research of others that a seeming insensitivity of outcomes to centrist asset allocation choices (within broad range boundaries friendly to equity risk) leaves a fair amount of latitude in selecting a whole slew of allocation choices that will not necessarily be "optimal."   Or at least that's true if one is well enough funded and well aware of risks of the road ahead.  

But let's look back now at my original "purpose" rather than at charts and optimal allocations in order to decide whether I had any success in this project.  Let's tick it off one at a time: did I satisfy my curiosity on whether I could pull it off?  I did.  Did I build some new technical capabilities? Of course. Did I learn something new about the world? Most certainly.  


notes
--------------------------------------------------------------
[1] Speaking of errors, in the first version of this post that I published, right after I pressed the publish button I realized I had mirror-flipped chart 1 left and right.  I had forgotten, after all the work on this stuff, that in backward induction we go "backward" so my data said 1-30 but 1 is really the last year not the first so 1 is really 30 and 30 1.  That's what I mean when I don't think we can lean on the charts.  I have not really completely shaken all of this out yet...

...and then I did it again. A day after I added the note1, I realized that chart2 was backwards, too.  Honestly, do you trust any of this?





No comments:

Post a Comment