Deductions & credits

Related question.   We are considering buying 2nd home with a 'cash offer' using a margin loan from our brokerage house to generate the short term cash needed at closing (the market in the area we're considering skews heavily to cash/quick to close offers, so financing contingencies can cause an otherwise good offer to be rejected).   Then the plan is to take out either a second mortgage (secured by the 2nd house), OR, a cash-out refinance on the primary residence to generate funds to help pay off that very short-term margin loan (along with liquidating some other assets).  But that takes some time.  Our hope is to not carry that margin loan any more than the time it takes to get a new mortgage or a refinance loan approved.   

 

Is that a viable plan to still have mortgage interest on either loan-type (2nd mortgage or cash-out refi) considered deductible (up to $750K limits)?  E.g., if the settlement statement for the original purchase of the 2nd home does not have a loan associated with it, can a subsequent secured loan still be used and meet the 'buy/build/improve' requirement for mortgage interest deductions on a qualified home?