SimFinance – The Industrious Squirrel https://blog.chadweisshaar.com Sun, 31 Dec 2017 18:42:58 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 https://blog.chadweisshaar.com/wp-content/uploads/2016/07/favicon.png SimFinance – The Industrious Squirrel https://blog.chadweisshaar.com 32 32 SimRetirement update and release https://blog.chadweisshaar.com/2017/12/31/simretirement-release/ https://blog.chadweisshaar.com/2017/12/31/simretirement-release/#respond Mon, 01 Jan 2018 00:00:24 +0000 http://gator3305.temp.domains/~cweissha/blog/?p=1377 Continue reading "SimRetirement update and release"]]> When I quit my job in 2011 I wrote a program to simulate retirement and give me a feel for the odds that we would be able to survive on the money we’d saved. The program used a Monte Carlo approach to simulate thousands of possible market scenarios and had logic for how we would spend money, collect social security, pay taxes, etc. At the time the program said that we had an 85% chance of outliving our money. That was good enough to quit; knowing that we could go back to work if we had to.

Since writing that program I’ve come back to it every few years to put in more recent data and make improvements. Once my spouse and I got married, I took out a bunch of code that split expenses and taxes between the two of us.

A few months ago I decided to give the program a full makeover and add features to make it useful to more people. The original program was very specific to our situation and didn’t handle account types, expenses, and investments that we didn’t have. Along with adding new features, I needed to make the program much more user friendly and error tolerant.

I’ve completed this project, and the program (and source) are available for download. It still doesn’t handle nearly as many situations as I’d like, and it has very little support for people who are still working, but it is good enough to release.

Motivations

Our brokerage offered us access to their retirement planning product called “Money Guide Pro”. In some ways it is very similar to my program: it uses a Monte Carlo market simulation; it requires you to input assets, expenses, and retirement goals; and it presents the results as a probability of success. There are also some big differences: they handle a wide variety of situations that my program doesn’t; their program runs as a web app; and most importantly their program isn’t available unless you have a financial adviser working with you. I couldn’t find out how much companies like Money Guide Pro charge brokerages for access to the program, but it certainly isn’t free, and the inner workings are proprietary. While my broker was pretty low pressure, the broker’s goal is to use the program to sell management services or annuities.

The results from the professional software were very similar to my program which gave me a little more confidence in my approach. After looking around the web, I didn’t see any other products that were already doing what my program did, and I have the flexibility to release the software for free and make the source code public.

Development

New features

For this release I added a bunch of new features to the program:

  • Singles or couples
  • Legacy planing
  • Medical expenses can be set to grow faster than inflation
  • Medicare replaces private insurance at age 65
  • Added equal lifetime payments to IRAs
  • Added annuities, pensions and HSA accounts
  • Added the ability to buy property during the simulation
  • Inheritance – benefactors have their own life expectancy model and you can set which member of the couple is the beneficiary
  • Calculates your optimal Social security start age – but starts early if you need the money
  • More control of how the external markets are modeled
  • More simulation outcomes – high wealth/success/success with reduced expenses/success with property sales/success with failed legacy goals or purchases/failures
  • Quick sim capability to make a tweak and get a quick result.
  • Stress test against historical scenarios
  • Better tax model – includes social security and the brackets and deduction amounts can be set on the GUI
  • Multiple save files.

Language and libraries

The original program was written in a mix of managed and native C++ using Mircosoft’s C++/CLI platform. I’ve had issues over the years getting my code to build in the latest versions of Visual Studio, and I’m not thrilled with the level of support for C++/CLI from Microsoft (they are pushing Metro App development). But between the reuse codebase and the advantages of C++/CLI, I decided to stick with it. C++/CLI allows you to write either managed C++ that acts a lot like C# and gives you access to the .NET libraries, or native C++ where you manage your own memory, have access to STL and BOOST, and get the performance advantage of native C++. The drawback of this mix is that the managed C++ uses funky looking symbols (^ is roughly *, and % is roughly &, gcnew instead of new) and doesn’t have good lambda function support. It is also a big pain moving data back and forth from managed data structures to native data structures.

The GUI in my program is all built on the Windows.Forms part of the .NET library. So all the GUI is managed code. Since the GUI often directly manipulates the data model, the model that backs the GUI is mostly built on the .NET System.Data.DataSet class and is managed. But, I want the simulation to run fast, so that part is written in native C++. At the start of a run, the managed data model is copied into native C++ classes.

Along with the hassle of managed C++, this was also the first C++ project that I have worked on for several years and I’ve really grown accustomed to the conveniences of C# and the LINQ extensions. Writing constructors, copy constructors, destructors and member accessors is a lot of code overhead that I’d gotten used to not having to write.

I used the C++ library Boost for random number generation and the normal and student’s t distribution. I also used the .NET charting library for all the plots and graphs.

Documentation

Another large task in this project was to write documentation for how to use the program and to describe how the simulation works.

Amount of work

At 111 hours, this update to SimRetirement has taken as long as a large touch table game. I don’t know how long I spent on the original program. Probably a similar amount of time. I spent a lot more time doing research for the first version of the program. Deciding how to model the stock market and other market variables took a long time.

Task Time Percent
Research 13 hr 12%
Coding (includes time in the debugger which should really be part of testing) 76 hr 69%
Testing 13 hr 12%
Documentation 9 hr 8%

The majority of the lines of code are for the GUI. Of those 75% are generated by the GUI builder.

Task Lines Percent
GUI – Generated code 3238 46%
GUI – Written code 1073 15%
Simulation 2737 39%
Total  7048

This project also required a lot of data. I use historical data for several of the “Market” tab plots. I also include data that is used by the model for life expectancy and social security calculations. I store all this data as XML. There are 1490 lines of this kind of data.

