This is particularly true in the current market. For example, if you bought the place I own today with a 20% down payment, the monthly payments after subtracting payments against principal would significantly exceed the rent on the same place. Yet I could rent it out at a profit. If it was purely about optimizing financial outcomes, it would make no sense for anyone to buy my place.
You can very easily come out ahead financially by renting in many markets.
You're going to need to show your work here, because, to me and apparently to several other posters at least, it makes no sense to even compare the numbers in the two cases you describe, because, as another poster responding to you said, you can't live in your stock portfolio.
> renting...
Renting the place you live in vs. owning it is not the comparison you are claiming to make when you say buying a house and living in it is a "bad investment". The comparison you are claiming to make is between buying a house and living in it, vs. buying a house and renting it out. Which, as noted above, doesn't even make sense as a comparison.
To put it another way, you could rent and save enough money to buy the house with cash before you'd be able to pay off your mortgage, ceteris paribus. You'd still have the house at the end.
Financial models that show you often come out ahead if you rent and put the difference in other investments have been done ad nauseam on the Internet, it doesn't need to be rehashed here.
Not the comparison I and others have been responding to. That was talking about buying a house and renting it out instead of living in it.
This is nearly never true. Tell that to all the people who say if they'd only bought a house X years ago but now they are priced out of the market.
The only scenario where what you say is true is if you bought at the peak of a decaying city, which can happen but isn't the normal scenario.
> Yet I could rent it out at a profit.
You seem to be assuming that you can find a place to rent for a price that is substantially under market rent, just because the landlord has a low cost basis on it and can make a profit even at such low rent.
Which is totally not how landlords price their rent. They'll charge what the market can bear even if their effective cost basis is zero (say, they inherited the property).
I.e. it ignores the cost of rent that you would otherwise be paying.