(Binary) Searching for your affordable home

February 12, 2018 ,

It’s an exciting time to be on the Path team. Two months ago, we released some new features for Path, and just two weeks ago, we added home planning. At a high level, our home planning feature aims to answer three questions:

  • What can I afford?
  • How does a home affect my overall finances?
  • Where can I afford to buy?

What can I afford?

This is a deceptively simple question that often lacks a clear answer. If you have a large amount of liquid net worth you can put toward a home purchase, you can probably afford a home worth at least that much by simply putting 100% down and not financing any part of the purchase. This is likely not the case for the majority of our clients, who are in the wealth accumulation phase of their lives. For the purposes of answering this question, our Research team devised a function that maps a positive real number (representing the price of a potential home) to a small set of four discrete values, which we designate as “Comfortable”1, “Manageable”2, “Stretch”3, and “Unaffordable”4. In actuality, this function takes many other inputs such as the client’s income, current wealth, and other factors, but we can treat these as constants during one instance of our home affordability computation. Our objective here is to provide the client with three values: the highest home price they could comfortably afford, the highest price they could manageably afford, and the highest price they could potentially “stretch” for. With the mapping function at our disposal, how can we accomplish this? Our best answer to this question is Binary Search.

From a code standpoint, we accomplish this by implementing a generic Binary Search solver that takes initial search bounds, a mapping function from Double to a result type (like the one described above), and a test function from that result type to a boolean indicating whether it passes the test for what we’re searching for. This solver has other applications in Path such as finding the minimum savings rate required to achieve the client’s retirement goal.

If you thought this algorithm seems a bit inefficient, your instincts are spot-on! This naive algorithm fails to leverage the monotonically increasing nature of affordabilities. For example, if our search for the maximum “Comfortable” affordability level comes back with $500K, we know that this must be the lower bound for the “Manageable” affordability level. Similarly, the “Manageable” upper bound must be the lower bound for “Stretch.” While binary search can zone in on a target range of values that will pass a binary test relatively quickly, we still want to minimize the number of times we ask “does this value pass our test?” especially if that is a computationally expensive question to ask (as we’ll find out in the next section, it is).

So we optimized our algorithm a bit by passing the upper bound of an affordability level as the lower bound of the next affordability level. Can we improve on this any further? As it turns out, we can!

While we have clear lower bounds for our searches, our upper bounds can still extend into the stratosphere5. To mitigate this oversight, we can quickly estimate some rough upper bounds so we have a reasonable range in which to search. We’ll start at our universal lower bound of $120K6 and progressively double it until our mapping function says “this is at best Manageable.” We can then use that as our upper bound for “Comfortable.” If in the process of doubling, we overshot “Manageable” and got to “Stretch” or even “Unaffordable,” that’s fine! We’ll just use the same upper bound as long as it appropriately defines a valid search range for a particular level. In the end, our algorithm looks like this:

Do you think we can do even better? Let us know!

You might now be wondering, “How does this mapping function work? How can I trust Path’s advice on what price is ‘Comfortable’, ‘Manageable’, or ‘A Stretch’?” That brings us to the second question:

How does a home affect my overall finances?

You may have had the experience back in grade school or high school of your Math teacher imploring you to show your work. Upon user testing early versions of the product, we realized that simply displaying to our clients what they could afford wouldn’t be sufficient to get them to trust our advice. This put us in a little bit of a pickle: how could we expose the inner workings of this complex mapping function to our clients in a simple and elegant way? To his credit, Pedro in Research figured out how to do just that. Our home affordability function aims to answer three simple questions:

  • Can I reasonably qualify for a mortgage on a home at this price?
  • Will purchasing this home significantly impact my retirement?
  • Will I run out of money before I pay off the mortgage?

The overall affordability we determine for the home goal depends on the answers to those three questions.

Can I reasonably qualify for a mortgage on a home at this price?

