In finance, a swap is a financial instrument--a kind of derivative security.
A swap is essentially an agreement in which counterparties (generally two) agree to exchange future cash flows arising from financial instruments. For example, in the case of a vanilla fixed-to-floating interest rate swap counterparty A agrees to pay counterparty B periodic fixed interest payments on some "notional" principal amount (say $100mm) in exchange for variable rate payments on that notional. The floating "leg" is typically periodically reset based on some reference rate such as LIBOR.
A swap is an agreement between two counterparties to exchange something (one "leg" of the swap) for something else (the other "leg"). These "things" will generally be cash flows arising from different financial instruments, obligations or rights. For instance a common swap might be "5000 shares of IBM for 50 points over the LIBOR" meaning one counterparty will receive the shares of IBM, and in exchange pay the other a fee as long as they keep them.
Usually, one leg involves quantities that are known in advance (e.g. the "fixed leg" in an interest rate swap) the other involves quantities that are uncertain or variable (e.g. the "floating leg" of an interest rate swap). The floating leg must therefore be "reset" against an agreed reference rate, which will become known at some point before the payment or settlement takes place. For instance the parties might agree to pay 50 points (.5%) over the LIBOR measured on the 1st trading day of every 3rd month. The payment schedule is often, but not always, timed to coincide with the resets.
Ideally, the determination of the reference rate must be outside the control of the counterparties, otherwise a conflict of interest will arise. However, many financial products in the retail market (such as capped mortgages) involve reference to a managed interest rate which is actually controlled by the mortgage provider. Typically, the reference rate is some figure made publicly available by a third party information vendor, or by government agencies. For example, BBA LIBOR.
Once a component of the floating leg is fixed (or "reset"), the fixed and floating components can be swapped or settled (typically one or two days after the fixing date).
Total return swap
Main article: total return swap
The first swaps were commonly used as a way to hedge exposure to market risk for a low fee. For instance, if a trader decides to short sell a stock, there is considerable "market risk" if the stock price rises. In order to hedge that risk, the trader could enter a swap agreement for the same stock, paying a small fee to "hold" it while not actually having to pay for the stock itself. In this case if the stock price does rise, they simply end the swap and use the stock to pay off the short. In effect, they are buying insurance against their position. Known as total return swaps, in these contracts all cash flows, dividend payments for instance, are payed or received by the holder as if they owned the stock directly. Yet for accounting purposes they are off-balance sheet and do not appear as an asset (they do not legally own the stock in question).
The value of the swap is the net present value of all future cash flows. Initially, the terms of a swap contract are set such that the NPV of all future cash flows are equal to zero.
For example, consider a fixed to floating rate interest rate swap involving the exchange of a periodic fixed rate payment for a periodic floating rate payment (e.g. 3-month LIBOR). In such an agreement the floating rate would be set such that the present value of its future payments are equal to the present value of the anticipated future floating rate payments (i.e. the NPV is zero).
Variations of swaps include Equity swaps, cross currency swaps , amortizing swaps and so on.
You can also have an option on a swap - a swaption