There may be signs the overheated housing market is cooling, but many buyers still feel like it’s near impossible to get a house without an all-cash offer, or something close to it.

One way to get your hands on that amount of cash is to borrow against an investment portfolio. It’s a strategy billionaires have used for years to fund their lifestyles: wielding assets such as long-held stock as collateral so they don’t have to sell and be subject to taxes. These days, more of the well-to-do are turning to their portfolios to come up with cash and seal the deal on a home.

It's a risky strategy, especially given how volatile stocks are. But there are some real advantages, and it could actually be a worthwhile move for a careful borrower with a sizable portfolio. The most important thing to remember, though, is that borrowing against investments should never be used to overextend, or buy a home that’s more than you had planned on.

First, a quick explainer on how using investments as collateral works: Borrowers can ask their brokerage firms or banks to set up either a margin loan or a securities-backed line of credit tied to their investment account. Most firms will specify a minimum account size in order to do the transaction. For example, at Raymond James it’s about $150,000, says Randy Carver, a financial adviser at Carver Financial Services in Mentor, Ohio.

Keep in mind, this is just for certain taxable accounts — retirement accounts like IRAs are prohibited. The mix of assets in a portfolio will determine the amount that can be borrowed (it’s typically set as a percentage of the account).

If the value of the account goes below a certain threshold, there’s a margin or maintenance call, where the borrower is responsible for depositing additional money into the account — otherwise the brokerage firm can sell the accountholder’s securities to meet the call.       

One of the most attractive features of borrowing against investments right now is that it is relatively cheap to do so. While it can vary based on factors such as the size of your investment account (the bigger your account, the lower the rate), margin loans are being offered at about 3% compared with 5.8% for a 30-year mortgage.

In addition, since there is a pre-existing relationship with the bank or brokerage firm and different regulatory guidelines, there is typically no real underwriting that happens, making for a much faster and easier process than obtaining a mortgage.

Another advantage is particularly relevant now — you don’t have to sell any holdings to come up with the cash. Investors who have to do that to make an all-cash offer are likely selling stocks that are down from their all-time high last year, but still are up overall from when they bought them — meaning they would be subject to substantial capital gains taxes. And they would be locking in those losses, rather than giving those investments time to recover.

Despite those benefits, the biggest danger of course is that the market will tank and you would be on the hook to come up with extra cash, or be at the mercy of the brokerage firm selling whatever is necessary to come out even.

And don’t forget, while the rates on margin loans or securities-backed lines of credit are lower than those for a 30-year mortgage as of now, they typically are variable rates, meaning they will fluctuate with the market. 

That’s why the smartest play is to use an investment portfolio as a means to an end, in effect a bridge from the sale of one home to the purchase of another. And then after the home sale is complete, pay off the margin loan or securities-backed line of credit and take out a more traditional mortgage.

Still, given the uncertain economic environment, you’ll want to be conservative. Firms will typically allow borrowers to tap up to 50% of the market value of their account, but sticking closer to 30% will give you more of a cushion to play it safe. Likewise, if you are banking on selling your home to pay off the margin loan, be realistic about what your home can sell for if the market continues to cool.

Jim Miller, a certified financial planner in Chapel Hill, North Carolina, suggests that margin-loan holders check rates quarterly — once the rate on a fixed mortgage becomes comparable to the margin loan, it’s time to make the switch. In the interim, make sure you have a budget in place to pay it down, Miller says.  

If you do borrow against your investment portfolio, remember that the interest you pay for a margin loan generally isn’t fully tax-deductible. You can only deduct that interest against any investment income you earn. With a traditional mortgage, you can deduct all the interest for loans up to $750,000 if you itemize your deductions.

Margin loans have a bad rap for getting reckless borrowers into hot water. But if used carefully, they’re a wise way for some homebuyers to become all cash-buyers, at least temporarily.

Alexis Leondis is a Bloomberg Opinion columnist covering personal finance. Previously, she oversaw tax coverage for Bloomberg News.