I'm trying to understand the factors that determine the interest rates that mortgage lenders offer borrowers. My understanding is that rates are determined based on the lender's cost of funds and the borrower's credit profile. Is there anything else? Doesn't the lender make a decision about profit margin? And what affects the lender's cost of funds? Can anyone recommend some more reading on this or a good reference source?