The following chart shows the process by which mortgage portfolio loans are purchased.
Lenders originate loans & can select to sell them as whole loans. On the other hand Fannie Mae purchases the mortgages for its portfolio & to fund the purchases, issues debt in capital markets.