Charles Schwab announced plans Monday to buy discount brokerage rival TD Ameritrade in an all-stock deal valued at $26 billion.

As part of the agreement, Ameritrade stockholders will receive 1.0837 Schwab shares for every share held, a 17% premium over the stock's 30-day average price before news of the deal broke. The deal is expected to close in the second half of 2020.

Schwab shares jumped 8% and TD Ameritrade's stock shot up 16% in trading on Thursday and Friday. Shares of TD Ameritrade closed up 7.6% higher to $51.78 on Monday, while Schwab shares rose 2.3% to $49.31.

The merging of the two biggest publicly traded discount brokers will create a mammoth with more than $5 trillion in client assets, $3.8 trillion from Schwab and $1.3 trillion from TD Ameritrade. The combined company will serve more than 24 million clients. San Francisco-based Schwab has a market value of $57.5 billion and Omaha-based TD Ameritrade has a $22.4 billion market cap.

"We believe the combination of our two great companies positions us to be competing and winning in the investment services business for the long run — the very long run," said Charles Schwab president and CEO Walter Bettinger.

Schwab's current shareholders will own 69% and TD Ameritrade's existing stockholders will own 18% of the combined company. TD Bank, which currently owns 43% of TD Ameritrade, will own the proportionate 13% of the new company.

Pending regulatory approval, the integration of the two firms is expected to take 18 months to 36 months after the deal is closed. The company is expecting $1.6 billion in integration spending over three years after closing. The combined company's headquarters will relocate to Schwab's new campus in Westlake, Texas.

The deal will create "a Goliath in Wealth Management," Wells Fargo senior analyst Mike Mayo said in a note to clients on Thursday, when talks of the merger were broken by CNBC's Becky Quick.