One item worth noting in this discussion is timing, re: interest rates. ;-)
Over the last 54 years in 25 of those years the interest rate for a mortgage was over 7.5%!
Would you want to invest money while paying a 7.5% mortgage?
Maybe! I tried to pick a bad time, '73' looks like a good candidate.
The average national interest rate was about 7.7% and no favorable
chance to refinance at a lower rate for 30 years.
I'll use $100,000 as the mortgage amount.
So 7.7% for the term of the 30 year mortgage.
If you had invested in the S&P 500 in '73' the 30 year
return on a $100,000 turns that into $1,430,700.
Adjusted for inflation this is $348,950.
Now to get complicated.
Assume you paid off your home and started investing the $713 dollars which would have been your mortgage payment at $7.7% on $100k, after 30 years you would have invested $257,400 and it would have grown to $1,799,000,
Adjusted for inflation adjusted value $438,780.
Now it seems like you are $89,830 ahead by investing, using an historical mortgage rate and S&P gains for 1973 to 2003, that I thought looked like a bad time to invest rather than mortgage.
I didn't get the answer I expected I was going to try to find a worse period, but I'm not sure I did everything right.
Looking here might give you incite into a worse period.
http://www.macrotrends.net/2526/sp-500-historical-annual-returnsHere are the tools I used to do my calculations.
http://mortgage-x.com/trends.htmhttps://dqydj.com/sp-500-dividend-reinvestment-and-periodic-investment-calculator/https://www.google.com/search?q=mortgage+interest+calculator&ie=utf-8&oe=utf-8&client=firefox-b-1