A trader who has a long or short position in a futures contract can terminate the contract in four ways:
This is the case where the futures trader closes out the futures contract even before the expiry. A trader who has a long position can take an equivalent short position in the same contract, and both the positions will be offset against each other. Similarly, a trader with a short position can take a long position in the same contract to closeout the position.
On the settlement date, the short can settle the contract by delivering the underlying asset to the long. The contract is settled by delivery. This method is hardly used and constitutes not more than 1% of contract settlements.
In case of the physical delivery, the clearinghouse will select a counterparty for physical settlement (accept delivery) of the futures contract. Typically the counterparty selected will be the one with the oldest long position.
Cash settlement can be done only if the contract specifies so. The trader just leaves his position open and when the contract expires, his margin account will be marked-to market for P&L on the final day of the contract. This is the most commonly used method as the trader saves on the transaction costs of closing out the position.
Exchange for Physicals
A contract can also be terminated through an exchange of physicals. In this case, a trader finds another trader who has an opposite position in the same futures contract and delivers the underlying assets to him. This happens outside the exchange floor, and is called an ex-pit transaction. The traders will then inform the clearinghouse about the transaction.