Unlike a touch game, this project required basically no art assets. Besides the icon, I didn’t need any graphics. All the charts and graphics in the program are from the .NET Data.Charting library.

Release

I’ve released the program and source code for download on my website. I’ll also post it to reddit in some of the personal finance subs. But I don’t expect to see much interest in the program. I think that it would be useful to people, but it is really difficult to find things like this program on the internet today.

While there’s a nearly unlimited market for phone and web apps, the market for desktop applications is really struggling. There isn’t nearly as much demand as there once was, and the process of discovering desktop software is broken.

We once relied on shareware aggregation websites where people looking for software could search both free and pay software. Sites like tucows and freewarefiles used to be the first stop when trying to find software. With the rise of Google, those sites have become an afterthought and many of them have turned into ad-burdened cesspits of low-quality and/or trial software. Today there isn’t something like the Play Store for desktop software, and searching for shareware/freeware on Google is frustrating (mostly due to shady SEOed sites selling software).

]]>
https://blog.chadweisshaar.com/2017/12/31/simretirement-release/feed/ 0
SimFinance Progress Update https://blog.chadweisshaar.com/2011/08/17/simfinance-progress-update/ https://blog.chadweisshaar.com/2011/08/17/simfinance-progress-update/#respond Wed, 17 Aug 2011 15:46:41 +0000 http://gator3305.temp.domains/~cweissha/blog/?p=40 Continue reading "SimFinance Progress Update"]]> The SimFinance application is mostly done.

As is always the case, the software was more complex than I thought it would be. The main complications were due to the fact that my partner and I aren’t married. So the application had to try to optimize who paid the bills to manage the size of each of our accounts and how much taxes we each had to pay. The other big complication was trying to manage our traditional and Roth IRAs to minimize taxes each year.

There are some big things yet to do:

  1. Come up with a model for stock dividends. Right now, dividends are simply included in the return of the S&P. However, that is not really accurate, as the yield of dividends lags behind changes in stock prices. Also, taxes are due on dividends the year they are paid instead of the year the stock is sold. Those two differences may end up balancing each other out in the overall results.
  2. Investment strategy comparison. Would dividing our money between bonds, i-bonds, and stocks be better overall than having everything in stocks? Does the reduction in volatility pay off? Or is it better to just accept the volatility and maximize returns?
  3. More optimization post 60. The order of IRA withdraws should change after 60. Need to model medicare.

The model is giving us an 85% chance of success right now. I don’t really think that the things that are left to do will change this number significantly. It is surprising how much money we have to have to get a 95% chance of success and how much variation there is in the possible outcomes.

It is possible that treating the S&P 500 as a random distribution is wrong. While the historic data looks random, there probably are some underlying “fundamentals” that keep the stock prices within a range. I am not sure how to add that to the model besides trying to put an overall cap on the market returns.

]]>
https://blog.chadweisshaar.com/2011/08/17/simfinance-progress-update/feed/ 0
Student-t distribution for stock returns https://blog.chadweisshaar.com/2011/04/15/student-t-distribution-for-stock-returns/ https://blog.chadweisshaar.com/2011/04/15/student-t-distribution-for-stock-returns/#respond Fri, 15 Apr 2011 15:27:17 +0000 http://gator3305.temp.domains/~cweissha/blog/?p=37 Continue reading "Student-t distribution for stock returns"]]> I have been working on the SimFinance 2.0 application and have been struggling to find a way to simulate the stock market. (Note: I am not trying to predict the stock market, I just need a way to generate a random stock market return that is similar to historic returns)

My first idea was to use a normal distribution centered around the average return with the same standard deviation that the real data has. This was close to correct, but if I plotted sample returns from history against the normal distribution, the historical returns had much longer tails. Meaning that, in reality, there are more really bad and really good years than there would be in a normal distribution.

After doing some research (I am not the only one interested in simulating the stock market), I found that some people are using a Student-t distribution. After playing with the parameters of that distribution I was able to get a much more realistic curve. Based on the historical data for the S&P 500, I am using the following parameters for the distribution: DOF = 3.40234, SCALE = 35, OFFSET = 0.00725

In software, I am using the boost library to generate random numbers according to the student-t distribution.

]]>
https://blog.chadweisshaar.com/2011/04/15/student-t-distribution-for-stock-returns/feed/ 0
SimFinance 2.0 https://blog.chadweisshaar.com/2011/03/26/simfinance-2-0/ https://blog.chadweisshaar.com/2011/03/26/simfinance-2-0/#comments Sat, 26 Mar 2011 15:17:46 +0000 http://gator3305.temp.domains/~cweissha/blog/?p=35 Continue reading "SimFinance 2.0"]]> I am starting work on SimFinance 2.0.

A long time ago, I tried to create a retirement analyzer/simulator. It would allow a user to enter everything about their finances, including their plans for the future. It then simulated the future by generating thousands of possible scenarios and displaying your odds of still having money when you die. It built these futures probabalistically based on historic performance of different investment types, the user’s life expectancy, etc. The project was too ambitious and I never completed it.

Now, as I consider retirement, I’d like to have this tool. And I realized that I could complete the project if I would limit the scope to just my own situation. It wouldn’t be useful for other people, but it would give me a better idea if I can really retire.

The old project was created with C++ and wxWidgets. I would like to build the new version in C# because it would be easier to create the user interfaces. But C++ would be faster for simulating thousands of futures month by month. It would also let me re-use some of the code from the original project. So I am going to compromise and build it with C++/CLI. I can use the GUI builder and the .NET libraries and also have the speed of native C++ for the time critical parts of the code.

]]>
https://blog.chadweisshaar.com/2011/03/26/simfinance-2-0/feed/ 2