To answer this question, we need to answer two sub-questions:

  • How much money can I put toward a down payment?
  • What will my debt-to-income (DTI) ratio be with this mortgage?

When lenders determine how big a mortgage to pre-approve for you, they seek to answer those two questions (in addition to looking at your credit score). In a similar fashion, Path looks at your complete financial picture (constructed from your linked accounts) as well as your income. To determine how much money you can put down, Path considers your liquid assets (cash, savings accounts, and liquid investment accounts). To figure out your DTI ratio, Path tacks on your existing debt payments to how much you’ll be paying on the financed amount of your mortgage then divides that by your monthly income. If your purchase is in the future, Path estimates future account values, potential changes in mortgage interest rates, and other factors in order to more accurately estimate what you can afford.

Once Path figures out your achievable down payment ratio and projected DTI ratio for a given home price, it compares those values to US state specific thresholds used by lenders.

Will purchasing this home significantly impact my retirement?

To answer this question, we can leverage the existing ability of Path to project your finances into retirement and beyond with the notable addition of this home purchase and all the costs associated with it. However, this is the reason why asking “is this price affordable?” is computationally expensive. Since we are projecting what your finances (with this home purchase) will look like every year going forward until your life expectancy, we need to do a lot of computations. And what is the end result of these computations? We tell you the age when you’ll run out of funds if you made this home purchase. Keep in mind, this number could be non-existent if your finances are robust enough to support owning the home and achieving your other goals. We also need to compute this same age assuming you don’t purchase the home. Once we have both of these, we can do a simple comparison to determine whether buying the home will have a significant impact on your retirement.

Will I run out of money before I pay off the mortgage?

Now that we have the age you’ll run out of funds with the home purchase, we can simply add on your desired mortgage term to the age at which you’ll purchase the home and see which comes first. If we estimate you’ll run out of funds before the mortgage ends, we deem the mortgage unaffordable.

In the end, we can pass back to the client side something like this:

Which will produce this:

Now that Path has shown you what you can afford and why you can afford that amount, it’s time to dive into the last question:

Where can I afford to buy?

Since we already know what home price you can afford, this is not a difficult question to answer. However, it isn’t trivial to serve the above experience without lots of accurate data. Using data made available by Zillow, we maintain a database of home prices across most cities and neighborhoods in the US. Using that price data and your affordability thresholds, we can display to you what kinds of homes you can afford in what neighborhoods.

Wrapping up

And that’s it! It’s been a blast solving these and many more engineering challenges over the past few months. This was a huge team effort that wouldn’t have been possible without all these amazing folks:


1. If a goal is comfortably affordable, it has little to no impact on your planned retirement and other goals.

2. If a goal is manageably affordable, you can afford it if you adjust your retirement or other goals (maybe a little, maybe a lot).

3. If a goal is a stretch, it has a significant impact on your retirement and other goals, and may cause you to run out of money too early.

4. If a goal is unaffordable, you may not have the cash to buy within your planned timeline, or the purchase may prevent you from ever retiring.

5. We really just cap at $10M because if you can afford more than that, you probably don’t need our help!

6. We start at $120K since it represents approximately the 25th percentile of home prices in the US.


Path is a sophisticated personal finance model offered by Wealthfront that allows Clients to explore projections of various possible financial outcomes based on the latest data from their linked financial accounts, tolerance for risk, and current investments, as well as assumptions compiled by Wealthfront’s Research team.

Wealthfront and its affiliates do not provide tax advice and investors are encouraged to consult with their personal tax advisor. Financial advisory and planning services are only provided to investors who become clients by way of a written agreement. All investing involves risk, including the possible loss of money you invest. Past performance does not guarantee future performance.

Wealthfront prepared this blog for educational purposes and not as an offer, recommendation, or solicitation to buy or sell any security. Wealthfront and its affiliates may rely on information from various sources we believe to be reliable (including clients and other third parties), but cannot guarantee its accuracy or completeness. See our Full Disclosure for more important information.