Not sure whether to rent or buy a home? Just run this Python 3 script. You can change the numbers at the top of the script to suit your preferences and your local real estate market.
This script outputs separate pre-tax net worths for renting or buying one home over its entire mortgage duration (30 years by default). It assumes that for every year during the mortgage, you invest all of the money you save by renting relative to buying, and all money saved by buying relative to renting. Thus, it constitutes a true comparison of renting and buying, including the annualized opportunity cost of having less available cash to invest in non-home assets with potentially higher returns.
NOTE: Because this script only compares pre-tax net worths, it doesn't compare the tax burden of selling your home, or non-home investment assets. For a comparison that also accounts for taxes after selling the home and all equivalent non-home assets, use the NYT's Rent or Buy Calculator here.